tc39 / ecma262

Status, process, and documents for ECMA-262
https://tc39.es/ecma262/
Other
14.85k stars 1.27k forks source link

More tweaks for the iterator handling AOs #3311

Closed bakkot closed 1 month ago

bakkot commented 2 months ago

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

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.

bakkot commented 2 months ago

Maybe "Whether the iterator has completed or been closed"?

syg commented 2 months ago

Maybe "Whether the iterator has completed or been closed"?

sgtm!