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/JSCallbackFunction.cpp

    r96164 r96627  
    3131#include "CodeBlock.h"
    3232#include "ExceptionHelpers.h"
     33#include "JSCallbackObject.h"
    3334#include "JSFunction.h"
    3435#include "FunctionPrototype.h"
     
    8990}
    9091
     92JSValueRef 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
     102JSValueRef 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
    91113} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.