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

Ross Lillie ross.lillie at motorola.com
Wed Jun 17 15:53:22 PDT 2009


Greetings again,

Never mind.  If I understand things correctly, calling into the DOMDocument
from native code, to create a new Event instance, does not create the
corresponding JSObject in the window's global context.  Dispatching the
event to a target appears to be when the corresponding JSObject is created.

Any insight (such as the way scope chains are set up, etc, just guessing
here...) on why it works like this would be appreciated.

Again thanks in advance and regards,
Ross


On 6/17/09 4:29 PM, "Ross Lillie" <ross.lillie at motorola.com> wrote:

> 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
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev



More information about the webkit-dev mailing list