@@ -167,12 +167,12 @@ Interpreter::~Interpreter()
167167
168168ALWAYS_INLINE Value Interpreter::get (Operand op) const
169169{
170- return m_registers_and_constants_and_locals_arguments .data ()[op.index ()];
170+ return m_running_execution_context-> registers_and_constants_and_locals_arguments .data ()[op.index ()];
171171}
172172
173173ALWAYS_INLINE void Interpreter::set (Operand op, Value value)
174174{
175- m_registers_and_constants_and_locals_arguments .data ()[op.index ()] = value;
175+ m_running_execution_context-> registers_and_constants_and_locals_arguments .data ()[op.index ()] = value;
176176}
177177
178178ALWAYS_INLINE Value Interpreter::do_yield (Value value, Optional<Label> continuation)
@@ -308,7 +308,7 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
308308NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception (u32 & program_counter, Value exception)
309309{
310310 reg (Register::exception ()) = exception;
311- m_scheduled_jump = {};
311+ m_running_execution_context-> scheduled_jump = {};
312312 auto handlers = current_executable ().exception_handlers_for_offset (program_counter);
313313 if (!handlers.has_value ()) {
314314 return HandleExceptionResponse::ExitFromExecutable;
@@ -318,7 +318,7 @@ NEVER_INLINE Interpreter::HandleExceptionResponse Interpreter::handle_exception(
318318
319319 VERIFY (!running_execution_context ().unwind_contexts .is_empty ());
320320 auto & unwind_context = running_execution_context ().unwind_contexts .last ();
321- VERIFY (unwind_context.executable == m_current_executable );
321+ VERIFY (unwind_context.executable == & current_executable () );
322322
323323 if (handler.has_value ()) {
324324 program_counter = handler.value ();
@@ -492,7 +492,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
492492 if (auto finalizer = handlers.value ().finalizer_offset ; finalizer.has_value ()) {
493493 VERIFY (!running_execution_context.unwind_contexts .is_empty ());
494494 auto & unwind_context = running_execution_context.unwind_contexts .last ();
495- VERIFY (unwind_context.executable == m_current_executable );
495+ VERIFY (unwind_context.executable == & current_executable () );
496496 reg (Register::saved_return_value ()) = reg (Register::return_value ());
497497 reg (Register::return_value ()) = js_special_empty_value ();
498498 program_counter = finalizer.value ();
@@ -503,21 +503,21 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
503503 return ;
504504 }
505505 auto const old_scheduled_jump = running_execution_context.previously_scheduled_jumps .take_last ();
506- if (m_scheduled_jump .has_value ()) {
507- program_counter = m_scheduled_jump .value ();
508- m_scheduled_jump = {};
506+ if (m_running_execution_context-> scheduled_jump .has_value ()) {
507+ program_counter = m_running_execution_context-> scheduled_jump .value ();
508+ m_running_execution_context-> scheduled_jump = {};
509509 } else {
510510 program_counter = instruction.resume_target ().address ();
511511 // set the scheduled jump to the old value if we continue
512512 // where we left it
513- m_scheduled_jump = old_scheduled_jump;
513+ m_running_execution_context-> scheduled_jump = old_scheduled_jump;
514514 }
515515 goto start;
516516 }
517517
518518 handle_ScheduleJump: {
519519 auto & instruction = *reinterpret_cast <Op::ScheduleJump const *>(&bytecode[program_counter]);
520- m_scheduled_jump = instruction.target ().address ();
520+ m_running_execution_context-> scheduled_jump = instruction.target ().address ();
521521 auto finalizer = executable.exception_handlers_for_offset (program_counter).value ().finalizer_offset ;
522522 VERIFY (finalizer.has_value ());
523523 program_counter = finalizer.value ();
@@ -704,26 +704,24 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
704704
705705Utf16FlyString const & Interpreter::get_identifier (IdentifierTableIndex index) const
706706{
707- return m_identifier_table .data ()[index.value ];
707+ return m_running_execution_context-> identifier_table .data ()[index.value ];
708708}
709709
710710Interpreter::ResultAndReturnRegister Interpreter::run_executable (Executable& executable, Optional<size_t > entry_point, Value initial_accumulator_value)
711711{
712712 dbgln_if (JS_BYTECODE_DEBUG, " Bytecode::Interpreter will run unit {:p}" , &executable);
713713
714- TemporaryChange restore_executable { m_current_executable, GC::Ptr { executable } };
715- TemporaryChange restore_saved_jump { m_scheduled_jump, Optional<size_t > {} };
716- TemporaryChange restore_realm { m_realm, GC::Ptr { vm ().current_realm () } };
717- TemporaryChange restore_global_object { m_global_object, GC::Ptr { m_realm->global_object () } };
718- TemporaryChange restore_global_declarative_environment { m_global_declarative_environment, GC::Ptr { m_realm->global_environment ().declarative_record () } };
719- TemporaryChange restore_identifier_table { m_identifier_table, executable.identifier_table ->identifiers () };
720-
721714 auto & running_execution_context = vm ().running_execution_context ();
715+ TemporaryChange restore_running_execution_context { m_running_execution_context, &running_execution_context };
716+
717+ running_execution_context.global_object = realm ().global_object ();
718+ running_execution_context.global_declarative_environment = realm ().global_environment ().declarative_record ();
719+ running_execution_context.identifier_table = executable.identifier_table ->identifiers ();
720+
722721 u32 registers_and_constants_and_locals_count = executable.number_of_registers + executable.constants .size () + executable.local_variable_names .size ();
723722 VERIFY (registers_and_constants_and_locals_count <= running_execution_context.registers_and_constants_and_locals_and_arguments_span ().size ());
724723
725- TemporaryChange restore_running_execution_context { m_running_execution_context, &running_execution_context };
726- TemporaryChange restore_registers_and_constants_and_locals { m_registers_and_constants_and_locals_arguments, running_execution_context.registers_and_constants_and_locals_and_arguments_span () };
724+ running_execution_context.registers_and_constants_and_locals_arguments = running_execution_context.registers_and_constants_and_locals_and_arguments_span ();
727725
728726 reg (Register::accumulator ()) = initial_accumulator_value;
729727 reg (Register::return_value ()) = js_special_empty_value ();
@@ -773,10 +771,10 @@ Interpreter::ResultAndReturnRegister Interpreter::run_executable(Executable& exe
773771void Interpreter::enter_unwind_context ()
774772{
775773 running_execution_context ().unwind_contexts .empend (
776- m_current_executable ,
774+ current_executable () ,
777775 running_execution_context ().lexical_environment );
778- running_execution_context ().previously_scheduled_jumps .append (m_scheduled_jump );
779- m_scheduled_jump = {};
776+ running_execution_context ().previously_scheduled_jumps .append (m_running_execution_context-> scheduled_jump );
777+ m_running_execution_context-> scheduled_jump = {};
780778}
781779
782780void Interpreter::leave_unwind_context ()
@@ -797,13 +795,13 @@ void Interpreter::catch_exception(Operand dst)
797795
798796void Interpreter::restore_scheduled_jump ()
799797{
800- m_scheduled_jump = running_execution_context ().previously_scheduled_jumps .take_last ();
798+ m_running_execution_context-> scheduled_jump = running_execution_context ().previously_scheduled_jumps .take_last ();
801799}
802800
803801void Interpreter::leave_finally ()
804802{
805803 reg (Register::exception ()) = js_special_empty_value ();
806- m_scheduled_jump = running_execution_context ().previously_scheduled_jumps .take_last ();
804+ m_running_execution_context-> scheduled_jump = running_execution_context ().previously_scheduled_jumps .take_last ();
807805}
808806
809807void Interpreter::enter_object_environment (Object& object)
0 commit comments