From fe1962d7fa0d8bd0d786f50e90bc32f36f723e8c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 5 Apr 2025 14:06:33 +0200 Subject: [PATCH] LibJS: Make SetCompletionType bytecode instruction actually set type This recovers 38 tests in test262 that regressed in a0bb31f7a0e. --- Libraries/LibJS/Bytecode/Interpreter.cpp | 2 +- ...-generator-function-set-completion-type.js | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Libraries/LibJS/Tests/regress/async-generator-function-set-completion-type.js diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index 0bec0d2f05c..31b2e95a402 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -3847,7 +3847,7 @@ void SetCompletionType::execute_impl(Bytecode::Interpreter& interpreter) const { auto& completion_cell = static_cast(interpreter.get(m_completion).as_cell()); auto completion = completion_cell.completion(); - completion_cell.set_completion(Completion { completion.type(), completion.value() }); + completion_cell.set_completion(Completion { m_type, completion.value() }); } ByteString SetCompletionType::to_byte_string_impl(Bytecode::Executable const& executable) const diff --git a/Libraries/LibJS/Tests/regress/async-generator-function-set-completion-type.js b/Libraries/LibJS/Tests/regress/async-generator-function-set-completion-type.js new file mode 100644 index 00000000000..da33402465b --- /dev/null +++ b/Libraries/LibJS/Tests/regress/async-generator-function-set-completion-type.js @@ -0,0 +1,43 @@ +test("test", () => { + var obj = { + [Symbol.iterator]() { + return { + next() { + return { value: 1, done: false }; + }, + }; + }, + }; + + async function* asyncg() { + yield* obj; + } + + let fail = false; + let done = false; + + function FAIL() { + fail = true; + } + + function DONE() { + done = true; + } + + var iter = asyncg(); + + iter.next() + .then(function (result) { + iter.return() + .then(function (result) { + expect(result.done).toBeTrue(); + expect(result.value).toBeUndefined(); + }) + .catch(FAIL); + }) + .catch(FAIL) + .then(DONE); + runQueuedPromiseJobs(); + expect(fail).toBe(false); + expect(done).toBe(true); +});