Changeset 15474 in webkit for trunk/JavaScriptCore/API


Ignore:
Timestamp:
Jul 16, 2006, 7:00:40 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Change getProperty* to return undefined, rather than NULL, for missing properties, since that's what the spec says. Also added exception out parameters to the *Index functions, because they can call through to the regular functions, which can throw for custom objects.
  • API/JSObjectRef.cpp: (JSObjectGetProperty): (JSObjectGetPropertyAtIndex): (JSObjectSetPropertyAtIndex):
  • API/JSObjectRef.h:
  • API/testapi.c: (main):
Location:
trunk/JavaScriptCore/API
Files:
3 edited

Legend:

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

    r15469 r15474  
    149149
    150150    JSValue* jsValue = jsObject->get(exec, Identifier(nameRep));
    151     if (jsValue->isUndefined())
    152         jsValue = 0;
    153151    if (exec->hadException()) {
    154152        if (exception)
     
    175173}
    176174
    177 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex)
     175JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
    178176{
    179177    JSLock lock;
     
    182180
    183181    JSValue* jsValue = jsObject->get(exec, propertyIndex);
    184     if (jsValue->isUndefined())
    185         return 0;
     182    if (exec->hadException()) {
     183        if (exception)
     184            *exception = toRef(exec->exception());
     185        exec->clearException();
     186    }
    186187    return toRef(jsValue);
    187188}
    188189
    189190
    190 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value)
     191void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
    191192{
    192193    JSLock lock;
     
    196197   
    197198    jsObject->put(exec, propertyIndex, jsValue);
     199    if (exec->hadException()) {
     200        if (exception)
     201            *exception = toRef(exec->exception());
     202        exec->clearException();
     203    }
    198204}
    199205
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15473 r15474  
    448448@param propertyName A JSString containing the property's name.
    449449@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    450 @result The property's value if object has the property, otherwise NULL.
     450@result The property's value if object has the property, otherwise the undefined value.
    451451*/
    452452JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
     
    481481@param object The JSObject whose property you want to get.
    482482@param propertyIndex The property's name as a number
    483 @result The property's value if object has the property, otherwise NULL.
    484 @discussion This is equivalent to getting a property by a string name containing the number, but allows faster access to JS arrays.
    485 */
    486 JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex);
     483@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     484@result The property's value if object has the property, otherwise the undefined value.
     485@discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays.
     486*/
     487JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
    487488
    488489/*!
     
    493494@param propertyIndex The property's name as a number
    494495@param value A JSValue to use as the property's value.
    495 @discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays.
    496 */
    497 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value);
     496@param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
     497@discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but it enables optimized access to JavaScript arrays.
     498*/
     499void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
    498500
    499501/*!
  • trunk/JavaScriptCore/API/testapi.c

    r15473 r15474  
    116116        || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
    117117        || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")
    118         || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")) {
     118        || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")
     119        || JSStringIsEqualToUTF8CString(propertyName, "0")) {
    119120        return true;
    120121    }
     
    138139    if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
    139140        return JSValueMakeUndefined();
     141    }
     142   
     143    if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
     144        *exception = JSValueMakeNumber(1);
     145        return JSValueMakeNumber(1);
    140146    }
    141147   
     
    415421    assert(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(1), &exception));
    416422    assert(exception);
     423   
     424    exception = NULL;
     425    JSObjectGetPropertyAtIndex(context, myObject, 0, &exception);
     426    assert(1 == JSValueToNumber(context, exception, NULL));
    417427
    418428    assertEqualsAsBoolean(jsUndefined, false);
     
    525535   
    526536    JSStringRef array = JSStringCreateWithUTF8CString("Array");
    527     v = JSObjectGetProperty(context, globalObject, array, NULL);
    528     assert(v);
    529     JSObjectRef arrayConstructor = JSValueToObject(context, v, NULL);
     537    JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
    530538    JSStringRelease(array);
    531539    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    532540    assert(result);
     541    assert(JSValueIsObject(result));
    533542    assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
    534543    assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor, NULL));
    535    
     544
     545    o = JSValueToObject(context, result, NULL);
     546    exception = NULL;
     547    assert(JSValueIsUndefined(JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
     548    assert(!exception);
     549   
     550    JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(1), &exception);
     551    assert(!exception);
     552   
     553    exception = NULL;
     554    assert(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception));
     555    assert(!exception);
     556
    536557    JSStringRef functionBody;
    537558    JSObjectRef function;
     
    543564    assert(JSValueIsObject(exception));
    544565    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
    545     assert(v);
    546566    assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact)
    547567    JSStringRelease(functionBody);
     
    619639    v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
    620640    assert(JSValueIsEqual(context, v, o, NULL));
     641   
     642   
    621643   
    622644    char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
Note: See TracChangeset for help on using the changeset viewer.