archives

« Bugzilla Issues Index

#3000 — 23.1.1.1: order of side effects for Map constructor makes it unimplementable with for-of


Discussed toward the end of https://www.w3.org/Bugs/Public/show_bug.cgi?id=26217

One would like to be able to implement the `new Map(iterable)` algorithm via something like this:

var call = uncurryThis(Function.prototype.call);

var adder = map[adder];
if (typeof adder !== "function") {
throw new TypeError;
}

for (var x of iterable) {
var k = iterable[0];
var v = iterable[1];
call(adder, map, k, v);
}

However, the specification requires that the iterator be gotten from the iterable before the `adder` is retrieved from `map`, which does not match this code.

This ordering means implementations cannot self-host using for-of, and must thus engage in some contortions to do the separate iterable-related steps.

It seems like it'd be simple enough to move step 7c,d,e before steps 7a,b and solve this.

I imagine the other collection initializers might suffer from the same issue.


fixed in rev26 editor's draft

Also for Set, WeakMap, WeakSet

Let me know if you see any other similar self-hosting issues like this. Jason already turned up a couple others that have been fixed.


in rev26