MapIterator.next definition in spec

# Katelyn Gadd (10 years ago)

The latest spec draft (feb 2) still lists MapIterator.next as returning an Array instance containing two elements. The implementation of MapIterator in latest SpiderMonkey and V8 returns a JS object, like { value: x, done: false }.

Is the current spec draft correct? Do applications using Map have to detect which of the two formats is being used by the current iterator implementation?

Most of the stuff out there on the web (MDN, caniuse, etc) suggests that the implementations in V8 and SpiderMonkey are current to the draft spec and reasonably complete, so this is quite confusing.

Thanks,

# Claude Pache (10 years ago)

Le 4 févr. 2015 à 08:57, Katelyn Gadd <kg at luminance.org> a écrit :

The latest spec draft (feb 2) still lists MapIterator.next as returning an Array instance containing two elements. The implementation of MapIterator in latest SpiderMonkey and V8 returns a JS object, like { value: x, done: false }.

If I read correctly the algorithm in Section 23.1.5.2.1 %MapIteratorPrototype%.next(), MapIterator#next() returns either CreateIterResultObject(result, false), or CreateIterResultObject(undefined, true) (when enumeration is completed), where CreateIterResult(result, done) is {value: result, done: done}.

Is there something in another part of the spec contradicting that?

# Katelyn Gadd (10 years ago)

Here's what I see in the feb 2 pdf:

  1. Assert: itemKind is "key+value".
  2. Let result be the result of performing ArrayCreate(2).
  3. Assert: result is a new, well-formed Array object so the following operations will never fail.
  4. Call CreateDataProperty(result, "0", e.[[key]]) .
  5. Call CreateDataProperty(result, "1", e.[[value]]).
# Claude Pache (10 years ago)

Le 4 févr. 2015 à 10:02, Katelyn Gadd <kg at luminance.org> a écrit :

Here's what I see in the feb 2 pdf:

  1. Assert: itemKind is "key+value".
  2. Let result be the result of performing ArrayCreate(2).
  3. Assert: result is a new, well-formed Array object so the following operations will never fail.
  4. Call CreateDataProperty(result, "0", e.[[key]]) .
  5. Call CreateDataProperty(result, "1", e.[[value]]).

So do I; but the algorithm doesn't say "Return result". The next step is:

iv. Return CreateIterResultObject(result, false).

# Katelyn Gadd (10 years ago)

I see, that's why I got confused, since that's defined elsewhere in the spec. Makes sense then, sorry for the error.