Le 26/05/2012 13:53, Tom Van Cutsem a écrit :
Hi,

If __proto__ is getting standardized, I propose we adapt proxies to be able to trap getPrototypeOf.

Why?
- with __proto__, stable prototypes are no longer an invariant. It's awkward to make proxies go out of their way to maintain it still.
This is very true.

- it's much more consistent with all the other Object.* methods:
Object.keys(proxy) => calls keys trap
Object.getPrototypeOf(proxy) => calls getPrototypeOf trap

- it makes membranes much simpler, because they can now do:
getPrototypeOf: function(target) {
  return wrap(Object.getPrototypeOf(target));
}
This saves the extra object allocation to create a dummy target with a wrapped prototype.

To be consistent with the other traps, if we buy into a getPrototypeOf trap, we should add a getPrototypeOf method in the "reflect" module as well (basically an alias for Object.getPrototypeOf).

Your thoughts?
I agree a lot with your rationale. I have no comment on the "how", but what you said makes sense.

Additionally, I'd like to add that if __proto__ gets in the spec, it should be clearly stated that proxy.__proto__ calls the get and set traps and does not get/set the prototype of the proxy without being trapped.

David
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to