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

Alexey Proskuryakov ap at webkit.org
Thu Nov 13 03:43:53 PST 2008

Nov 13, 2008, в 1:22 PM, Daniel Waylonis написал(а):

> 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.

You need to evaluate the JavaScript source, then look up the function  
by name as a global object property:

JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef  
script, JSObjectRef thisObject, JSStringRef sourceURL, int  
startingLineNumber, JSValueRef* exception);
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object,  
JSStringRef propertyName, JSValueRef* exception)

Here, object will be a result of JSContextGetGlobalObject(), and  
propertyName will be "AddOne".

- WBR, Alexey Proskuryakov

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

More information about the webkit-dev mailing list