Ignore:
Timestamp:
Jul 7, 2006, 7:02:47 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


More API action.


  • Headerdoc finished

Semantic Changes:

  • Added a JSContextRef argument to many functions, because you need a JSContextRef for doing virtually anything. I expect to add this argument to even more functions in a future patch.


  • Removed the globalObjectPrototype argument to JSContextCreate because you can't create an object until you have a context, so it's impossible to pass a prototype object to JSContextCreate. That's OK because (1) there's no reason to give the global object a prototype and (2) if you really want to, you can just use a separate call to JSObjectSetPrototype.


  • Removed the JSClassRef argument to JSClassCreate because it was unnecessary, and you need to be able to make the global object's class before you've created a JSContext.


  • Added an optional exception parameter to JSFunctionMakeWithBody because anything less would be uncivilized.


  • Made the return value parameter to JSObjectGetProperty optional to match all other return value parameters in the API.


  • Made JSObjectSetPrivate/JSObjectGetPrivate work on JSCallbackFunctions and JSCallbackConstructors. You could use an abstract base class or strategic placement of m_privateData in the class structure to implement this, but the former seemed like overkill, and the latter seemed too dangerous.


  • Fixed a bug where JSPropertyEnumeratorGetNext would skip the first property.

Cosmetic Changes:

  • Reversed the logic of the JSChar #ifdef to avoid confusing headerdoc


  • Removed function names from @function declarations because headeroc can parse them automatically, and I wanted to rule out manual mismatch.
  • Changed Error::create to take a const UString& instead of a UString* because it was looking at me funny.


  • Renamed JSStringBufferCreateWithCFString to JSStringBufferCreateCF because the latter is more concise and it matches JSStringBufferCreateUTF8.


  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::getOwnPropertySlot): (KJS::JSCallbackObject::put): (KJS::JSCallbackObject::deleteProperty): (KJS::JSCallbackObject::getPropertyList): (KJS::JSCallbackObject::toBoolean): (KJS::JSCallbackObject::toNumber): (KJS::JSCallbackObject::toString):
  • API/JSClassRef.cpp: (JSClassCreate):
  • API/JSContextRef.cpp: (JSContextCreate): (JSContextSetException):
  • API/JSContextRef.h:
  • API/JSNode.c: (JSNodePrototype_class): (JSNode_class):
  • API/JSNodeList.c: (JSNodeListPrototype_class): (JSNodeList_class):
  • API/JSObjectRef.cpp: (JSObjectGetProperty): (JSObjectGetPrivate): (JSObjectSetPrivate): (JSObjectCallAsFunction): (JSObjectCallAsConstructor): (JSPropertyEnumeratorGetNext):
  • API/JSObjectRef.h:
  • API/JSStringBufferRef.cpp: (JSStringBufferCreateCF):
  • API/JSStringBufferRef.h:
  • API/JSValueRef.cpp: (JSValueIsInstanceOf):
  • API/JSValueRef.h:
  • API/minidom.c: (main):
  • API/minidom.js:
  • API/testapi.c: (MyObject_hasProperty): (MyObject_setProperty): (MyObject_deleteProperty): (MyObject_getPropertyList): (MyObject_convertToType): (MyObject_class): (main):
  • JavaScriptCore.exp:
File:
1 edited

Legend:

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

    r15168 r15224  
    7171}
    7272
    73 JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber)
     73JSObjectRef JSFunctionMakeWithBody(JSContextRef context, JSStringBufferRef body, JSStringBufferRef sourceURL, int startingLineNumber, JSValueRef* exception)
    7474{
    7575    JSLock lock;
     
    7777    ExecState* exec = toJS(context);
    7878    UString::Rep* bodyRep = toJS(body);
    79     UString::Rep* sourceURLRep = toJS(sourceURL);
     79    UString jsSourceURL = UString(toJS(sourceURL));
     80
    8081    if (!bodyRep)
    8182        bodyRep = &UString::Rep::null;
    82     RefPtr<FunctionBodyNode> bodyNode = Parser::parse(UString(sourceURLRep), startingLineNumber, bodyRep->data(), bodyRep->size(), NULL, NULL, NULL);
    83     if (!bodyNode)
     83   
     84    int sid;
     85    int errLine;
     86    UString errMsg;
     87    RefPtr<FunctionBodyNode> bodyNode = Parser::parse(jsSourceURL, startingLineNumber, bodyRep->data(), bodyRep->size(), &sid, &errLine, &errMsg);
     88    if (!bodyNode) {
     89        if (exception)
     90            *exception = Error::create(exec, SyntaxError, errMsg, errLine, sid, jsSourceURL);
    8491        return NULL;
     92    }
    8593
    8694    ScopeChain scopeChain;
     
    127135    UString::Rep* nameRep = toJS(propertyName);
    128136
    129     *value = toRef(jsObject->get(exec, Identifier(nameRep)));
    130     return !JSValueIsUndefined(*value);
     137    JSValue* jsValue = jsObject->get(exec, Identifier(nameRep));
     138    if (value)
     139        *value = toRef(jsValue);
     140    return !jsValue->isUndefined();
    131141}
    132142
     
    161171    JSObject* jsObject = toJS(object);
    162172   
    163     if (!jsObject->inherits(&JSCallbackObject::info))
    164         return 0;
    165    
    166     return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
     173    if (jsObject->inherits(&JSCallbackObject::info))
     174        return static_cast<JSCallbackObject*>(jsObject)->getPrivate();
     175   
     176    if (jsObject->inherits(&JSCallbackFunction::info))
     177        return static_cast<JSCallbackFunction*>(jsObject)->getPrivate();
     178   
     179    if (jsObject->inherits(&JSCallbackConstructor::info))
     180        return static_cast<JSCallbackConstructor*>(jsObject)->getPrivate();
     181   
     182    return 0;
    167183}
    168184
     
    171187    JSObject* jsObject = toJS(object);
    172188   
    173     if (!jsObject->inherits(&JSCallbackObject::info))
    174         return false;
    175    
    176     static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
    177     return true;
     189    if (jsObject->inherits(&JSCallbackObject::info)) {
     190        static_cast<JSCallbackObject*>(jsObject)->setPrivate(data);
     191        return true;
     192    }
     193       
     194    if (jsObject->inherits(&JSCallbackFunction::info)) {
     195        static_cast<JSCallbackFunction*>(jsObject)->setPrivate(data);
     196        return true;
     197    }
     198       
     199    if (jsObject->inherits(&JSCallbackConstructor::info)) {
     200        static_cast<JSCallbackConstructor*>(jsObject)->setPrivate(data);
     201        return true;
     202    }
     203   
     204    return false;
    178205}
    179206
     
    194221    for (size_t i = 0; i < argc; i++)
    195222        argList.append(toJS(argv[i]));
    196    
    197     JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList));
     223
     224    JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false
    198225    if (exec->hadException()) {
    199226        if (exception)
     
    221248        argList.append(toJS(argv[i]));
    222249   
    223     JSObjectRef result = toRef(jsObject->construct(exec, argList));
     250    JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false
    224251    if (exec->hadException()) {
    225252        if (exception)
     
    260287    ReferenceListIterator& iterator = enumerator->iterator;
    261288    if (iterator != enumerator->list.end()) {
     289        JSStringBufferRef result = toRef(iterator->getPropertyName(exec).ustring().rep());
    262290        iterator++;
    263         return toRef(iterator->getPropertyName(exec).ustring().rep());
     291        return result;
    264292    }
    265293    return 0;
Note: See TracChangeset for help on using the changeset viewer.