Changeset 15484 in webkit for trunk/JavaScriptCore/API/JSNode.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/JSNode.c

    r15483 r15484  
    157157};
    158158
     159static void JSNode_initialize(JSContextRef context, JSObjectRef object)
     160{
     161    Node* node = JSObjectGetPrivate(object);
     162    assert(node);
     163
     164    Node_ref(node);
     165}
     166
    159167static void JSNode_finalize(JSObjectRef object)
    160168{
     
    171179        JSClassDefinition definition = kJSClassDefinitionNull;
    172180        definition.staticValues = JSNode_staticValues;
     181        definition.initialize = JSNode_initialize;
    173182        definition.finalize = JSNode_finalize;
    174183
     
    182191    static JSObjectRef prototype;
    183192    if (!prototype) {
    184         prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL, NULL);
     193        prototype = JSObjectMake(context, JSNodePrototype_class(context), NULL);
    185194        JSValueProtect(context, prototype);
    186195    }
     
    190199JSObjectRef JSNode_new(JSContextRef context, Node* node)
    191200{
    192     Node_ref(node);
    193 
    194     JSObjectRef jsNode = JSObjectMake(context, JSNode_class(context), JSNode_prototype(context), NULL);
    195     JSObjectSetPrivate(jsNode, node);
    196     return jsNode;
     201    return JSObjectMakeWithData(context, JSNode_class(context), JSNode_prototype(context), node);
    197202}
    198203
Note: See TracChangeset for help on using the changeset viewer.