On __proto__ as a magical data property

Jeff Walden jwalden+es at MIT.EDU
Tue Jul 17 09:50:27 PDT 2012

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"


  ({}).__proto__ = {}; // mutating mutation

or for that matter

  Object.prototype.__proto__ = null; // non-mutating "mutation"


  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.


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.

More information about the es-discuss mailing list