archives

« Bugzilla Issues Index

#2083 — Make Array.from step 8 behave exactly like a for..of loop


It should be possible for a polyfill to get Array.from right using a for..of loop to implement step 8.

Currently there's just one very minor issue with that. Step 8 says:

> 8. If usingIterator is true, then
> a. Let iterator be the result of performing GetIterator(items).
> b. ReturnIfAbrupt(iterator).
> c. If IsConstructor(C) is true, then
> i. Let A be the result of calling the [[Construct]] internal
> method of C with an empty argument list.
> d. Else,
> i. Let A be the result of the abstract operation ArrayCreate
> with argument 0.
> e. ReturnIfAbrupt(A).
> f. Let k be 0.
> g. Repeat
> (...)

This can't be written using for..of because:

var A = isConstructor(C) ? new C() : [];
var k = 0;
for (var nextValue of items) {
...
}

It is observable that `items[Symbol.iterator]()` is called after `new C()`.

Can we swap the order so that A is created first?


Full disclosure: I actually want to self-host this in SpiderMonkey and I'd like to use a for..of loop myself. :)


no problem, and a good reason to make the change. Let me know if you spot any more like that.

foxed in rev21 editor's draft


fixed in rev21 draft