Skip to content

Interpreter direct native async yield-star does not adopt synchronous generator values #3667

Open

Description

@nickna

Direct delegation from an interpreted async generator to a native synchronous generator yields the Promise object instead of adopting its value. A rejected promise therefore fulfills the outer next() and leaves the inner generator suspended.

const marker = {};
function* values() {
    try { yield Promise.reject(marker); }
    finally { console.log("inner finally"); }
}
async function* run() { yield* values(); }
async function main() {
    try {
        const result = await run().next();
        console.log("resolved", result.done, result.value === marker);
    } catch (error) { console.log("rejected", error === marker); }
}
main();

Interpreted output on unchanged baseline 0b44ff4de and after scoped PR #3663 review fix 774f626b4:

resolved false false

Current ECMAScript AsyncFromSyncIteratorContinuation requires value adoption and closing the non-final synchronous iterator on rejection, so the expected output is:

inner finally
rejected true

Node v22.23.2 prints rejected true; it adopts the promise but predates the newer close-on-rejection behavior, so current Test262 is the cleanup oracle.

Pinned Test262 d5e73fc8d2c663554fb72e2380a8c2bc1a318a33 case test/built-ins/AsyncFromSyncIteratorPrototype/next/yield-iterator-next-rejected-promise-close.js fails in the interpreted worker with:

Promise should be rejected Expected a Reject to be thrown asynchronously but no exception was thrown at all

SharpTSAsyncGenerator.DelegateYieldStarAsync directly handles iterable is SharpTSGenerator through DelegateGeneratorAsync; that branch bypasses the async-from-sync value adoption path. A custom iterable factory returning the same native generator uses the acquired iterator path and passes a new finally/error-identity regression in 774f626b4.

This is independent of the acquired custom iterator rejection cleanup fixed for review comment 4546709732. The emitted-adapter omission is separately tracked in #3666. No production fix was expanded into the direct-native branch during that scoped review correction.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions