Ignore:
Timestamp:
Jul 16, 2006, 3:17:04 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Added names to functions.


  • Removed GetPrivate/SetPrivate from callbackFunctions and callbackConstructors. The private data idiom is that a JS object stores its native implementation as private data. For functions and constructors, the native implementation is nothing more than the callback they already store, so supporting private data, too, confuses the idiom. If you *really* want, you can still create a custom function with private data.
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::JSCallbackFunction):
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::staticFunctionGetter):
  • API/JSObjectRef.cpp: (JSObjectMakeFunction): (JSObjectMakeFunctionWithBody): (JSObjectGetPrivate): (JSObjectSetPrivate):
  • API/JSObjectRef.h:
  • API/minidom.c: (main):
  • API/testapi.c: (main):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r15468 r15469  
    7676}
    7777
    78 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction)
    79 {
    80     JSLock lock;
    81     ExecState* exec = toJS(context);
    82     return toRef(new JSCallbackFunction(exec, callAsFunction));
     78JSObjectRef JSObjectMakeFunction(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
     79{
     80    JSLock lock;
     81    ExecState* exec = toJS(context);
     82    Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous");
     83   
     84    return toRef(new JSCallbackFunction(exec, callAsFunction, nameID));
    8385}
    8486
     
    9597   
    9698    ExecState* exec = toJS(context);
    97     UString::Rep* nameRep = name ? toJS(name) : &UString::Rep::null;
    9899    UString::Rep* bodyRep = toJS(body);
    99100    UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
    100101   
    101     Identifier nameIdentifier = nameRep ? Identifier(nameRep) : Identifier("anonymous");
     102    Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous");
    102103   
    103104    List args;
     
    106107    args.append(jsString(UString(bodyRep)));
    107108
    108     JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameIdentifier, UString(sourceURLRep), startingLineNumber);
     109    JSObject* result = exec->dynamicInterpreter()->builtinFunction()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
    109110    if (exec->hadException()) {
    110111        if (exception)
     
    220221        return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
    221222   
    222     if (jsObject->inherits(&JSCallbackFunction::info))
    223         return static_cast<JSCallbackFunction*>(jsObject)->getPrivate();
    224    
    225     if (jsObject->inherits(&JSCallbackConstructor::info))
    226         return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate();
    227    
    228223    return 0;
    229224}
     
    238233    }
    239234       
    240     if (jsObject->inherits(&JSCallbackFunction::info)) {
    241         static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data);
    242         return true;
    243     }
    244        
    245     if (jsObject->inherits(&JSCallbackConstructor::info)) {
    246         static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data);
    247         return true;
    248     }
    249    
    250235    return false;
    251236}
Note: See TracChangeset for help on using the changeset viewer.