Changeset 34843 in webkit for trunk/JavaScriptCore/kjs/BooleanObject.cpp
- Timestamp:
- Jun 27, 2008, 9:29:48 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/BooleanObject.cpp
r34821 r34843 22 22 #include "BooleanObject.h" 23 23 24 #include "JSGlobalObject.h"25 #include "error_object.h"26 #include "operations.h"27 #include <wtf/Assertions.h>28 29 24 namespace KJS { 30 31 // ------------------------------ BooleanObject ---------------------------32 25 33 26 const ClassInfo BooleanObject::info = { "Boolean", 0, 0, 0 }; … … 38 31 } 39 32 40 // ------------------------------ BooleanPrototype --------------------------41 42 // Functions43 static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, JSValue*, const ArgList&);44 static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, JSValue*, const ArgList&);45 46 // ECMA 15.6.447 48 BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)49 : BooleanObject(objectPrototype)50 {51 setInternalValue(jsBoolean(false));52 53 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum);54 putDirectFunction(new (exec) PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum);55 }56 57 58 // ------------------------------ Functions --------------------------59 60 // ECMA 15.6.4.2 + 15.6.4.361 62 JSValue* booleanProtoFuncToString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)63 {64 if (thisValue == jsBoolean(false))65 return jsString(exec, "false");66 67 if (thisValue == jsBoolean(true))68 return jsString(exec, "true");69 70 if (!thisValue->isObject(&BooleanObject::info))71 return throwError(exec, TypeError);72 73 if (static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(false))74 return jsString(exec, "false");75 76 ASSERT(static_cast<BooleanObject*>(thisValue)->internalValue() == jsBoolean(true));77 return jsString(exec, "true");78 }79 80 JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList&)81 {82 if (JSImmediate::isBoolean(thisValue))83 return thisValue;84 85 if (!thisValue->isObject(&BooleanObject::info))86 return throwError(exec, TypeError);87 88 return static_cast<BooleanObject*>(thisValue)->internalValue();89 }90 91 // ------------------------------ BooleanConstructor -----------------------------92 93 94 BooleanConstructor::BooleanConstructor(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)95 : InternalFunction(functionPrototype, Identifier(exec, booleanPrototype->classInfo()->className))96 {97 putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);98 99 // no. of arguments for constructor100 putDirect(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontDelete | DontEnum);101 }102 103 // ECMA 15.6.2104 JSObject* constructBoolean(ExecState* exec, const ArgList& args)105 {106 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());107 obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec)));108 return obj;109 }110 111 static JSObject* constructWithBooleanConstructor(ExecState* exec, JSObject*, const ArgList& args)112 {113 return constructBoolean(exec, args);114 }115 116 ConstructType BooleanConstructor::getConstructData(ConstructData& constructData)117 {118 constructData.native.function = constructWithBooleanConstructor;119 return ConstructTypeNative;120 }121 122 // ECMA 15.6.1123 static JSValue* callBooleanConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)124 {125 return jsBoolean(args[0]->toBoolean(exec));126 }127 128 CallType BooleanConstructor::getCallData(CallData& callData)129 {130 callData.native.function = callBooleanConstructor;131 return CallTypeNative;132 }133 134 JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSValue* immediateBooleanValue)135 {136 BooleanObject* obj = new (exec) BooleanObject(exec->lexicalGlobalObject()->booleanPrototype());137 obj->setInternalValue(immediateBooleanValue);138 return obj;139 }140 141 33 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.