[webkit-dev] Question about JSGlobalObject and RootObject use in the objc bridge

Rémy Saissy remy.saissy at gmail.com
Sun Oct 30 07:49:01 PDT 2011

I've just wrote a small patch to webkit in order to have javascript string
parameters being bridged to NSString.

It works fine but I think it can be improved, but to do it, I first need
some explanations from you guys :).

What I've found out is that in WebCore::objc_utility.mm, when the method

*ObjcValue convertValueToObjcValue(ExecState* exec, JSValue value,
ObjcValueType type)*
Receives an ObjcObjectType it tries to retrieve both the originRootObject
and the rootObject. In the case of a non object parameter, both are be the
The issue is that:

*JSGlobalObject *originGlobalObject = exec->dynamicGlobalObject();*

*RootObject* originRootObject = findRootObject(originGlobalObject);*

Returns the originGlobalObject but *findRootObject()* returns nil.

My patch adds an if else statement at the end of this case block but I
think that the correct way to fix the issue is to let the conversion to

*[webScriptObjectClass() _convertValueToObjcValue:value
and to figure out why there is no originRootObject return (and thus no
rootObject). From my current understanding, it is because the following
method in *runtime_root.cpp*

*PassRefPtr<RootObject> RootObject::create(const void* nativeHandle,
JSGlobalObject* globalObject)*

is not called everytime it should be.  For example, I think it should be
called in *WebScriptObject.mm:- (*void*)setValue:(*id*)*value* forKey:(*
NSString* *)**key* so the root object at this time will be in in the
rootObjectSet of runtime_root.cpp.* *But since I am not sure to correctly
understand what is the difference between a RootObject and a JSGlobalObject
and how they interact with each other and with the ExecState, I prefer to
ask ;).

It would be nice if somebody could explain me or at least point me to some
useful resources.

Rémy Saissy
Picassa: http://picasaweb.google.com/remy.saissy
Blog: http://blog.remysaissy.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20111030/04a1c52f/attachment.html>

More information about the webkit-dev mailing list