diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index c47fe41357..d0ec45c665 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -206,11 +206,9 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() }; if (in_frame) - m_register_windows.append(in_frame); + push_register_window(in_frame, executable.number_of_registers); else - m_register_windows.append(make(MarkedVector(vm().heap()), MarkedVector>(vm().heap()), MarkedVector>(vm().heap()), Vector {})); - - registers().resize(executable.number_of_registers); + push_register_window(make(MarkedVector(vm().heap()), MarkedVector>(vm().heap()), MarkedVector>(vm().heap()), Vector {}), executable.number_of_registers); for (;;) { Bytecode::InstructionStreamIterator pc(m_current_block->instruction_stream()); @@ -306,7 +304,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu } } - auto frame = m_register_windows.take_last(); + auto frame = pop_register_window(); Value return_value = js_undefined(); if (!m_return_value.is_empty()) { @@ -453,4 +451,18 @@ Realm& Interpreter::realm() return *m_vm.current_realm(); } +void Interpreter::push_register_window(Variant, RegisterWindow*> window, size_t register_count) +{ + m_register_windows.append(move(window)); + this->window().registers.resize(register_count); + m_current_register_window = this->window().registers; +} + +Variant, RegisterWindow*> Interpreter::pop_register_window() +{ + auto window = m_register_windows.take_last(); + m_current_register_window = m_register_windows.is_empty() ? Span {} : this->window().registers; + return window; +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.h b/Userland/Libraries/LibJS/Bytecode/Interpreter.h index 1245e08030..ba14691723 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.h +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.h @@ -101,10 +101,15 @@ private: return const_cast(this)->window(); } - MarkedVector& registers() { return window().registers; } + Span registers() { return m_current_register_window; } + ReadonlySpan registers() const { return m_current_register_window; } + + void push_register_window(Variant, RegisterWindow*>, size_t register_count); + [[nodiscard]] Variant, RegisterWindow*> pop_register_window(); VM& m_vm; Vector, RegisterWindow*>> m_register_windows; + Span m_current_register_window; Optional m_pending_jump; BasicBlock const* m_scheduled_jump { nullptr }; Value m_return_value;