W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

Re: variable declarations shadowing named properties on window

From: Ojan Vafai <ojan@chromium.org>
Date: Wed, 4 Jan 2012 00:10:09 -0800
Message-ID: <CANMdWTtarh0ebYmrQcoYiyShpADp4PyRAf_9yx+UvCBPrEySdw@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: Cameron McCormack <cam@mcc.id.au>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Travis Leithead <Travis.Leithead@microsoft.com>, Allen Wirfs-Brock <allen@wirfs-brock.com>, Ian Hickson <ian@hixie.ch>
On Tue, Jan 3, 2012 at 10:49 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 1/3/12 9:18 PM, Ojan Vafai wrote:
>
>> Firefox behaves differently for frames and elements I believe (or maybe
>> names versus IDs?).
>>
>
> Frame names vs global scope polluter.
>
> In Gecko, the global scope polluter is currently implemented as an object
> on the prototype chain of the window, so var declarations will always
> shadow it.  But frames are own properties of the window, and the behavior
> is what it is for exactly the reason Cameron described, as far as I can
> tell.


Yeah, sorry, I'm not too familiar with the implementation or spec side of
this.

 My strong preference is that declaring a variable should cause it to
>> shadow (i.e. alert undefined above).
>>
>
> Can we move frames away from being own properties of the window (i.e. move
> them onto some prototype)?  That seems like the "simplest" (in terms of how
> it works, not in terms of expressing it in WebIDL) way of making var shadow
> their names.


Seems fine to me. I don't see any downsides. Maybe I just don't understand
the implications. :)

Not shadowing has been a frequent
>> source of bugs for the Closure Compiler in WebKit. Shadowing makes it
>> much easier to reason about how library code will behave when embedded
>> in a page.
>>
>
> This argues for not having any sort of weird own property behavior on
> Window at all and putting all that on some prototype of the window.
>
> That will incidentally simplify implementation in Gecko, I believe
> (because it doesn't require having a proxy or otherwise "weird" object as a
> global object).


With my web developer hat on, this is what makes sense to me. Web
developers I've spoken to either don't care or strongly want to be able to
shadow all with declarations. Noone voiced a preference for not shadowing
declarations.

I don't know how any of this is implemented in WebKit, but the implementors
I've spoken to on the V8 and WebKit side haven't expressed strong opinions
and just want interoperability.

Ojan
Received on Wednesday, 4 January 2012 08:16:08 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC