From 1de475b4042f9ab8ff1ae9f54f927cfc2a5fe5c0 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sat, 18 May 2024 17:25:43 +0200 Subject: [PATCH] LibJS: Prepare yield object before re-routing it through finally --- Userland/Libraries/LibJS/Bytecode/Generator.h | 6 ++- .../Libraries/LibJS/Bytecode/Instruction.h | 1 + .../Libraries/LibJS/Bytecode/Interpreter.cpp | 43 +++++++++++++------ .../Libraries/LibJS/Bytecode/Interpreter.h | 1 + Userland/Libraries/LibJS/Bytecode/Op.h | 25 +++++++++++ .../LibJS/Tests/try-return-finally.js | 40 +++++++++++++++++ 6 files changed, 102 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h index 8d4fb234c92..e481d66686d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.h +++ b/Userland/Libraries/LibJS/Bytecode/Generator.h @@ -283,11 +283,13 @@ public: // * Interpreter::run_bytecode::handle_ContinuePendingUnwind // * Return::execute_impl // * Yield::execute_impl - emit(Operand(Register::saved_return_value()), value); + if constexpr (IsSame) + emit(Operand(Register::saved_return_value()), value); + else + emit(Operand(Register::saved_return_value()), value); emit(Operand(Register::exception()), add_constant(Value {})); // FIXME: Do we really need to clear the return value register here? emit(Operand(Register::return_value()), add_constant(Value {})); - emit(Label { *m_current_basic_block->finalizer() }); return; } diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index ec026b9c896..f30793758f4 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -110,6 +110,7 @@ O(NewRegExp) \ O(NewTypeError) \ O(Not) \ + O(PrepareYield) \ O(PostfixDecrement) \ O(PostfixIncrement) \ O(PutById) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 76ebf165af6..0b206058e8d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -161,6 +161,22 @@ ALWAYS_INLINE void Interpreter::set(Operand op, Value value) m_registers_and_constants_and_locals.data()[op.index()] = value; } +ALWAYS_INLINE Value Interpreter::do_yield(Value value, Optional