On __proto__ as a magical data property

David Bruant bruant.d at gmail.com
Thu Jul 19 00:47:13 PDT 2012

Le 19/07/2012 09:18, Tom Van Cutsem a écrit :
> 2012/7/18 Jason Orendorff <jason.orendorff at gmail.com 
> <mailto:jason.orendorff at gmail.com>>
>     On Wed, Jul 18, 2012 at 3:28 PM, Brendan Eich <brendan at mozilla.org
>     <mailto:brendan at mozilla.org>> wrote:
>     > Your suggestion of the setter checking that the receiving object
>     inherit the
>     > built-in __proto__ before actually doing the "set" is
>     interesting, but it
>     > seems to me that it means every set does a proxy-observable
>     "has" operation.
>     > That's not something we do today -- maybe it's ok to add it --
>     but it is
>     > also overhead and opportunity for mischief. Or did you have a
>     thought on how
>     > to silently probe for the property descriptor?
>     Yes, there's actually a nice answer for this. Consider:
>         // Applying __proto__ setter directly to a proxy
>         var proto_prop =
>           Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
>         proto_prop.set.call(proxy, {});
>         // Applying a DOM getter directly to a proxy
>         var nodeType_prop =
>           Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
>         nodeType_prop.get.call(proxy);
>     The nodeType getter is non-generic; it only works on Nodes. The
>     __proto__ setter should be "non-generic" too: namely, it should only
>     work on non-Proxy objects.
>     As the proxies spec stands, non-generic methods applied to proxies
>     will
>     just throw TypeError.  This is safe.
> That's not how I would expect proxies to interact with 
> Object.prototype.__proto__.{get,set}. Instead, if we spec mutable 
> __proto__, I would expect proxies to have a {get,set}PrototypeOf trap, 
> and the above code snippet would trigger the setPrototypeOf trap.
I agree with that vision and it is making me realize that we only need a 
setPrototypeOf trap if the setter is extractable. If __proto__ is a data 
property, the existing traps are enough.
This probably weighs in favor of __proto__ as a data property.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120719/8fc460d4/attachment.html>

More information about the es-discuss mailing list