Re: scopes, execution contexts, and scripts
Boris Zbarsky <[email protected]> Fri, 22 Jan 2010 01:16:57 -0500
| Newsgroups | gmane.comp.mozilla.devel.jsdebugger |
|---|---|
| Message-ID | <[email protected]> |
On 1/22/10 12:46 AM, John J. Barton wrote: > Does anyone understand what jsdIStackframe.executionContext is? It seems to be an abstraction for the JSContext the script is running on. > How is it related to jsdIStackframe.scope? It's not, in general. > /* Top of the scope chain for this context. */ > readonly attribute jsdIValue globalObject; Right. > and at > http://mxr.mozilla.org/mozilla/source/js/jsd/idl/jsdIDebuggerService.idl#841 > > we read about jsdIStackframe: > > /* Top object in the scope chain. */ > readonly attribute jsdIValue scope; This is probably a bit of a misuse of the word "top". > Despite the word 'top' here, in practice, you get the scope chain by > chasing scope.jsParent. So I'm guessing that the correct comment for the > frame.scope would be "youngest object in the scope chain". It's not necessarily "youngest" so much. Just the one that's first to have names looked up in it. > If I apply the same correction to the globalObject for jsdIContext we'd > have "youngest scope for this context", but that does not make any more > sense to me. Sure. That's because there's no age anything going on there. > I guess that frame.executionContext is basically the container for the > frames, which is why is not useful for anything. But I'd like to know > more about it. The executionContext is what I said above: a reflection of the JSContext the script is running on (well, and maybe of the nsIScriptContext). What this means in practice depends on the particular JS embedding; in the case of Firefox each (outer) DOM window has its own JSContext. There are also various other JSContexts floating about (e.g. an XPConnect sandbox gets its own JSContext, temporary JSContexts are used in the component loader, DOM workers have separate JSContexts, that sort of thing). The JSContext gives the JSAPI consumer the ability to control certain things about how script will be compiled and run (e.g. which JS version will be used, whether jit will be used, whether strict mode should be used etc). As far as debugger usage... if a cross-window call happens, then the script from one window will end up running on the other windows JSContext: the executionContext doesn't change when such a call occurs. So it doesn't tell you much about the script you're looking at (other than some data about how it's being run, but NOT data about how it was compiled). The globalObject of a JSContext is just some arbitrary object of the embedding's choosing; in Firefox's case it's the JSObject for the outer window. Does that help? -Boris