ecma262
ecma262 copied to clipboard
More tweaks for the iterator handling AOs
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
IteratorStepstill 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.IteratorNextgets used in%AsyncFromSyncIteratorPrototype%.next(the thing which handlesfor awaitover a sync iterator)IteratorCompleteandIteratorValueget used infor ofandyield *so that they can share logic between sync vs async iteration, plus in%AsyncFromSyncIteratorPrototype.
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.
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.
Maybe "Whether the iterator has completed or been closed"?
Maybe "Whether the iterator has completed or been closed"?
sgtm!