[webkit-dev] Attaching property to external (Obj-c) synthetic event

Ross Lillie ross.lillie at motorola.com
Wed Jun 17 14:29:54 PDT 2009


Greetings,

I need to generate a synthetic event (DOM Level 2) from external (native)
code and inject into the current DOM structure.  Furthermore, this event
needs to have a custom property attached, to pass external data into the
current Javascript context.

Generating and dispatching the event from external code is straightforward.
>From the delegate method (didFinishLoadForFrame) of the WebFrame, I can
access the DOMDocument as well as the JSGlobalContextRef.  Using the
DOMDocument reference I create a new Event instance via the createEvent()
method and initialize to the desired type.  This event can then be
dispatched to a specified target in the DOM without any problems.

However, at this point (before dispatch) I would like to attach a JavaScript
property to the corresponding JSObject of the DOMEvent.  I assumed that this
could be accomplished by retrieving the JSObject reference from the
DOMEvent, but this appears not to work, as calling the [(DOMEvent)ev
JSObject] method returns NULL. Has the corresponding Javascript Object been
created yet, or is it created when dispatched to the desired target?

What am I missing?  It appears that my understanding of the
WindowScriptObject interface is not what it should be.  Any insight would be
appreciated.

Thanks in advance, and regards
Ross

--
Example (abbreviated) code snippet:

>From the window didFinishLoadForFrame method:

    JSGlobalContextRef ctx = [frame globalContext];
    DOMDocument *doc = [frame DOMDocument];

    DOMEvent *ev = [doc createEvent:@"Events"];
    [ev initEvent:@"eventType" canBubbleArg:YES cancelableArg:NO];

// At this point I can select the event target via the DOMDocument
// getElementByID method and dispatch my custom event without problems.
// However, I'm trying to attach a custom property to the event as
// follows:

    JSObjectRef evObj = [ev JSObject];  // THIS RETURNS NULL!!

// Intent was to use the JavaScriptCore APIs to add a custom property to the
// DOMEvent object created above



More information about the webkit-dev mailing list