Subj : Re: SM: JS_ExecuteScript and rval To : Franky Braem From : Brendan Eich Date : Tue Apr 08 2003 03:42 pm > > >I've got something working now like this. My only concern is: do I have to >root the JSScript that I compile and execute in the wxScript constructor? > Probably. Why do you execute it in the ctor? Wouldn't it be better to compile it and let others execute it later, possibly repeatedly? That's how the built-in Script object works. To get the function declarations bound, you could JS_ExecuteScriptPart(cx, obj, scdript, JSEXEC_PROLOG, &junk). If you keep the JSScript around after the constructor returns, you definitely have to root a script object that protects it (see JS_NewScriptObject in jsapi.h). If you run the GC (conditionally) from the branch callback, or from a last-ditch limit in the runtime (i.e., if you pass 4000000 or some such small-ish number to JS_NewRuntime, instead of 0xffffffff), then a GC could nest in the execution of the script (even of the prolog -- however unlikely, it could happen, due to memory pressure). If any such nesting GC could occur, you need a rooted object protecting the JSScript. If your embedding is multithreaded, you need a root. This should be well-known, the topic comes up over and over in this group. /be .