The iterator protocol has a bunch of helper AOs. But almost everything just uses IteratorStepValue (introduced in https://github.com/tc39/ecma262/pull/3268) and IteratorClose; the exceptions are
IteratorStep still gets used when you need to iterate but don't care about the value - specifically, it gets used for [foo, , bar] = bazdestructurings with elisions, and in some of the iterator helper proposals (e.g. .drop), which will need updating.
This PR changes IteratorStep and IteratorNext so that they set the [[Done]] slot on the Iterator Record to true when some part of the protocol throws or the iterator result object's .done is found to be true, consistent with how IteratorStepValue behaves. (I'd previously considered eliminating IteratorStep entirely, but "I need to advance this iterator but I don't care about the value" is a coherent thing and does come up sometimes.)
Of the above uses, only the "destructurings with elisions" case actually care whether the [[Done]] slot gets set to true, which it was previously doing explicitly. Still, it seems nicer to handle these uniformly, such that manipulation of that slot is done only in the iterator AOs themselves.
The iterator protocol has a bunch of helper AOs. But almost everything just uses
IteratorStepValue
(introduced in https://github.com/tc39/ecma262/pull/3268) andIteratorClose
; the exceptions areIteratorStep
still gets used when you need to iterate but don't care about the value - specifically, it gets used for[foo, , bar] = baz
destructurings with elisions, and in some of the iterator helper proposals (e.g..drop
), which will need updating.IteratorNext
gets used in%AsyncFromSyncIteratorPrototype%.next
(the thing which handlesfor await
over a sync iterator)IteratorComplete
andIteratorValue
get used infor of
andyield *
so that they can share logic between sync vs async iteration, plus in%AsyncFromSyncIteratorPrototype
.This PR changes
IteratorStep
andIteratorNext
so that they set the[[Done]]
slot on the Iterator Record totrue
when some part of the protocol throws or the iterator result object's.done
is found to betrue
, consistent with howIteratorStepValue
behaves. (I'd previously considered eliminatingIteratorStep
entirely, but "I need to advance this iterator but I don't care about the value" is a coherent thing and does come up sometimes.)Of the above uses, only the "destructurings with elisions" case actually care whether the
[[Done]]
slot gets set totrue
, which it was previously doing explicitly. Still, it seems nicer to handle these uniformly, such that manipulation of that slot is done only in the iterator AOs themselves.This also incidentally eliminates 2 of the remaining 4 explicit uses of the ReturnIfAbrupt macro (cf https://github.com/tc39/ecma262/pull/1573#issuecomment-1913042895), the last two being in
[[Call]]
and[[Construct]]
for ECMAScript function objects.