Subj : Document, window objects ... not accessible from my jsFunction To : netscape.public.mozilla.jseng From : Béatrice Philippe Date : Sun Jan 30 2005 10:18 pm hello ! i'm still trying to execute my newly created jsFunction, but i have some problems with all objects like 'document', 'window' 'navigator' ... that my app cannot access. Here is my code: //consider the following function i want to create and add in the global object of the current domWindow (in fact, i take an existing javascript function i got from nsiDomHtmlScriptObject, get its source in a string, and create a new one with a new javascript code in my c++ app): ...... char * = "var i = 'http: '; var j = 'yahoo.com'; var x = document; var y = i+j; y.toString();" // the following code fails (see below) because 'document' object maybe is not known. And without 'x=document', JS_CallFunction() runs very well (why ????) : ..... nsCOMPtr scriptGlobal(do_QueryInterface(mDomWindow)); nsIScriptContext * aScriptContext = scriptGlobal->GetContext(); aScriptContext->SetProcessingScriptTag(PR_TRUE); JSContext* existing_cx = (JSContext *)aScriptContext->GetNativeContext(); JSRuntime * rt = JS_GetRuntime(existing_cx); JSContext *cx = JS_NewContext(rt, 8192); JSObject * aGlobalObject = scriptGlobal->GetGlobalJSObject(); JSClass globalClass = { "aFunction", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; JSObject *aObject = JS_NewObject(cx, &globalClass, nsnull, nsnull); JS_InitStandardClasses(cx, aObject); JSFunction* aFunction_ptr = JS_CompileFunction(cx, aObject, "aFunction", 0, NULL, aScript_String, strlen(aScript_String), "error", lineno); JSObject * childObject = JS_GetFunctionObject(aFunction_ptr); JS_AddNamedRoot(existing_cx, aFunction_ptr, "aFunction"); JS_SetGlobalObject(existing_cx, window_obj);//old= aGlobalObject JS_SetOptions(cx, JS_GetOptions(existing_cx) | JSOPTION_VAROBJFIX); if(!JS_CallFunction(cx, aObject, aFunction_ptr, 0, NULL, &rval2)) { fprintf(mFile,"\n play_script_call() - call function failed !!\n"); fflush(mFile); MY APP GOES HERE !!!! } Thank you if you have any idea because it's a very big problem for me. -- Béatrice Philippe-Derbez Société Urbilog 80, rue d'Iéna - 59000 Lille 01-69-88-08-11 06-77-92-88-51 beatrice.derbez.bd@wanadoo.fr .