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


Ignore:
Timestamp:
Jul 17, 2006, 3:49:28 AM (19 years ago)
Author:
ggaren
Message:

Reviewed by Maciej.


  • Removed the exception parameter from the initialize callback and, by extension, JSObjectMake. We have never had a need for exceptions when iniitializing, so the parameter seemed likely to "get in the way."


Also, an exception in JavaScript is thrown in response to input --
"invalid URL", "index not a number", etc., so it's the job of the
constructor function, not the initialize method, to throw.


If initialize *really* wants to throw, it can communicate the throw to
the constructor through the constructed object's private data (e.g., set
it to NULL, signaling to the consntructor that initialization failed.)


  • Added JSObjectMakeWithData, which enables a constructor to set private data on an object *before* it has been initialized. That way, the initialize methods can properly operate on the data.
  • API/JSNode.c: Moved ref into the initialize method, for better encapsulation, now that it's possible.
  • API/JSNodeList.c: ditto
  • API/minidom.c: (main): Do more aggressive garbage collection to test ref/deref and initialize/finalize.
  • API/minidom.js: store childNodes in a temporary so it doesn't get re-created like a thousand times. This makes debugging ref/deref easier
File:
1 edited

Legend:

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

    r15483 r15484  
    101101
    102102static bool didInitialize = false;
    103 static void MyObject_initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception)
     103static void MyObject_initialize(JSContextRef context, JSObjectRef object)
    104104{
    105105    UNUSED_PARAM(context);
     
    291291}
    292292
    293 static void Base_initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception)
     293static void Base_initialize(JSContextRef context, JSObjectRef object)
    294294{
    295295    assert(!JSObjectGetPrivate(object));
     
    316316}
    317317
    318 static void Derived_initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception)
     318static void Derived_initialize(JSContextRef context, JSObjectRef object)
    319319{
    320320    assert((void*)1 == JSObjectGetPrivate(object));
     
    362362    UNUSED_PARAM(constructorObject);
    363363   
    364     JSObjectRef result = JSObjectMake(context, NULL, 0, NULL);
     364    JSObjectRef result = JSObjectMake(context, NULL, NULL);
    365365    if (argumentCount > 0) {
    366366        JSStringRef value = JSStringCreateWithUTF8CString("value");
     
    391391    JSValueRef jsOne = JSValueMakeNumber(context, 1);
    392392    JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
    393     JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context), NULL);
     393    JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, JSValueMakeNull(context));
    394394
    395395    // FIXME: test funny utf8 characters
     
    445445#endif // __APPLE__
    446446
    447     JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL, NULL);
     447    JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
    448448    assert(didInitialize);
    449449    JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
     
    559559#endif // __APPLE__
    560560   
    561     jsGlobalValue = JSObjectMake(context, NULL, NULL, NULL);
     561    jsGlobalValue = JSObjectMake(context, NULL, NULL);
    562562    JSValueProtect(context, jsGlobalValue);
    563563    JSGarbageCollect(context);
     
    667667    assert(!JSObjectGetPrivate(myConstructor));
    668668   
    669     o = JSObjectMake(context, NULL, NULL, NULL);
     669    o = JSObjectMake(context, NULL, NULL);
    670670    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
    671671    JSObjectSetProperty(context, o, jsCFIString,  JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
     
    690690    assert(JSValueIsEqual(context, v, o, NULL));
    691691   
    692     exception = NULL;
    693     o = JSObjectMake(context, Derived_class(context), NULL, &exception);
    694     assert(!exception);
     692    o = JSObjectMake(context, Derived_class(context), NULL);
    695693    assert(JSObjectGetPrivate(o) == (void*)2);
    696694    o = NULL;
     
    713711
    714712    // Allocate a few dummies so that at least one will be collected
    715     JSObjectMake(context, MyObject_class(context), NULL, NULL);
    716     JSObjectMake(context, MyObject_class(context), NULL, NULL);
     713    JSObjectMake(context, MyObject_class(context), NULL);
     714    JSObjectMake(context, MyObject_class(context), NULL);
    717715    JSGarbageCollect(context);
    718716    assert(MyObject_didFinalize);
Note: See TracChangeset for help on using the changeset viewer.