« Bugzilla Issues Index

#588 — Update Array.from to use iterable protocol

Array.from should… (this is a change to current specification)

1. Attempt to use the iterable protocol, if cannot… (new addition)
2. Fall back to using Array-like protocol (current)

Did we talk about the implications of of using iterable protocol if the array has holes?

The proposed standard iterator for Arrays turns holes into undefined. While normal array-like iteration skips holes. I would expect that

let a2 = Array.from([,,,,5]);

would produce a new array that was just like the argument array. But using iterator protocol would make it just like:

let a3 = Array.from[undefined, undefined, undefined, undefined, 5]);

It seems to me that the right solution, is that if the from argument is a real Array then Array-like, hole preservation, iteration should be used. If it isn't a real Array, then from should first try iterable protocol and if it isn't there fall back to array-like.