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

Re: "var" declarations shadowing properties from Window.prototype

From: Axel Rauschmayer <axel@rauschma.de>
Date: Wed, 15 Aug 2012 09:48:25 +0200
Cc: Brandon Benvie <brandon@brandonbenvie.com>, public-script-coord@w3.org, Brendan Eich <brendan@mozilla.com>, es-discuss@mozilla.org
Message-Id: <6D5A3353-B856-4D4E-8340-D5617C3244C4@rauschma.de>
To: Boris Zbarsky <bzbarsky@mit.edu>
> That's basically what the Global Scope Polluter does.  That's certainly how I plan to implement it in Gecko in the WebIDL bindings: Window.prototype.__proto__ will be a proxy which will do all the weird stuff the GSP has to do.


In FF 14, Iím getting the following results (if there is an element whose ID is "foo"):

    $ "foo" in window
    false
    $ foo
    ReferenceError: foo is not defined
    $ window.foo  // (*)
    [object HTMLDivElement]
    Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
    $ foo  // (**)
    undefined
    Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. @ Web Console:1
    $ "foo" in window
    true

That looks like what you described: The Global Scope Polluter auto-creates foo after the read access (*). However, (**) puzzles me: A getter for foo seems to be called (as a warning is displayed), but it returns `undefined`. How come?

Also interesting: window instanceof EventTarget holds, but EventTarget.prototype is not in protos(window), an array created by:
    function protos(obj) {
        var chain = [];
        while (obj) {
            chain.push(obj);
            obj = Object.getPrototypeOf(obj);
        }
        return chain;
    }

Axel

-- 
Dr. Axel Rauschmayer
axel@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
Received on Wednesday, 15 August 2012 07:48:56 UTC

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