Changeset 96627 in webkit
- Timestamp:
- Oct 4, 2011 12:02:03 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSCallbackFunction.cpp
r96164 r96627 31 31 #include "CodeBlock.h" 32 32 #include "ExceptionHelpers.h" 33 #include "JSCallbackObject.h" 33 34 #include "JSFunction.h" 34 35 #include "FunctionPrototype.h" … … 89 90 } 90 91 92 JSValueRef JSCallbackFunction::toStringCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef* exception) 93 { 94 JSObject* object = toJS(thisObject); 95 if (object->inherits(&JSCallbackObject<JSNonFinalObject>::s_info)) 96 return static_cast<JSCallbackObject<JSNonFinalObject>*>(object)->classRef()->convertToType(ctx, thisObject, kJSTypeString, exception); 97 if (object->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) 98 return static_cast<JSCallbackObject<JSGlobalObject>*>(object)->classRef()->convertToType(ctx, thisObject, kJSTypeString, exception); 99 return 0; 100 } 101 102 JSValueRef JSCallbackFunction::valueOfCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef* exception) 103 { 104 JSObject* object = toJS(thisObject); 105 if (object->inherits(&JSCallbackObject<JSNonFinalObject>::s_info)) 106 return static_cast<JSCallbackObject<JSNonFinalObject>*>(object)->classRef()->convertToType(ctx, thisObject, kJSTypeNumber, exception); 107 if (object->inherits(&JSCallbackObject<JSGlobalObject>::s_info)) 108 return static_cast<JSCallbackObject<JSGlobalObject>*>(object)->classRef()->convertToType(ctx, thisObject, kJSTypeNumber, exception); 109 return 0; 110 } 111 112 91 113 } // namespace JSC -
trunk/Source/JavaScriptCore/API/JSCallbackFunction.h
r96164 r96627 56 56 } 57 57 58 static JSValueRef toStringCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 59 static JSValueRef valueOfCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 60 58 61 private: 59 62 virtual CallType getCallDataVirtual(CallData&); -
trunk/Source/JavaScriptCore/API/JSClassRef.cpp
r94701 r96627 244 244 * DerivedClass | DerivedClassPrototype 245 245 */ 246 246 247 if (convertToType) { 248 if (!prototypeClass) 249 prototypeClass = OpaqueJSClass::create(&kJSClassDefinitionEmpty).leakRef(); 250 if (!prototypeClass->m_staticFunctions) 251 prototypeClass->m_staticFunctions = new OpaqueJSClassStaticFunctionsTable; 252 const Identifier& toString = exec->propertyNames().toString; 253 const Identifier& valueOf = exec->propertyNames().valueOf; 254 prototypeClass->m_staticFunctions->add(StringImpl::create(toString.characters(), toString.length()), new StaticFunctionEntry(&JSCallbackFunction::toStringCallback, 0)); 255 prototypeClass->m_staticFunctions->add(StringImpl::create(valueOf.characters(), valueOf.length()), new StaticFunctionEntry(&JSCallbackFunction::valueOfCallback, 0)); 256 } 257 247 258 if (!prototypeClass) 248 259 return 0; -
trunk/Source/JavaScriptCore/API/tests/testapi.js
r87588 r96627 155 155 shouldBe("MyObject ? 1 : 0", true); // toBoolean 156 156 shouldBe("+MyObject", 1); // toNumber 157 shouldBe("(MyObject.toString())", "[object MyObject]"); // toString 158 shouldBe("String(MyObject)", "MyObjectAsString"); // type conversion to string 157 shouldBe("(Object.prototype.toString.call(MyObject))", "[object MyObject]"); // Object.prototype.toString 158 shouldBe("(MyObject.toString())", "MyObjectAsString"); // toString 159 shouldBe("String(MyObject)", "MyObjectAsString"); // toString 159 160 shouldBe("MyObject - 0", 1); // toNumber 161 shouldBe("MyObject.valueOf()", 1); // valueOf 160 162 161 163 shouldBe("typeof MyConstructor", "object"); -
trunk/Source/JavaScriptCore/ChangeLog
r96613 r96627 1 2011-10-04 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Implicitly add toString and valueOf to prototype when convertToType callback is provided 4 https://bugs.webkit.org/show_bug.cgi?id=69156 5 6 Reviewed by Geoffrey Garen. 7 8 Added callbacks for toString and valueOf which are implicitly added to a client object's 9 prototype if they provide a convertToType callback when declaring their class through 10 the JSC API. 11 12 * API/JSCallbackFunction.cpp: 13 (JSC::JSCallbackFunction::toStringCallback): 14 (JSC::JSCallbackFunction::valueOfCallback): 15 * API/JSCallbackFunction.h: 16 * API/JSClassRef.cpp: 17 (OpaqueJSClass::prototype): 18 * API/tests/testapi.js: 19 1 20 2011-10-03 Jon Lee <jonlee@apple.com> 2 21
Note: See TracChangeset
for help on using the changeset viewer.