Re: scopes, execution contexts, and scripts

John J Barton <[email protected]> Mon, 25 Jan 2010 18:10:27 -0800
Newsgroups gmane.comp.mozilla.devel.jsdebugger
Message-ID <[email protected]>
Boris Zbarsky wrote:
> On 1/25/10 6:18 PM, John J Barton wrote:
>> If true, we chase the global.parent until it is null or equal to itself,
>> then test
>> if (context.window == rootWindow)
>> where context.window is set to a previous reference from the same(?) API
>> call.
> 
> OK, so this is correctly testing outer window identity.  In particular, 
> this is the object that (currently) does NOT change identity when you 
> perform navigation (e.g. clicking a link).
> 
> Is that really what you want?

Yes, (I guess) because we don't have any event to tell us about identity 
change, so we track link clicking with onLocationChange in Firebug. In 
Chromebug I just do something for each case. For example, onOpenWindow 
from nsIWindowMediatorListener tells us that a new XUL window arrives, 
so we track it's nsIDOMWindow.

> 
>> I can see this is wrong: we should use the child window directly in
>> chromebug, not the top window as in Firebug. So I need to test whether
>> the window is a content or chrome window. The only way I know how to do
>> this is with some bizarre nsIDocShellTreeItem.itemType test. Is there a
>> better way?
> 
>   if (win instanceof ChromeWindow) {
>     /* It's a chrome window */
>   }

Thanks, but I want the reverse test, I want to know it is a content 
window (since I guess there may be Window objects that are not 
ChromeWindow objects and not content windows.

> 
>> If the global is not a Window, then we test (context.global == global),
>> where context.global was set to a global from a previous call.
> 
> So I'm curious... at what point is the reference from context to the 
> global removed?

Good question! The one I am trying to answer now! For content windows, 
pagehide or unload handlers; for ChromeWindows, unload handlers; for 
non-windows, my only story so far is exit the app. For non-windows I 
think can mark off the deleted scripts as they die, then when they all 
go, remove the ref. That assumes that non-windows are only useful for JS.

jjb