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

RE: variable declarations shadowing named properties on window

From: Travis Leithead <travis.leithead@microsoft.com>
Date: Wed, 4 Jan 2012 19:28:24 +0000
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: Ojan Vafai <ojan@chromium.org>, Cameron McCormack <cam@mcc.id.au>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Allen Wirfs-Brock <allen@wirfs-brock.com>, Ian Hickson <ian@hixie.ch>
Message-ID: <9768D477C67135458BF978A45BCF9B38381E5FB5@TK5EX14MBXW604.wingroup.windeploy.ntdev.microsoft.com>
>-----Original Message-----
>From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
>On 1/4/12 1:21 PM, Travis Leithead wrote:
>>> -----Original Message-----
>>> From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
>>> On 1/4/12 3:24 AM, Ojan Vafai wrote:
>>>> IE and Opera already do this and have done so for a long time, right?
>>> They've allowed var to shadow the frame names, right?
>>> Have they actually put the frame names somewhere on the proto chain
>>> other than the global itself?  Doing that changes behaviors other than
>>> that of var....
>> The described behavior has been in IE for a while. In Trident, frame
>references are just another global scope polluter, but with higher
>priority. The var declarations are assigned the undefined value (I
>believe), and so they shadow everything else in the lookup order.
>var declarations don't do any value assignment, per spec.  They just
>define a property if one isn't there already.  Try this testcase:
>   <script>
>     x = 5;
>   </script>
>   <script>
>     var x;
>     alert(x);
>   </script>
>Does that alert 5 in IE?  If so, how is this case different from the GSP
>case in IE?  In both cases, when the var declaration happens, you need
>to check whether the object already has an own property with that name....

The above does alert 5 in IE.

I'm going to reason about an implementation detail without verifying it here... my guess is that the var declaration code (without assignment) is failing to perform a full lookup of the window object before assigning the var. I ran the following code to confirm my thinking:

<!DOCTYPE html>
  Object.getPrototypeOf(this).x = 5;
  var x;

And here's the results:

IE9:     undefined
Chrome:  5
Safari:  5
Firefox: undefined
Opera:   undefined

So, in IE, Firefox, and Opera, the prototype chain (and by inference the GSP) is not even getting consulted given the proposed lookup order and this scenario.

>Or does IE put all its GSPs, including frame names, on the proto chain
>and not on the object itself?
Received on Wednesday, 4 January 2012 19:30:20 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:05 UTC