Subj : Re: SM: JS_ExecuteScript and rval To : netscape.public.mozilla.jseng From : "Franky Braem" Date : Wed Apr 09 2003 10:56 pm "Brendan Eich" wrote in message news:3E93425C.8030805@meer.net... > > 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). I execute the script only when the constructor is called as a method. It can be executed repeatedly by using the execute method of wxScript. JS_ExecuteScriptPart is (was) an unknown API for me. > > 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). I need to keep it, because the execute method needs the script object. But instead of rooting, I add a property to wxScript which contains the Script object. Does this solve the root problem? > > 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. At the moment wxJS is not multithreaded. Maybe at sometime ... > > This should be well-known, the topic comes up over and over in this group. > > /be > thanks for your help, Franky. .