Subj : Re: spidermonkey: where global vars live To : Brian Barnes From : Brendan Eich Date : Mon May 12 2003 12:07 pm Brian Barnes wrote: > I thought I knew it all, but little pieces of information keep > escaping me no matter how hard Brendan tries to pound them in :) > > Take this script: > > var x=5; > > Where does the global reside? In the global object I initiated the > standard classes on and use in CallFunction? Those are (or can be) two different objects (1) and (2), as I think you say below. If you're calling a function defined by the script, you must be evaluating the script first, with JS_ExecuteScript, right? The obj param you pass to that (2) is used to find the place where global variables are bound. Do read the JSOPTION_VAROBJFIX comments in jsapi.h for a wrinkle. > Or in the "global object" I can get from the context with > js_getglobalobject? That's the object you passed to JS_InitStandardClasses, if not to JS_SetGlobalObject. So that's (1), above. > What I'm trying to do is use the same compiled script on a > standard-class initialized global object You don't need a standard-class-initialized global object when precompiling. FYI, tangential point only: with recent versions of SpiderMonkey, when precompiling a function using any of the JS_Compile*Function* APIs, you don't need any global object at all -- you can pass NULL as the obj parameter. I hope to relax the JS_Compile*Script* API rules so you can pass null for the obj param with those functions, too, but that will require some jsparse.c changes. > over and over with a different set of global data (instead of using 20 > different global objects each with the same script). > > What I got now works, it just seems a bit unecessary. Not clear what you have now -- are you recompiling the script for each of those 20 global objects? You don't need to do that. /be > > > [>] Brian > > .