diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 17a0a4a509..1396ee0c31 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -183,10 +183,8 @@ inline ThrowCompletionOr get_by_value(VM& vm, Value base_value, Value pro inline ThrowCompletionOr get_global(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& identifier, GlobalVariableCache& cache) { auto& vm = interpreter.vm(); - auto& realm = *vm.current_realm(); - - auto& binding_object = realm.global_environment().object_record().binding_object(); - auto& declarative_record = realm.global_environment().declarative_record(); + auto& binding_object = interpreter.global_object(); + auto& declarative_record = interpreter.global_declarative_environment(); // OPTIMIZATION: If the shape of the object hasn't changed, we can use the cached property offset. auto& shape = binding_object.shape(); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index facfb4299e..1ba9065af3 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -426,6 +426,9 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa TemporaryChange restore_executable { m_current_executable, &executable }; TemporaryChange restore_saved_jump { m_scheduled_jump, static_cast(nullptr) }; + TemporaryChange restore_realm { m_realm, vm().current_realm() }; + TemporaryChange restore_global_object { m_global_object, &m_realm->global_object() }; + TemporaryChange restore_global_declarative_environment { m_global_declarative_environment, &m_realm->global_environment().declarative_record() }; VERIFY(!vm().execution_context_stack().is_empty()); @@ -530,11 +533,6 @@ ThrowCompletionOr> compile(VM& vm, ASTNode co return bytecode_executable; } -Realm& Interpreter::realm() -{ - return *m_vm.current_realm(); -} - void Interpreter::push_call_frame(Variant, CallFrame*> frame) { m_call_frames.append(move(frame)); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.h b/Userland/Libraries/LibJS/Bytecode/Interpreter.h index 0ef2185eaf..ae9f91c5be 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.h +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.h @@ -51,7 +51,9 @@ public: explicit Interpreter(VM&); ~Interpreter(); - Realm& realm(); + [[nodiscard]] Realm& realm() { return *m_realm; } + [[nodiscard]] Object& global_object() { return *m_global_object; } + [[nodiscard]] DeclarativeEnvironment& global_declarative_environment() { return *m_global_declarative_environment; } VM& vm() { return m_vm; } VM const& vm() const { return m_vm; } @@ -125,6 +127,9 @@ private: BasicBlock const* m_scheduled_jump { nullptr }; Executable* m_current_executable { nullptr }; BasicBlock const* m_current_block { nullptr }; + Realm* m_realm { nullptr }; + Object* m_global_object { nullptr }; + DeclarativeEnvironment* m_global_declarative_environment { nullptr }; Optional m_pc {}; };