[webkit-dev] JavaScriptCore: Lookup object by string?

Daniel Waylonis danw at nekotech.com
Thu Nov 13 02:22:34 PST 2008


I'm using JavaScriptCore Framework in a Cocoa program.  I'm trying to  
evaluate a function in the JavaScript code via C, but I'm having  
problems with figuring out how to get a proper reference to that  
function.  I'm trying to have behavior analogous to the setTimeout()  
function, which takes a string which will be evaluated after the time  
has lapsed.

function AddOne(num) {
   return num + 1;

var thirtyThree = myClass.callFunction("AddOne()", 32);

In myClass's callFunction(), I need to convert this passed in string  
value to a function which will return "true" to JSObjectIsFunction()  
so that I can then use the JSObjectCallAsFunction() function.

I've tried making a JSValue out of the string passed in and then:
JSObjectRef fnObj = JSValueToObject(globalcontext, fnValue);

but that doesn't come back as a valid function object.

I looked inside of the JavaScriptCore Framework source,  
WebScriptObject.mm, callWebScriptMethod:withArguments: and it looks  
like it's looking up the string from a hash table associated with the  
ExecState, which I don't have access to inside of the public API for  
the JavaScriptCore Framework.

Any suggestions on how I can accomplish this lookup?

Dan Waylonis                    danw at nekotech.com
nekotech SOFTWARE
650.964.2490 Voice / Fax

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20081113/325cab00/attachment.html>

More information about the webkit-dev mailing list