The global object in browsers

Ian Hickson ian at hixie.ch
Tue Feb 17 15:02:07 PST 2009


On Tue, 17 Feb 2009, Mark Miller wrote:
> On Tue, Feb 17, 2009 at 2:02 PM, Ian Hickson <ian at hixie.ch> wrote:
> > 
> > Now, if the other page's script calls f() and g(), it will get 
> > different results (2 and 1 respectively, if I didn't screw up the 
> > example code).
> >
> > For HTML5, this behaviour has been defined in more detail. The global 
> > object is a Window object. This object is per-Document. The object 
> > returned by the "window" attribute on that global object is actually a 
> > WindowProxy object, which forwards everything to the "current" Window 
> > object.
> 
> What do you mean by "current"? Are you proposing to legitimize the 
> dynamic scoping behavior demonstrated by your example?

I'm not really trying to "legitimize" anything so much as accurately 
describe the status quo so that new browsers can be written without having 
to reverse engineer other browsers.


> If all major browsers agree on this bizarre behavior, we will indeed be 
> stuck. But if some existing browsers use lexical capture (i.e., return 1 
> in both cases), then ES-Harmony should feel free to specify that. What 
> do each of the major browsers do?

My understanding (assuming I got the code right) is that Webkit and Gecko 
return different values, and Trident returns 2 for the g() and throws an 
exception for f().

Here are some demos. 001 is a control test. If it says "false", you have a 
violation of ES, and are likely incompatible with legacy content. If it 
says "true", then test 002. If 002 says "false", then ES is being violated 
in some way. If 002 doesn't say anything, then code is being blocked when 
the global object doesn't match the current document; Mozilla, Apple, and 
Opera have all told me not to do that for performance reasons. If it says 
false, then test 005 -- if that says true before and false after, then the 
browser is probably incompatible with legacy content.

   http://damowmow.com/playground/demos/global-object/001.html
   http://damowmow.com/playground/demos/global-object/002.html
   http://damowmow.com/playground/demos/global-object/005.html

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the Es-discuss mailing list