throwsAsync, Promise.try: avoid unneeded syntax

Followup to #4086
This commit is contained in:
Jordan Harband 2024-05-17 09:13:21 -07:00
parent 57c7d06bf1
commit 5217ef396e
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 75 additions and 73 deletions

View File

@ -28,7 +28,8 @@ function asyncTest(testFunc) {
} }
} }
assert.throwsAsync = async function (expectedErrorConstructor, func, message) { assert.throwsAsync = function (expectedErrorConstructor, func, message) {
return new Promise(function (resolve) {
var innerThenable; var innerThenable;
if (message === undefined) { if (message === undefined) {
message = ""; message = "";
@ -63,7 +64,7 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
} }
try { try {
return innerThenable.then( resolve(innerThenable.then(
function () { function () {
message += message +=
"Expected a " + "Expected a " +
@ -91,7 +92,7 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
throw new Test262Error(message); throw new Test262Error(message);
} }
} }
); ));
} catch (thrown) { } catch (thrown) {
if (typeof thrown !== "object" || thrown === null) { if (typeof thrown !== "object" || thrown === null) {
message += message +=
@ -108,4 +109,5 @@ assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
} }
throw new Test262Error(message); throw new Test262Error(message);
} }
});
}; };

View File

@ -9,8 +9,8 @@ flags: [async]
includes: [asyncHelpers.js] includes: [asyncHelpers.js]
---*/ ---*/
asyncTest(async function() { asyncTest(function () {
await assert.throwsAsync( return assert.throwsAsync(
Test262Error, Test262Error,
function () { function () {
Promise.try(function () { throw new Test262Error(); }) Promise.try(function () { throw new Test262Error(); })