harness/asyncHelpers.js: Refactor assert.throwsAsync to fail fast

This commit is contained in:
Richard Gibson 2024-05-19 13:18:45 -04:00
parent 1b34a1c484
commit b22b500f24

View File

@ -56,32 +56,31 @@ assert.throwsAsync = function (expectedErrorConstructor, func, message) {
} else {
message += " ";
}
if (typeof func === "function") {
try {
innerThenable = func();
if (
innerThenable === null ||
typeof innerThenable !== "object" ||
typeof innerThenable.then !== "function"
) {
message +=
"Expected to obtain an inner promise that would reject with a" +
expectedErrorConstructor.name +
" but result was not a thenable";
throw new Test262Error(message);
}
} catch (thrown) {
message +=
"Expected a " +
expectedErrorConstructor.name +
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
throw new Test262Error(message);
}
} else {
if (typeof func !== "function") {
message +=
"assert.throwsAsync called with an argument that is not a function";
throw new Test262Error(message);
}
try {
innerThenable = func();
if (
innerThenable === null ||
typeof innerThenable !== "object" ||
typeof innerThenable.then !== "function"
) {
message +=
"Expected to obtain an inner promise that would reject with a" +
expectedErrorConstructor.name +
" but result was not a thenable";
throw new Test262Error(message);
}
} catch (thrown) {
message +=
"Expected a " +
expectedErrorConstructor.name +
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
throw new Test262Error(message);
}
try {
resolve(innerThenable.then(