diff options
author | Linus Groh <mail@linusgroh.de> | 2022-08-22 18:56:16 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-23 13:58:30 +0100 |
commit | 7c468b5a772342243d1b306389c34ce485033392 (patch) | |
tree | 00a97c85b321b88e63709b5202b95c871d178abb /Userland/Services/WebContent | |
parent | b465f46e009164b5d2659f216b9307efee187222 (diff) | |
download | serenity-7c468b5a772342243d1b306389c34ce485033392.zip |
LibJS: Pass Realm to GlobalObject::initialize_global_object()
Global object initialization is tightly coupled to realm creation, so
simply pass it to the function instead of relying on the non-standard
'associated realm' concept, which I'd like to remove later.
This works essentially the same way as regular Object::initialize() now.
Additionally this allows us to forward the realm to GlobalObject's
add_constructor() / initialize_constructor() helpers, so they set the
correct realm on the allocated constructor function object.
Diffstat (limited to 'Userland/Services/WebContent')
-rw-r--r-- | Userland/Services/WebContent/ConsoleGlobalObject.cpp | 4 | ||||
-rw-r--r-- | Userland/Services/WebContent/ConsoleGlobalObject.h | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentConsoleClient.cpp | 7 |
3 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.cpp b/Userland/Services/WebContent/ConsoleGlobalObject.cpp index d4adda9bd9..0b2479b287 100644 --- a/Userland/Services/WebContent/ConsoleGlobalObject.cpp +++ b/Userland/Services/WebContent/ConsoleGlobalObject.cpp @@ -20,9 +20,9 @@ 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); diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.h b/Userland/Services/WebContent/ConsoleGlobalObject.h index 9f024c1859..884ca4b4c7 100644 --- a/Userland/Services/WebContent/ConsoleGlobalObject.h +++ b/Userland/Services/WebContent/ConsoleGlobalObject.h @@ -35,7 +35,7 @@ public: virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override; virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> 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/Userland/Services/WebContent/WebContentConsoleClient.cpp b/Userland/Services/WebContent/WebContentConsoleClient.cpp index 6c4a2171a6..9e3922e97a 100644 --- a/Userland/Services/WebContent/WebContentConsoleClient.cpp +++ b/Userland/Services/WebContent/WebContentConsoleClient.cpp @@ -24,7 +24,8 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J 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& global_object = realm.global_object(); auto console_global_object = m_interpreter->heap().allocate_without_realm<ConsoleGlobalObject>(m_interpreter->realm(), static_cast<Web::Bindings::WindowObject&>(global_object)); @@ -32,8 +33,8 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J // It gets removed immediately after creating the interpreter in Document::interpreter(). auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*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->set_associated_realm(realm); + console_global_object->initialize_global_object(realm); vm.pop_execution_context(); m_console_global_object = JS::make_handle(console_global_object); |