Thanks, Boris, this explanation solves the puzzle for me.

On Mon, May 5, 2014 at 1:32 PM, Boris Zbarsky <bzbar...@mit.edu> wrote:

> On 5/5/14, 4:21 PM, John Barton wrote:
>
>> Let me rephrase my question: why is the Proxy get even called in this
>> case?
>>
>
> Because the way __proto__ works is as if the JS implementation had done:
>
> (function() {
>   protoGetter = Object.getPrototypeOf;
>   Object.defineProperty(Object.prototype, "__proto__",
>     {
>        set: function() { /* magic here */ },
>        get: function() { return protoGetter(this); }
>     });
> })();
>
> before any page script got to run.
>
> Which means that __proto__ is a simple accessor property on
> Object.prototype.  On the one hand, that means that by default it appears
> on all objects.  On the other hand it means it can be shadowed, for example
> by someone doing an explicit defineProperty for that property name on some
> object.
>
> But it can also be shadowed by proxies, because those get to intercept
> _all_ property access.  So when a obj.__proto__ get happens the
> implementation walks up the proto chain of "obj" looking for a proxy or an
> object with an own property named "__proto__".  If a proxy is found, its
> get() is invoked and that's all there is to do as far as the implementation
> is concerned.  If an own property named "__proto__" is found, then the
> implementation checks whether it's an accessor or value property, and
> either returns the value or calls the getter, depending on which sort it is.
>
> -Boris
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to