On __proto__ as a magical data property

Oliver Hunt oliver at apple.com
Tue Jul 17 10:45:20 PDT 2012


JSC has not had any problems with __proto__ being implemented as a getter/setter pair on the Object.prototype.

--Oliver

On Jul 17, 2012, at 9:50 AM, Jeff Walden wrote:

> If __proto__ were a magical data property, what would happen if you did:
> 
>  Object.defineProperty(Object.prototype, "__proto__", { writable: false });
> 
> and then later:
> 
>  ({}).__proto__ = Object.prototype; // non-mutating "mutation"
> 
> or
> 
>  ({}).__proto__ = {}; // mutating mutation
> 
> or for that matter
> 
>  Object.prototype.__proto__ = null; // non-mutating "mutation"
> 
> or
> 
>  Object.prototype.__proto__ = Object.create(null); // mutating mutation
> 
> I spent a little time experimenting implementing __proto__ as an accessor property to see how the issues previously raised -- proxies, cross-global objects, and so on -- actually played out.  It required surprisingly few special-case behaviors.  SpiderMonkey's existing wrapper/proxy mechanism addresses those issues (through the "nativeCall" trap, if you're curious) without special effort.
> 
> More data's always helpful, and because Firefox is at the start of a development cycle, now is the ideal time to get it.  There's no substitute for data.  David Mandelin and I discussed this, and we agreed to push it to the Firefox tree to get that data.  We can always back it out if necessary.
> 
> Jeff
> 
> 0. https://bugzilla.mozilla.org/show_bug.cgi?id=770344 Note that I didn't implement the restrictions of the wiki proposal, just a straight reimplementation.  This is *only* to test the as-accessor proposition.  If the wiki's restrictions are deemed desirable, they can be implemented atop this patch.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list