Subj : Javascript function from 'C' with thread To : netscape.public.mozilla.jseng From : ismy_br Date : Fri Sep 17 2004 03:18 pm Hi Everyone! - Using Mozilla 1.7.3 sources I have some problems in execute Javascript function from 'C' Itīs crashing because I canīt use the global context at same time. here is my code: ===================================================== JSContext *cx_glob; JSObject *obj_glob; /* This thread executes Javascript code from C for Mozilla HTML page */ /* This Javascript code is a document.write that I have to send to the HTML page from Mozilla */ int thread_display() { jsval rval_thread; while(foo) { if(bar) { JS_BeginRequest(cx_glob); JS_EvaluateScript(cx_glob, obj_glob, "script()", 8, "", 0, &rval_thread); JS_EndRequest(cx_glob); } } } /* I call this function from Javascript like: OnLoad=classname.getcontext() */ /* In this function I get the context and the object passing to global and init thread*/ /* Its called when the HTML page is loaded event*/ static JSBool classname_getcontext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { cx_glob = cx; obj_glob = obj; evento_thread = pthread_create(&thdisp, NULL, (void*)&thread_display, NULL); return JS_TRUE; } ===================================================== Itīs the better way to call Javascript functions from C code? I need the thread to get events of my control. Iīve remember that The context may be used by only one thread at a time! I tried the function JS_SetContextThread that ties context to the current thread for exclusive use. But I think that the other threads need to be in process to execute the document.write to the HTML page. Thanks a lot! Regards, Jacknill .