[webkit-help] JSC How to obtain an available JSContext object in native C function

bins_mail at sina.com bins_mail at sina.com
Mon Mar 12 00:04:33 PDT 2012



Dear Sirs:
    I decide to use the JavascriptCore's API of the Webkit-1.2.7 to do some interactions between C code and javascript. Now I find it difficultied to get an appropriate JSContextRef when I intend to use it to call a Javascript function in the native C method.  I have tried some functions in the JSContextRef.h, but it seemed that did not work well.
Here is part of my codes:
...
static void
on_foo(gpointer user_data)
{
    ...
    JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);

    JSStringRef body = JSStringCreateWithUTF8CString("alert(\"Hello World\");");

    JSObjectRef function = JSObjectMakeFunction(context, NULL, 0, NULL, body, NULL, 0, NULL);
    
    JSValueRef result = JSObjectCallAsFunction(context,function, NULL, 0, NULL, 0);
    ...
}
...
  on_foo is a native callback in C code part and it seems that the javascript function "alert()" will not be called due to the context object not handling well. So how should I modify my code to build a right jscontext ref ?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20120312/26bbffe2/attachment.html>


More information about the webkit-help mailing list