Files
scriptc/tests/test262/assert-throws.js
Chris Tate 3d04a561ef Expand static Test262 execution and exception behavior (#486)
* Expand static Test262 harness and exception semantics

* Ignore ASan fiber warning in dev source test

* Refresh TS7 parity baselines after main rebase
2026-09-27 09:21:29 -05:00

18 lines
589 B
JavaScript

/**
* @param {unknown} expectedErrorConstructor
* @param {() => unknown} func
* @returns {"pass" | "missing" | "primitive" | "wrong" | "invalid" | "unsupported"}
*/
export function throwsOutcome(expectedErrorConstructor, func) {
if (typeof func !== "function") return "invalid";
try {
func();
} catch (thrown) {
const value = thrown;
if (typeof thrown !== "object" || thrown === null) return "primitive";
if (!(thrown instanceof Error)) return "unsupported";
return value.constructor === expectedErrorConstructor ? "pass" : "wrong";
}
return "missing";
}