Changeset 15443 in webkit for trunk/JavaScriptCore/API/testapi.c


Ignore:
Timestamp:
Jul 14, 2006, 9:10:31 PM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Finalized exception handling in the API.


setProperty can throw because it throws for built-in arrays. getProperty
and deleteProperty can throw because setProperty can throw and we want
to be consistent, and also because they seem like "actions." callAsFunction,
callAsConstructor, and hasInstance can throw, because they caan throw for
all built-ins.


toBoolean can't throw because it's defined that way in the spec.


  • Documented that toBoolean and toObject can't be overridden by custom objects because they're defined that way in the spec.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/testapi.c

    r15437 r15443  
    3939static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
    4040{
    41     if (JSValueToBoolean(context, value, NULL) != expectedValue)
     41    if (JSValueToBoolean(context, value) != expectedValue)
    4242        fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue);
    4343}
     
    106106}
    107107
    108 static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     108static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
    109109{
    110110    UNUSED_PARAM(context);
     
    160160        return true;
    161161   
     162    if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
     163        *exception = JSValueMakeNumber(2);
     164        return false;
     165    }
     166
    162167    return false;
    163168}
     
    206211
    207212    JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
    208     JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString), NULL);
     213    JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, NULL), NULL);
    209214    JSStringRelease(numberString);
    210215
    211     return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor);
     216    return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, NULL);
    212217}
    213218
     
    218223   
    219224    switch (type) {
    220     case kJSTypeBoolean:
    221         *exception = JSValueMakeNumber(2);
    222         return NULL;
    223225    case kJSTypeNumber:
    224226        return JSValueMakeNumber(1);
     
    288290    if (argc > 0) {
    289291        JSStringRef value = JSStringCreateWithUTF8CString("value");
    290         JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone);
     292        JSObjectSetProperty(context, result, value, argv[0], kJSPropertyAttributeNone, NULL);
    291293        JSStringRelease(value);
    292294    }
     
    371373    assert(didInitialize);
    372374    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
    373     JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone);
     375    JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL);
    374376    JSStringRelease(myObjectIString);
    375377   
     
    389391    assert(exception);
    390392   
    391     exception = NULL;
    392     assert(!JSValueToBoolean(context, myObject, &exception));
    393     assert(exception);
     393    assert(JSValueToBoolean(context, myObject));
    394394   
    395395    exception = NULL;
     
    505505   
    506506    JSStringRef array = JSStringCreateWithUTF8CString("Array");
    507     v = JSObjectGetProperty(context, globalObject, array);
     507    v = JSObjectGetProperty(context, globalObject, array, NULL);
    508508    assert(v);
    509509    JSObjectRef arrayConstructor = JSValueToObject(context, v, NULL);
     
    511511    result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
    512512    assert(result);
    513     assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor));
    514     assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor));
     513    assert(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
     514    assert(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(), arrayConstructor, NULL));
    515515   
    516516    JSStringRef functionBody;
     
    521521    assert(!JSObjectMakeFunctionWithBody(context, functionBody, NULL, 1, &exception));
    522522    assert(JSValueIsObject(exception));
    523     v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line);
     523    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
    524524    assert(v);
    525525    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)
     
    537537    JSStringRef print = JSStringCreateWithUTF8CString("print");
    538538    JSObjectRef printFunction = JSObjectMakeFunction(context, print_callAsFunction);
    539     JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone);
     539    JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL);
    540540    JSStringRelease(print);
    541541   
     
    545545    JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
    546546    JSObjectRef myConstructor = JSObjectMakeConstructor(context, myConstructor_callAsConstructor);
    547     JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone);
     547    JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL);
    548548    JSStringRelease(myConstructorIString);
    549549   
     
    552552   
    553553    o = JSObjectMake(context, NULL, NULL);
    554     JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone);
    555     JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(1), kJSPropertyAttributeDontEnum);
     554    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone, NULL);
     555    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(1), kJSPropertyAttributeDontEnum, NULL);
    556556    JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(o);
    557557    int count = 0;
Note: See TracChangeset for help on using the changeset viewer.