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

Tom Van Cutsem at
Fri Nov 14 12:52:42 PST 2014

2014-11-13 22:35 GMT+01:00 Tom Van Cutsem < at>:

> My intuition is that Array.isArray is often used to branch based on
> whether code received just one versus a collection of values. E.g. a
> function may take a single parameter that can be bound to either a single
> value or a collection of values, and treat a collection of values
> differently. In fact, that is essentially what Array.prototype.concat does:
> if the argument is an array, splice its values, otherwise, don't splice.
> This has nothing to do with `length` magic. The same goes for
> JSON.stringify (serialize as "[]" vs "{}").

Amusingly, not only does JSON.stringify(value, replacer, space) branch on
the type of its `value` argument (to serialize as "[]" vs "{}"), it
apparently also type-tests its `replacer` argument, which can either be a
function or an array. If it's an array, it serves as a whitelist of the
properties that can appear in the output. While it's unlikely anyone would
ever want to pass a proxy-for-array as a JSON whitelist, JSON.stringify is
an example of the kind of type-testing I had in mind to simply distinguish
whether one of its parameters is just one value vs. a collection of values.
For such functions, there would be no harm in treating proxies-for-arrays
as arrays.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list