Subj : Re: SpiderMonkey's Funky GC and me To : netscape.public.mozilla.jseng From : Alex Date : Wed Mar 23 2005 07:20 pm "Brendan Eich" a écrit dans le message de news:d1sat0$go1@ripley.netscape.com... > Alex wrote: > > well > > > > I have this script: > > > > var strdef = "psittacisme ?"; > > var intdef = 42; > > var dbldef = 8.6; > > var truedef = true; > > var falsedef = false; > > > > if i run my script, invoke the gc system and try to get dbldef's value, i > > get an int (under linux), or a string (under solaris). > > > What do you mean by try to get dbldef's value? > > What code do you use to run the script, and what keeps the object in > which these variables are defined alive across the GC? > > /be Well, here is a summary of the code: *********************************************** JSClass g_globClass = { "GlobalObj", //Class Name 0, //flags /* Mandatory non-null members. */ JS_PropertyStub, //add JS_PropertyStub, //del JS_PropertyStub, //get JS_PropertyStub, //set JS_EnumerateStub, //enumerate JS_ResolveStub, //resolve JS_ConvertStub, //convert JS_FinalizeStub, //finalize /* Optionally non-null members.*/ NULL, //getObjectOps NULL, //checkAccess NULL, //call NULL, //construct NULL, //xdrObject NULL, //hasInstance NULL //spare (reserved for future use.) }; m_Runtime = JS_NewRuntime(0x400000L); if (m_Runtime) return EXT_JS_INIT_ERROR; m_Context = JS_NewContext(m_Runtime, 8192); if (!m_Context) return EXT_JS_INIT_ERROR; m_GlobalObj = JS_NewObject(m_Context, &g_globClass, 0, 0); if (m_GlobalObj) return EXT_JS_INIT_ERROR; if (!JS_InitStandardClasses(m_Context, m_GlobalObj)) return EXT_JS_INIT_ERROR; JS_SetErrorReporter(m_Context, ErrReporRef); // ErrReporRef is an error reporting fun... //m_ScriptArray is an array of compiled script (we are meant to use more than only one) for (int i = 0; i < SCRIPTNBR; i++) m_ScriptArray[i] = NULL; JSFunction * PrintPtr = JS_DefineFunction(m_Context, m_GlobalObj, "print", print, 1, 0); if (!PrintPtr) cerr << "Oop" << endl; char * lscriptBuff = getScript(a_path); JSScript *lscript = JS_CompileScript(m_Context, m_GlobalObj, lscriptBuff, strlen(lscriptBuff), a_path, 0); m_ScriptArray[42] = lscript; jsval vp; JSBool lJSResult = JS_ExecuteScript(m_Context, m_GlobalObj, m_ScriptArray[a_scriptIdx], &vp); JS_GC(m_Context); jsval rval; lJSResult = JS_GetProperty(m_Context, m_GlobalObj, "dbldef", rval); if (lJSResult != JS_TRUE) return EXT_JS_INTERNAL_ERROR; *********************************************** after this, i though i could have access to the variable used by the script mentionned earlyer, but... Another funky trick is this: if i have a javascript file containing: ********************* print("Wizz !!\n"); ********************* and if i use the garbage collector before executing the script (JS_ExecuteScript), my print function receive a null pointer as the string to print. Thanks for interesting in my trouble (And sorry for the pure frenchy grammar...) .