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

Re: variable declarations shadowing named properties on window

From: Cameron McCormack <cam@mcc.id.au>
Date: Fri, 06 Jan 2012 09:45:13 +1100
Message-ID: <4F0627F9.4090701@mcc.id.au>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: Travis Leithead <travis.leithead@microsoft.com>, Ojan Vafai <ojan@chromium.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Allen Wirfs-Brock <allen@wirfs-brock.com>, Ian Hickson <ian@hixie.ch>
Travis Leithead:
>> I thought Cameron proposed another alternative, which I much prefer
>> over adding another object to the prototype chain:
...
>>> We could either make [[HasProperty]] return false for named properties
>>> on window despite [[GetOwnProperty]] returning a property descriptor.
>>> Or, we could make the window object have a custom [[GetProperty]]
>>> instead of [[GetOwnProperty]], so that [[HasProperty]] returns false and
>>> [[GetOwnProperty]] returns undefined, while fetching the property off
>>> the object still gives you the named property value.

Boris Zbarsky:
> It's not entirely clear to me whether this works for the window in
> particular, because as far as I can tell the bareword lookup algorithm
> in ES relies on [[HasProperty]] before ever calling [[Get]]. I could
> well be wrong on that, though; I don't follow that section of the spec
> very well.

Right, I don't think either of my proposals Travis quoted will work now, 
due to this bareword lookup problem.  Here is my reading of the ES5 spec 
for barewords:

   Bare identifiers are evaluated here:
   http://people.mozilla.org/~jorendorff/es5.html#sec-11.1.2

   which does Identifier Resolution:
   http://people.mozilla.org/~jorendorff/es5.html#sec-10.3.1

   which calls GetIdentifierReference:
   http://people.mozilla.org/~jorendorff/es5.html#sec-10.2.2.1

   where the lexical environment passed to it is the unique "global
   environment":
   http://people.mozilla.org/~jorendorff/es5.html#sec-10.2.3

   whose Environment Record is an object environment record.

   GetIdentifierReference calls HasBinding on its Environment
   Record, which because it is an object environment record is
   this operation:
   http://people.mozilla.org/~jorendorff/es5.html#sec-10.2.1.2.1

   which calls [[HasProperty]], which will return false for named
   properties if we define it so.

I think the upshot of this is that with named properties exposed on this 
window object itself, there is no way to have

   1. var statements with no assignment shadow the named property
      with "undefined", and

   2. allow bareword identifiers to reference named properties

because if [[HasProperty]] returns true, (1) will fail but (2) will 
work, and if it returns false, (1) will work but (2) will fail.
Received on Thursday, 5 January 2012 22:45:57 UTC

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