diff --git a/Ladybird/ConsoleClient.cpp b/Ladybird/ConsoleClient.cpp index 8f44aa444a..1a72de5fdc 100644 --- a/Ladybird/ConsoleClient.cpp +++ b/Ladybird/ConsoleClient.cpp @@ -26,16 +26,17 @@ ConsoleClient::ConsoleClient(JS::Console& console, WeakPtr inte JS::DeferGC defer_gc(m_interpreter->heap()); auto& vm = m_interpreter->vm(); - auto& global_object = m_interpreter->global_object(); + auto& realm = m_interpreter->realm(); + auto& window = static_cast(realm.global_object()); - auto console_global_object = m_interpreter->heap().allocate_without_global_object(*global_object.associated_realm(), static_cast(global_object)); + auto console_global_object = m_interpreter->heap().allocate_without_realm(realm, window); // NOTE: We need to push an execution context here for NativeFunction::create() to succeed during global object initialization. // It gets removed immediately after creating the interpreter in Document::interpreter(). auto& eso = verify_cast(*m_interpreter->realm().host_defined()); vm.push_execution_context(eso.realm_execution_context()); console_global_object->set_associated_realm(m_interpreter->realm()); - console_global_object->initialize_global_object(); + console_global_object->initialize_global_object(realm); vm.pop_execution_context(); m_console_global_object = JS::make_handle(console_global_object); diff --git a/Ladybird/ConsoleGlobalObject.cpp b/Ladybird/ConsoleGlobalObject.cpp index 07ba5329f1..c4da91221e 100644 --- a/Ladybird/ConsoleGlobalObject.cpp +++ b/Ladybird/ConsoleGlobalObject.cpp @@ -21,12 +21,12 @@ ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::Bindings::Window { } -void ConsoleGlobalObject::initialize_global_object() +void ConsoleGlobalObject::initialize_global_object(JS::Realm& realm) { - Base::initialize_global_object(); + Base::initialize_global_object(realm); // $0 magic variable - define_native_accessor("$0", inspected_node_getter, nullptr, 0); + define_native_accessor(realm, "$0", inspected_node_getter, nullptr, 0); } void ConsoleGlobalObject::visit_edges(Visitor& visitor) @@ -98,10 +98,11 @@ JS::ThrowCompletionOr> ConsoleGlobalObject::internal JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter) { - auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + auto& realm = *vm.current_realm(); + auto* this_object = TRY(vm.this_value().to_object(vm)); if (!is(this_object)) - return vm.throw_completion(global_object, JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject"); + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject"); auto console_global_object = static_cast(this_object); auto& window = console_global_object->m_window_object->impl(); @@ -109,7 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter) if (!inspected_node) return JS::js_undefined(); - return Web::Bindings::wrap(global_object, *inspected_node); + return Web::Bindings::wrap(realm, *inspected_node); } } diff --git a/Ladybird/ConsoleGlobalObject.h b/Ladybird/ConsoleGlobalObject.h index 2e50f951cf..e6f4c60c16 100644 --- a/Ladybird/ConsoleGlobalObject.h +++ b/Ladybird/ConsoleGlobalObject.h @@ -38,7 +38,7 @@ public: virtual JS::ThrowCompletionOr internal_delete(JS::PropertyKey const& name) override; virtual JS::ThrowCompletionOr> internal_own_property_keys() const override; - virtual void initialize_global_object() override; + virtual void initialize_global_object(JS::Realm&) override; private: virtual void visit_edges(Visitor&) override; diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp index a53f5d3fcf..5c5d06e8ed 100644 --- a/Ladybird/WebView.cpp +++ b/Ladybird/WebView.cpp @@ -186,8 +186,11 @@ public: return; m_interpreter = interpreter; - m_console_client = make(interpreter->global_object().console(), interpreter, m_view); - interpreter->global_object().console().set_client(*m_console_client.ptr()); + + auto& realm = interpreter->realm(); + auto& global_object = realm.global_object(); + m_console_client = make(global_object.console(), interpreter, m_view); + global_object.console().set_client(*m_console_client.ptr()); } virtual void page_did_change_selection() override