Subj : Re: spidermonkey cross script execute doesn't work To : netscape.public.mozilla.jseng From : Mike Moening Date : Thu Mar 17 2005 09:47 am Exactly what is a "Root" and do I have to name them unique or can I create a single "root name" for all my objects that require rooting. Thanks "Brendan Eich" wrote in message news:42391FA6.1030201@meer.net... > Mike Moening wrote: > > Thanks for your reply! > > > > To recap my understanding: > > > > Basically the JS_CompileScript generates the bytecode but nothing else. > > (Allows for multiple execute calls) > > > That's right -- no side effects, just the result returned. > > > > The JSEvaluateScript actually "runs" the script. > > > Including processing declarations per ECMA-262 section 10 (entering > execution contexts). > > > > So in the case of the 1st script I have to be a little carefull not to add > > any javascript code that would actually execute other than declaring > > functions which would be called by the second script. > > > Not sure why not -- you can interleave declarations and code among N > scripts, if you don't make forward references from script i to script j, > j > i. > > > > One followup question. Is it necessary to "Root" the compiled scripts to > > protect them from GC? > > > Yes. > > > > I'm not really clear on how this actually works. > > > Call JS_NewScriptObject and store its return value in a rooted pointer. > > > > I store my compiled JS_Script pointers an a for later reference. Are > > they safe? > > > No. You need objects wrapping each, created by JS_NewScriptObject, and > you need to root or otherwise protect those object references (you could > implement a JSClass.mark hook that marks them, if the map is associated > with an object [global object?] of a class you designed). > > /be .