Hi All,
Whenever I get asynchronous events, I am calling Javascript callback
functions from C++ as described in the attached sample code.
>From the given sample code, I have written two functions in C++(i.e. *
myServerNotification_1* and *myServerNotification_2*), for calling same JS
callback function (i.e *notificationReceived*) with different argument
values on two different events.
In my application asynchronous events will come frequently and by using this
approach ( as attached in the sample code ) it is working fine sometimes and
sometimes its giving error like "Illegal opcode" or "caught signal 4
segmentation fault".
Can you please suggest me whether this approach is proper or not? If so
could you please suggest me where I am making mistake in the given sample
code.
or Is there any better approach other than which I mentioned above for
calling JS callback functions from C++ in webkit ?
We are using Webkit GTK port version 1.1.1 and the platform is ARM
Thanks in Advance.
Thanks,
Anil.V
int myServerNotification_1(unsigned char *mydata)
{
JSStringRef jsEmptyIString;
JSValueRef exception = 0x00;
JSStringRef functionName = JSStringCreateWithUTF8CString("notificationReceived");
WebkitWebFrame *frame_myserver = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
JSGlobalContextRef jsCtx = webkit_web_frame_get_global_context (frame_myserver);
JSValueRef jsArgs[2];
jsArgs[0] = JSValueMakeNumber(jsCtx,3);
JSValueRef functionValue = JSObjectGetProperty(jsCtx, JSContextGetGlobalObject(jsCtx), functionName, &exception);
JSStringRelease(functionName);
if( exception )
{
fprintf(stderr,"\n Exception occured in %s at %d \n",__FILE__,__LINE__);
return 0;
}
jsEmptyIString = JSStringCreateWithUTF8CString((const char *)mydata);
jsArgs[1] = JSValueMakeString(jsCtx, jsEmptyIString);
JSStringRelease(jsEmptyIString);
JSObjectRef jsFunctionObject = JSValueToObject(jsCtx, functionValue, &exception);
if( exception )
{
fprintf(stderr,"\n Excepion occured in %s at %d \n",__FILE__,__LINE__);
return 0;
}
JSObjectCallAsFunction(jsCtx,jsFunctionObject, NULL, 2, jsArgs, &exception);
if( exception )
{
fprintf(stderr,"\n Exception occured while calling the JS CallBack function \n");
return 0;
}
}
int myServerNotification_2(unsigned char *mydata)
{
JSStringRef jsEmptyIString;
JSValueRef exception = 0x00;
JSStringRef functionName = JSStringCreateWithUTF8CString("notificationReceived");
WebkitWebFrame *frame_myserver = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view));
JSGlobalContextRef jsCtx = webkit_web_frame_get_global_context (frame_myserver);
//JSGlobalContextRef jsCtx = js_context_reg;
JSValueRef jsArgs[2];
jsArgs[0] = JSValueMakeNumber(jsCtx,3);
JSValueRef functionValue = JSObjectGetProperty(jsCtx, JSContextGetGlobalObject(jsCtx), functionName, &exception);
JSStringRelease(functionName);
if( exception )
{
fprintf(stderr,"\n Exception occured in %s at %d \n",__FILE__,__LINE__);
return 0;
}
jsEmptyIString = JSStringCreateWithUTF8CString((const char *)mydata);
jsArgs[1] = JSValueMakeString(jsCtx, jsEmptyIString);
JSStringRelease(jsEmptyIString);
JSObjectRef jsFunctionObject = JSValueToObject(jsCtx, functionValue, &exception);
if( exception )
{
fprintf(stderr,"\n Excepion occured in %s at %d \n",__FILE__,__LINE__);
return 0;
}
JSObjectCallAsFunction(jsCtx,jsFunctionObject, NULL, 2, jsArgs, &exception);
if( exception )
{
fprintf(stderr,"\n Exception occured while calling the JS CallBack function \n");
return 0;
}
}
_______________________________________________
webkit-help mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-help