Implementing membranes using proxies, and [[GetInheritance]]

Tom Van Cutsem tomvc.be at gmail.com
Fri Sep 13 03:35:15 PDT 2013


2013/9/13 David Bruant <bruant.d at gmail.com>
>
> If one wants Object.getPrototypeOf to return the same object twice, the
> membrane has to associate a new prototype with a given object. If there is
> a shadow target, the place of where to store this object is pretty obvious
> ([[Prototype]]).
> That said, the good property that remains is that if a prototype setting
> capability has been kept around is that prototype chains can be built
> lazily.
>

Returning the same object twice is taken care of by the use of WeakMaps,
separately.

I'm thinking of an implementation as follows:

// in a wet->dry membrane proxy's handler:
getPrototypeOf: function(dryShadow) {
  if (!Object.isExtensible(wetTarget)) {
    // no need to use the shadow
    return wet2dry(Object.getPrototypeOf(wetTarget)); // wet2dry consults a
WeakMap to avoid creating multiple wrappers
  }
  var dryProto = wet2dry(Object.getPrototypeOf(wetTarget));
  Object.setPrototypeOf(dryShadow, dryProto);
  return dryProto;
}

Cheers,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130913/a2c91982/attachment.html>


More information about the es-discuss mailing list