Changeset 29588 in webkit for trunk/JavaScriptCore/kjs/bool_object.cpp
- Timestamp:
- Jan 17, 2008, 11:27:33 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/bool_object.cpp
r28469 r29588 1 // -*- c-basic-offset: 2 -*-2 1 /* 3 * This file is part of the KDE libraries4 2 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 5 * Copyright (C) 2003 Apple Computer, Inc.3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. 6 4 * 7 5 * This library is free software; you can redistribute it and/or … … 29 27 #include <wtf/Assertions.h> 30 28 31 using namespace KJS; 29 namespace KJS { 32 30 33 31 // ------------------------------ BooleanInstance --------------------------- 34 32 35 const ClassInfo BooleanInstance::info = { "Boolean", 0, 0};33 const ClassInfo BooleanInstance::info = { "Boolean", 0, 0 }; 36 34 37 BooleanInstance::BooleanInstance(JSObject *proto)38 : JSWrapperObject(proto)35 BooleanInstance::BooleanInstance(JSObject* proto) 36 : JSWrapperObject(proto) 39 37 { 40 38 } … … 42 40 // ------------------------------ BooleanPrototype -------------------------- 43 41 42 // Functions 43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, const List&); 44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, const List&); 45 44 46 // ECMA 15.6.4 45 47 46 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectProto , FunctionPrototype* funcProto)47 : BooleanInstance(objectProto)48 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype) 49 : BooleanInstance(objectPrototype) 48 50 { 49 putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ToString, 0, exec->propertyNames().toString), DontEnum); 50 putDirectFunction(new BooleanProtoFunc(exec, funcProto, BooleanProtoFunc::ValueOf, 0, exec->propertyNames().valueOf), DontEnum); 51 setInternalValue(jsBoolean(false)); 51 setInternalValue(jsBoolean(false)); 52 53 putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum); 54 putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum); 52 55 } 53 56 54 57 55 // ------------------------------ BooleanProtoFunc -------------------------- 56 57 BooleanProtoFunc::BooleanProtoFunc(ExecState* exec, FunctionPrototype* funcProto, int i, int len, const Identifier& name) 58 : InternalFunctionImp(funcProto, name) 59 , id(i) 60 { 61 putDirect(exec->propertyNames().length, len, DontDelete|ReadOnly|DontEnum); 62 } 63 58 // ------------------------------ Functions -------------------------- 64 59 65 60 // ECMA 15.6.4.2 + 15.6.4.3 66 JSValue *BooleanProtoFunc::callAsFunction(ExecState* exec, JSObject *thisObj, const List &/*args*/) 61 62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject* thisObj, const List&) 67 63 { 68 // no generic function. "this" has to be a Boolean object 69 if (!thisObj->inherits(&BooleanInstance::info)) 70 return throwError(exec, TypeError); 64 if (!thisObj->inherits(&BooleanInstance::info)) 65 return throwError(exec, TypeError); 71 66 72 // execute "toString()" or "valueOf()", respectively 67 JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue(); 68 ASSERT(v); 73 69 74 JSValue *v = static_cast<BooleanInstance*>(thisObj)->internalValue(); 75 ASSERT(v); 70 return jsString(v->toString(exec)); 71 } 72 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const List&) 73 { 74 if (!thisObj->inherits(&BooleanInstance::info)) 75 return throwError(exec, TypeError); 76 76 77 if (id == ToString) 78 return jsString(v->toString(exec)); 79 return jsBoolean(v->toBoolean(exec)); /* TODO: optimize for bool case */ 77 JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue(); 78 ASSERT(v); 79 80 // TODO: optimize for bool case 81 return jsBoolean(v->toBoolean(exec)); 80 82 } 81 83 … … 83 85 84 86 85 BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* func Proto, BooleanPrototype* booleanProto)86 : InternalFunctionImp(funcProto)87 BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype) 88 : InternalFunctionImp(functionPrototype) 87 89 { 88 putDirect(exec->propertyNames().prototype, booleanProto, DontEnum|DontDelete|ReadOnly);90 putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly); 89 91 90 // no. of arguments for constructor91 putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);92 // no. of arguments for constructor 93 putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum); 92 94 } 93 95 … … 95 97 bool BooleanObjectImp::implementsConstruct() const 96 98 { 97 return true;99 return true; 98 100 } 99 101 100 102 // ECMA 15.6.2 101 JSObject *BooleanObjectImp::construct(ExecState *exec, const List &args)103 JSObject* BooleanObjectImp::construct(ExecState* exec, const List& args) 102 104 { 103 BooleanInstance *obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype())); 104 105 bool b; 106 if (args.size() > 0) 107 b = args[0]->toBoolean(exec); 108 else 109 b = false; 110 111 obj->setInternalValue(jsBoolean(b)); 112 113 return obj; 105 BooleanInstance* obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype())); 106 obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec))); 107 return obj; 114 108 } 115 109 116 110 // ECMA 15.6.1 117 JSValue *BooleanObjectImp::callAsFunction(ExecState *exec, JSObject *, const List &args)111 JSValue* BooleanObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args) 118 112 { 119 if (args.isEmpty()) 120 return jsBoolean(false); 121 else 122 return jsBoolean(args[0]->toBoolean(exec)); /* TODO: optimize for bool case */ 113 // TODO: optimize for bool case 114 return jsBoolean(args[0]->toBoolean(exec)); 123 115 } 124 116 117 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.