Array.isArray(new Proxy([], {})) should be false (Bug 1096753)

Brendan Eich brendan at mozilla.org
Fri Nov 14 13:54:40 PST 2014


Tom Van Cutsem wrote:
> 2014-11-14 21:52 GMT+01:00 Jeremy Martin <jmar777 at gmail.com 
> <mailto:jmar777 at gmail.com>>:
>
>     Allen's previous comments:
>
>         Proxies are not transparent forwarders!  In particular their
>         default handling of the `this` value on method invokes will
>         break any built-in method that needs to access "internal
>         slots" of an object.
>
>
>     ...lead me to believe that this isn't the case for proxified
>     Arrays, so I'd have to reverse my earlier position, as
>     `Array.isArray(proxifiedArray)` evaluating to true just seems
>     likely to break code.
>
>
> For the particular case of Arrays though, because Array methods were 
> carefully specified to be generic (i.e. to also work on non-array 
> objects), they will work just fine on proxies-for-arrays:
>
> var p = new Proxy([1,2,3] , {} );
> var a = p.map(function(x) { return x + 1; });
> console.log(a); // [2,3,4]
>
> So, of all the exotic objects in the ES and WebIDL specs, Arrays are 
> probably one of the few exceptions where a Proxy wrapper *is* 
> transparent by default.

Right.

There is no all-or-nothing solution. Allen's words applie to exceptions 
to the rule. Arrays and well-written proxies for them fit in the rule. 
Jeremy, what do you say?

/be


More information about the es-discuss mailing list