Ignore:
Timestamp:
Oct 4, 2011, 12:02:03 PM (14 years ago)
Author:
[email protected]
Message:

Implicitly add toString and valueOf to prototype when convertToType callback is provided
https://bugs.webkit.org/show_bug.cgi?id=69156

Reviewed by Geoffrey Garen.

Added callbacks for toString and valueOf which are implicitly added to a client object's
prototype if they provide a convertToType callback when declaring their class through
the JSC API.

  • API/JSCallbackFunction.cpp:

(JSC::JSCallbackFunction::toStringCallback):
(JSC::JSCallbackFunction::valueOfCallback):

  • API/JSCallbackFunction.h:
  • API/JSClassRef.cpp:

(OpaqueJSClass::prototype):

  • API/tests/testapi.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSClassRef.cpp

    r94701 r96627  
    244244     *  DerivedClass  |  DerivedClassPrototype
    245245     */
    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
    247258    if (!prototypeClass)
    248259        return 0;
Note: See TracChangeset for help on using the changeset viewer.