Skip to content

For-await does not capture the async iterator next method during acquisition #3618

Closed

Description

@nickna

Run with --no-tsconfig --noLib and, for saved output, --compile --verify.

const iterable = {
    [Symbol.asyncIterator]() {
        let calls = 0;
        return {
            get next() {
                console.log("lookup");
                return function () { return Promise.resolve({ value: ++calls, done: calls > 2 }); };
            }
        };
    }
};
async function run() {
    try { for await (const value of iterable) console.log(value); }
    catch (error) { console.log(error.message); }
}
run();

Node prints lookup, 1, and 2 on separate lines. Acquiring an async iterator should read its next method once and call the captured method for each step with the iterator as the receiver.

The interpreter prints Cannot call method 'next' on SharpTSObject. without invoking the getter. Saved output passes IL verification but prints lookup before each step, including the final step that reports done. Found while working on #3598 and #3607.

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