Re: [WebIDL] Remove ArrayClass?

Boris,

The problem was a combination of instanceof Array and use of
Array.prototype.concat with the node list as one of the arguments.
Something like this:

var x;
if (obj instanceof Array) {
  x = array.concat(obj);
} else {
  ...
}

In ES5, concat only spreads the argument if the argument is an array
instance (not instanceof). In ES6 we are fixing A.p.concat to allow non
array instances to be spreadable:
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isconcatspreadable

In some way I'm glad that we failed to ship [ArrayClass] 2 years ago
because in ES5 the array functions are not meant to generate non array
object results. This has also been fixed in ES6, meaning that if we try
this again, `nodeList.map(...)` would now be able to produce a new
NodeList. This is important for things like `query(...).map(...)`, which
should return a new Elements collection and not an Array.


On Sat, Jul 19, 2014 at 12:01 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 7/19/14, 9:23 AM, Dirk Schulze wrote:
>
>> I do not have more information than the bits that you filtered already.
>>
>
> OK.
>
> Erik, do you?  This is about the specific issue
> https://bugs.webkit.org/show_bug.cgi?id=81573#c45 is talking about.
>
> One other thing: WebKit seems to seems to use NodeList in various places
> where the spec says to have an HTMLCollection (e.g. getElementsByTagName).
>  So it's possible it ran into compat issues that other UAs won't ran into,
> depending on which exact lists got passed into where...
>
>
>  For current WebKit, you just need the part that does not patch V8 from
>> https://bugs.webkit.org/attachment.cgi?id=170983&action=prettypatch.
>>
>
> Hey, that code looks familiar.  ;)
>
>
>  I suppose it is easier to add [ArrayClass] to NodeList.webidl in Gecko.
>>
>
> Sure.  The hard part here is the compat testing, not the one line of IDL.
>
>
>  Maybe this is enough and just needs to be evangelist?
>>
>
> Enough for what?  I mean, it's possible to write:
>
>   Array.from(document.querySelectorAll("whatever")).map(someFunc)
>
> today in Firefox, but no other browser seems to support it so far.
>
> It's possible to do:
>
>   Array.prototype.slice.
>         call(document.querySelectorAll("whatever")).map(someFunc)
>
> in all browsers, but the first reaction people have when they see that is
> "WAT?".  Can't say I blame them.  With ArrayClass that becomes:
>
>   document.querySelectorAll("whatever").map(someFunc)
>
> which is what people want out of this stuff anyway.
>
> -Boris
>



-- 
erik

Received on Monday, 21 July 2014 14:29:00 UTC