[[Extensible]]and Proxies (Was: Proxy.isProxy )
david.bruant at labri.fr
Thu Jul 14 06:01:13 PDT 2011
Le 13/07/2011 20:52, Mark S. Miller a écrit :
> On Wed, Jul 13, 2011 at 8:38 AM, Allen Wirfs-Brock
> <allen at wirfs-brock.com <mailto:allen at wirfs-brock.com>> wrote:
> Hate to start another cycle of this, but if (trapping) proxies
> can't be set to [[Extensible]]: false, then they can't be used to
> fully emulate built-ins such as Array. Why is there this restriction?
> On Wed, Jul 13, 2011 at 10:30 AM, Allen
> Wirfs-Brock <allen at wirfs-brock.com <mailto:allen at wirfs-brock.com>> wrote:
> Yes, but the restriction prohibits otherwise legal behavior that
> doesn't violate the invariant. Isn't that as "bad" as not
> enforcing the invariant?
> What behavior of non-extensible arrays cannot be emulated by a normal
> non-proxy object?
I'm not sure I understand your question since "normal non-proxy object"
cannot really emuate anything. Did you mean to ask what behavior of
non-extensible arrays cannot be emulated by proxies?
If that's the question:
var a = Array(1,2,3,4); // a.length===4
console.log(a); // 4, of course
a.length = 3; // should delete a under the hood.
Logs "undefined" with a conformant ECMAScript Array.
This cannot be emulated with current proxies. Current choices are:
* Throw a TypeError on Object.preventExtensions
* Accept to be transformed into a normal object fully respecting ES5.1
8.12 algorithms and log "4"
* Turn the "length" property into a getter/setter pair which violates
ES5.1 188.8.131.52 which ask the length property to be a non-configurable
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss