From 378595e8b102a083d14cf240000a61286155d631 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 29 Jul 2023 19:19:34 +1200 Subject: [PATCH] LibJS: Add three more await thenable tests The first test crashes in AST, and fails in bytecode, so the best thing which we can do here without complicated test setup logic is to just skip this test for now. Interestinglny, this crashing test is very similar to the existing thenable test case, and only differs in the way that the thenable is given to the async function. The next two tests are effectively the same as the above two mentioned tests, with the only different being that the thenable calls the fulfill function. For the test case that crashes in AST mode, doing that appears to fix the test case for AST mode (but both still fail in bytecode). --- .../LibJS/Tests/syntax/async-await.js | 75 ++++++++++++++++--- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Tests/syntax/async-await.js b/Userland/Libraries/LibJS/Tests/syntax/async-await.js index 43456d42b5..a561b7e426 100644 --- a/Userland/Libraries/LibJS/Tests/syntax/async-await.js +++ b/Userland/Libraries/LibJS/Tests/syntax/async-await.js @@ -201,14 +201,71 @@ describe("await cannot be used in class static init blocks", () => { }); }); -test.xfailIf(isBytecodeInterpreterEnabled(), "async returning a thenable", () => { - let isCalled = false; - const f = async () => ({ - then() { - isCalled = true; - }, +describe("await thenables", () => { + // FIXME: This test crashes for AST, and fails for bytecode. + test.skip("async returning a thanable variable without fulfilling", () => { + let isCalled = false; + const obj = { + then() { + isCalled = true; + }, + }; + + const f = async () => await obj; + f(); + runQueuedPromiseJobs(); + expect(isCalled).toBe(true); }); - f(); - runQueuedPromiseJobs(); - expect(isCalled).toBe(true); + + test.xfailIf( + isBytecodeInterpreterEnabled(), + "async returning a thanable variable that fulfills", + () => { + let isCalled = false; + const obj = { + then(fulfill) { + isCalled = true; + fulfill(isCalled); + }, + }; + + const f = async () => await obj; + f(); + runQueuedPromiseJobs(); + expect(isCalled).toBe(true); + } + ); + + test.xfailIf( + isBytecodeInterpreterEnabled(), + "async returning a thenable directly without fulfilling", + () => { + let isCalled = false; + const f = async () => ({ + then() { + isCalled = true; + }, + }); + f(); + runQueuedPromiseJobs(); + expect(isCalled).toBe(true); + } + ); + + test.xfailIf( + isBytecodeInterpreterEnabled(), + "async returning a thenable directly that fulfills", + () => { + let isCalled = false; + const f = async () => ({ + then(fulfill) { + isCalled = true; + fulfill(isCalled); + }, + }); + f(); + runQueuedPromiseJobs(); + expect(isCalled).toBe(true); + } + ); });