LibJS: Close sync iterator when async wrapper yields rejection

This is a normative change in the ECMA-262 spec. See:
ff129b1
This commit is contained in:
Timothy Flynn 2025-04-28 17:53:04 -04:00 committed by Tim Flynn
commit 568524f8ba
Notes: github-actions[bot] 2025-04-29 11:34:26 +00:00
3 changed files with 162 additions and 45 deletions

View file

@ -77,4 +77,28 @@ describe("normal behavior", () => {
checkResult(promise, TestArray);
expect(callCount).toBe(1);
});
asyncTest("sync iterable is closed upon rejection", async () => {
const thenable = {
then(resolve, reject) {
reject();
},
};
let counter = 0;
function* iterator() {
try {
yield thenable;
} finally {
counter++;
}
}
try {
await Array.fromAsync(iterator());
} catch (e) {}
expect(counter).toBe(1);
});
});