Await async iterator return() when a for-await loop breaks#1580
Merged
saghul merged 1 commit intoJul 17, 2026
Conversation
When a `for await` loop was exited via `break`, the async iterator's return() method was called but its result was not awaited. Per spec, AsyncIteratorClose performs Await(Call(return, iterator)), so execution must not continue until that promise settles. Only async generators awaited the close; a plain async function used the synchronous OP_iterator_close path. The break/loop-close emit now routes async iterators through a shared emit_iterator_close() helper that calls return() and awaits it, and skips the call when the iterator has already been closed on normal completion (the slot is undefined), matching the sync for-of behavior.
saghul
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
for awaitloop is exited viabreak, the async iterator'sreturn()method is called but its result is not awaited. Per spec,AsyncIteratorCloseperformsAwait(Call(return, iterator)), so code after the loop must not run until that promise settles. Only async generators awaited the close; a plain async function used the synchronous close path.returncalledreturn()promise awaitedlogreturn, afterreturn, resolved, afterThe break/loop close now routes async iterators through a shared helper that calls
return()and awaits it, and skips the call when the iterator was already closed on normal completion.Disclaimer: This is an AI-assisted patch from the v8x project.