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

@ -617,6 +617,37 @@ class ExpectationError extends Error {
}
};
asyncTest = async (message, callback) => {
if (!__TestResults__[suiteMessage]) __TestResults__[suiteMessage] = {};
const suite = __TestResults__[suiteMessage];
if (Object.prototype.hasOwnProperty.call(suite, message)) {
suite[message] = {
result: "fail",
details: "Another test with the same message did already run",
duration: 0,
};
return;
}
const start = Date.now();
const time_ms = () => Date.now() - start;
try {
await callback();
suite[message] = {
result: "pass",
duration: time_ms(),
};
} catch (e) {
suite[message] = {
result: "fail",
details: String(e),
duration: time_ms(),
};
}
};
test.skip = (message, callback) => {
if (typeof callback !== "function")
throw new Error("test.skip has invalid second argument (must be a function)");