summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-08-22 18:56:16 +0100
committerLinus Groh <mail@linusgroh.de>2022-08-23 13:58:30 +0100
commit7c468b5a772342243d1b306389c34ce485033392 (patch)
tree00a97c85b321b88e63709b5202b95c871d178abb /Userland
parentb465f46e009164b5d2659f216b9307efee187222 (diff)
downloadserenity-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')
-rw-r--r--Userland/Applications/Spreadsheet/JSIntegration.cpp4
-rw-r--r--Userland/Applications/Spreadsheet/JSIntegration.h2
-rw-r--r--Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp4
-rw-r--r--Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp5
-rw-r--r--Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h4
-rw-r--r--Userland/Libraries/LibJS/Interpreter.h8
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.cpp70
-rw-r--r--Userland/Libraries/LibJS/Runtime/GlobalObject.h13
-rw-r--r--Userland/Libraries/LibJS/Runtime/Realm.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp2
-rw-r--r--Userland/Libraries/LibTest/JavaScriptTestRunner.h6
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.h2
-rw-r--r--Userland/Services/WebContent/ConsoleGlobalObject.cpp4
-rw-r--r--Userland/Services/WebContent/ConsoleGlobalObject.h2
-rw-r--r--Userland/Services/WebContent/WebContentConsoleClient.cpp7
-rw-r--r--Userland/Utilities/js.cpp12
17 files changed, 75 insertions, 78 deletions
diff --git a/Userland/Applications/Spreadsheet/JSIntegration.cpp b/Userland/Applications/Spreadsheet/JSIntegration.cpp
index 601ae8fcef..10b5d3d420 100644
--- a/Userland/Applications/Spreadsheet/JSIntegration.cpp
+++ b/Userland/Applications/Spreadsheet/JSIntegration.cpp
@@ -144,9 +144,9 @@ JS::ThrowCompletionOr<bool> SheetGlobalObject::internal_set(const JS::PropertyKe
return Base::internal_set(property_name, value, receiver);
}
-void SheetGlobalObject::initialize_global_object()
+void SheetGlobalObject::initialize_global_object(JS::Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_native_function("get_real_cell_contents", get_real_cell_contents, 1, attr);
define_native_function("set_real_cell_contents", set_real_cell_contents, 2, attr);
diff --git a/Userland/Applications/Spreadsheet/JSIntegration.h b/Userland/Applications/Spreadsheet/JSIntegration.h
index ecd1d32d5e..bf6f007e5e 100644
--- a/Userland/Applications/Spreadsheet/JSIntegration.h
+++ b/Userland/Applications/Spreadsheet/JSIntegration.h
@@ -30,7 +30,7 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override;
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver) const override;
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(JS::Realm&) override;
JS_DECLARE_NATIVE_FUNCTION(get_real_cell_contents);
JS_DECLARE_NATIVE_FUNCTION(set_real_cell_contents);
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
index 54a31f7ae8..74e7568ac7 100644
--- a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
+++ b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp
@@ -23,7 +23,7 @@ $262Object::$262Object(Realm& realm)
{
}
-void $262Object::initialize(JS::Realm& realm)
+void $262Object::initialize(Realm& realm)
{
Base::initialize(realm);
@@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
VERIFY(realm_global_object);
realm->set_global_object(realm_global_object, nullptr);
realm_global_object->set_associated_realm(*realm);
- realm_global_object->initialize_global_object();
+ realm_global_object->initialize_global_object(*realm);
return Value(realm_global_object->$262());
}
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp
index da196c73da..4d2e7c0841 100644
--- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp
@@ -14,11 +14,10 @@
namespace JS::Test262 {
-void GlobalObject::initialize_global_object()
+void GlobalObject::initialize_global_object(Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
- auto& realm = *associated_realm();
m_$262 = vm().heap().allocate<$262Object>(realm, realm);
// https://github.com/tc39/test262/blob/master/INTERPRETING.md#host-defined-functions
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h
index 359f5b5036..168467d0b6 100644
--- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h
+++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -19,7 +19,7 @@ public:
: JS::GlobalObject(realm)
{
}
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(Realm&) override;
virtual ~GlobalObject() override = default;
$262Object* $262() const { return m_$262; }
diff --git a/Userland/Libraries/LibJS/Interpreter.h b/Userland/Libraries/LibJS/Interpreter.h
index 9d939ee8c0..0a8c1647fd 100644
--- a/Userland/Libraries/LibJS/Interpreter.h
+++ b/Userland/Libraries/LibJS/Interpreter.h
@@ -44,11 +44,13 @@ public:
VM::InterpreterExecutionScope scope(*interpreter);
GlobalObject* global_object { nullptr };
+ Realm* realm { nullptr };
interpreter->m_global_execution_context = MUST(Realm::initialize_host_defined_realm(
vm,
- [&](Realm& realm) -> GlobalObject* {
- global_object = interpreter->heap().allocate_without_realm<GlobalObjectType>(realm, forward<Args>(args)...);
+ [&](Realm& realm_) -> GlobalObject* {
+ global_object = interpreter->heap().allocate_without_realm<GlobalObjectType>(realm_, forward<Args>(args)...);
+ realm = &realm_;
return global_object;
},
nullptr));
@@ -58,7 +60,7 @@ public:
interpreter->m_global_execution_context->function_name = global_execution_context_name;
interpreter->m_global_object = make_handle(global_object);
- interpreter->m_realm = make_handle(global_object->associated_realm());
+ interpreter->m_realm = make_handle(realm);
return interpreter;
}
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
index d0ca61d56e..ceb9718c93 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -145,15 +145,13 @@ GlobalObject::GlobalObject(Realm& realm)
{
}
-void GlobalObject::initialize_global_object()
+void GlobalObject::initialize_global_object(Realm& realm)
{
auto& vm = this->vm();
ensure_shape_is_unique();
// These are done first since other prototypes depend on their presence.
- VERIFY(associated_realm());
- auto& realm = *associated_realm();
m_empty_object_shape = heap().allocate_without_realm<Shape>(realm);
m_object_prototype = heap().allocate_without_realm<ObjectPrototype>(realm);
m_function_prototype = heap().allocate_without_realm<FunctionPrototype>(realm);
@@ -200,7 +198,7 @@ void GlobalObject::initialize_global_object()
// Must be allocated before `Intl::Intl` below.
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
- initialize_constructor(vm.names.ClassName, m_intl_##snake_name##_constructor, m_intl_##snake_name##_prototype);
+ initialize_constructor(realm, vm.names.ClassName, m_intl_##snake_name##_constructor, m_intl_##snake_name##_prototype);
JS_ENUMERATE_INTL_OBJECTS
#undef __JS_ENUMERATE
@@ -212,7 +210,7 @@ void GlobalObject::initialize_global_object()
// Must be allocated before `Temporal::Temporal` below.
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
- initialize_constructor(vm.names.ClassName, m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype);
+ initialize_constructor(realm, vm.names.ClassName, m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype);
JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE
@@ -259,44 +257,44 @@ void GlobalObject::initialize_global_object()
define_direct_property(vm.names.Temporal, heap().allocate<Temporal::Temporal>(realm, realm), attr);
// This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype.
- initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype);
-
- add_constructor(vm.names.AggregateError, m_aggregate_error_constructor, m_aggregate_error_prototype);
- add_constructor(vm.names.Array, m_array_constructor, m_array_prototype);
- add_constructor(vm.names.ArrayBuffer, m_array_buffer_constructor, m_array_buffer_prototype);
- add_constructor(vm.names.BigInt, m_bigint_constructor, m_bigint_prototype);
- add_constructor(vm.names.Boolean, m_boolean_constructor, m_boolean_prototype);
- add_constructor(vm.names.DataView, m_data_view_constructor, m_data_view_prototype);
- add_constructor(vm.names.Date, m_date_constructor, m_date_prototype);
- add_constructor(vm.names.Error, m_error_constructor, m_error_prototype);
- add_constructor(vm.names.FinalizationRegistry, m_finalization_registry_constructor, m_finalization_registry_prototype);
- add_constructor(vm.names.Function, m_function_constructor, m_function_prototype);
- add_constructor(vm.names.Map, m_map_constructor, m_map_prototype);
- add_constructor(vm.names.Number, m_number_constructor, m_number_prototype);
- add_constructor(vm.names.Object, m_object_constructor, m_object_prototype);
- add_constructor(vm.names.Promise, m_promise_constructor, m_promise_prototype);
- add_constructor(vm.names.Proxy, m_proxy_constructor, nullptr);
- add_constructor(vm.names.RegExp, m_regexp_constructor, m_regexp_prototype);
- add_constructor(vm.names.Set, m_set_constructor, m_set_prototype);
- add_constructor(vm.names.ShadowRealm, m_shadow_realm_constructor, m_shadow_realm_prototype);
- add_constructor(vm.names.String, m_string_constructor, m_string_prototype);
- add_constructor(vm.names.Symbol, m_symbol_constructor, m_symbol_prototype);
- add_constructor(vm.names.WeakMap, m_weak_map_constructor, m_weak_map_prototype);
- add_constructor(vm.names.WeakRef, m_weak_ref_constructor, m_weak_ref_prototype);
- add_constructor(vm.names.WeakSet, m_weak_set_constructor, m_weak_set_prototype);
-
- initialize_constructor(vm.names.TypedArray, m_typed_array_constructor, m_typed_array_prototype);
+ initialize_constructor(realm, vm.names.Error, m_error_constructor, m_error_prototype);
+
+ add_constructor(realm, vm.names.AggregateError, m_aggregate_error_constructor, m_aggregate_error_prototype);
+ add_constructor(realm, vm.names.Array, m_array_constructor, m_array_prototype);
+ add_constructor(realm, vm.names.ArrayBuffer, m_array_buffer_constructor, m_array_buffer_prototype);
+ add_constructor(realm, vm.names.BigInt, m_bigint_constructor, m_bigint_prototype);
+ add_constructor(realm, vm.names.Boolean, m_boolean_constructor, m_boolean_prototype);
+ add_constructor(realm, vm.names.DataView, m_data_view_constructor, m_data_view_prototype);
+ add_constructor(realm, vm.names.Date, m_date_constructor, m_date_prototype);
+ add_constructor(realm, vm.names.Error, m_error_constructor, m_error_prototype);
+ add_constructor(realm, vm.names.FinalizationRegistry, m_finalization_registry_constructor, m_finalization_registry_prototype);
+ add_constructor(realm, vm.names.Function, m_function_constructor, m_function_prototype);
+ add_constructor(realm, vm.names.Map, m_map_constructor, m_map_prototype);
+ add_constructor(realm, vm.names.Number, m_number_constructor, m_number_prototype);
+ add_constructor(realm, vm.names.Object, m_object_constructor, m_object_prototype);
+ add_constructor(realm, vm.names.Promise, m_promise_constructor, m_promise_prototype);
+ add_constructor(realm, vm.names.Proxy, m_proxy_constructor, nullptr);
+ add_constructor(realm, vm.names.RegExp, m_regexp_constructor, m_regexp_prototype);
+ add_constructor(realm, vm.names.Set, m_set_constructor, m_set_prototype);
+ add_constructor(realm, vm.names.ShadowRealm, m_shadow_realm_constructor, m_shadow_realm_prototype);
+ add_constructor(realm, vm.names.String, m_string_constructor, m_string_prototype);
+ add_constructor(realm, vm.names.Symbol, m_symbol_constructor, m_symbol_prototype);
+ add_constructor(realm, vm.names.WeakMap, m_weak_map_constructor, m_weak_map_prototype);
+ add_constructor(realm, vm.names.WeakRef, m_weak_ref_constructor, m_weak_ref_prototype);
+ add_constructor(realm, vm.names.WeakSet, m_weak_set_constructor, m_weak_set_prototype);
+
+ initialize_constructor(realm, vm.names.TypedArray, m_typed_array_constructor, m_typed_array_prototype);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
- add_constructor(vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype);
+ add_constructor(realm, vm.names.ClassName, m_##snake_name##_constructor, m_##snake_name##_prototype);
JS_ENUMERATE_NATIVE_ERRORS
JS_ENUMERATE_TYPED_ARRAYS
#undef __JS_ENUMERATE
// NOTE: These constructors cannot be initialized with add_constructor as they have no global binding.
- initialize_constructor(vm.names.GeneratorFunction, m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable);
- initialize_constructor(vm.names.AsyncGeneratorFunction, m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable);
- initialize_constructor(vm.names.AsyncFunction, m_async_function_constructor, m_async_function_prototype, Attribute::Configurable);
+ initialize_constructor(realm, vm.names.GeneratorFunction, m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable);
+ initialize_constructor(realm, vm.names.AsyncGeneratorFunction, m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable);
+ initialize_constructor(realm, vm.names.AsyncFunction, m_async_function_constructor, m_async_function_prototype, Attribute::Configurable);
// 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor
m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable);
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
index f013ec8f7c..ef9a2ae1c2 100644
--- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h
+++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h
@@ -18,7 +18,7 @@ class GlobalObject : public Object {
public:
explicit GlobalObject(Realm&);
- virtual void initialize_global_object();
+ virtual void initialize_global_object(Realm&);
virtual ~GlobalObject() override;
@@ -103,9 +103,9 @@ protected:
virtual void visit_edges(Visitor&) override;
template<typename ConstructorType>
- void initialize_constructor(PropertyKey const&, ConstructorType*&, Object* prototype, PropertyAttributes = Attribute::Writable | Attribute::Configurable);
+ void initialize_constructor(Realm&, PropertyKey const&, ConstructorType*&, Object* prototype, PropertyAttributes = Attribute::Writable | Attribute::Configurable);
template<typename ConstructorType>
- void add_constructor(PropertyKey const&, ConstructorType*&, Object* prototype);
+ void add_constructor(Realm&, PropertyKey const&, ConstructorType*&, Object* prototype);
private:
virtual bool is_global_object() const final { return true; }
@@ -174,10 +174,9 @@ private:
};
template<typename ConstructorType>
-inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
+inline void GlobalObject::initialize_constructor(Realm& realm, PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
{
auto& vm = this->vm();
- auto& realm = *associated_realm();
constructor = heap().allocate<ConstructorType>(realm, realm);
constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
if (prototype)
@@ -185,11 +184,11 @@ inline void GlobalObject::initialize_constructor(PropertyKey const& property_key
}
template<typename ConstructorType>
-inline void GlobalObject::add_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype)
+inline void GlobalObject::add_constructor(Realm& realm, PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype)
{
// Some constructors are pre-initialized separately.
if (!constructor)
- initialize_constructor(property_key, constructor, prototype);
+ initialize_constructor(realm, property_key, constructor, prototype);
define_direct_property(property_key, constructor, Attribute::Writable | Attribute::Configurable);
}
diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp
index 32444af365..ca9e09b449 100644
--- a/Userland/Libraries/LibJS/Runtime/Realm.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp
@@ -64,7 +64,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
// 10. Let globalObj be ? SetDefaultGlobalBindings(realm).
// 11. Create any host-defined global object properties on globalObj.
- realm->global_object().initialize_global_object();
+ realm->global_object().initialize_global_object(*realm);
// 12. Return unused.
return new_context;
diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
index 9db52daed5..82e7f86259 100644
--- a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp
@@ -64,7 +64,7 @@ ThrowCompletionOr<Object*> ShadowRealmConstructor::construct(FunctionObject& new
// 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined).
auto* new_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
realm->set_global_object(new_global_object, nullptr);
- new_global_object->initialize_global_object();
+ new_global_object->initialize_global_object(*realm);
// TODO: I don't think we should have these exactly like this, that doesn't work well with how
// we create global objects. Still, it should be possible to make a ShadowRealm with a
diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
index 31d326dd57..f53c27203d 100644
--- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h
+++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
@@ -197,12 +197,12 @@ public:
virtual ~TestRunnerGlobalObject() override = default;
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(JS::Realm&) override;
};
-inline void TestRunnerGlobalObject::initialize_global_object()
+inline void TestRunnerGlobalObject::initialize_global_object(JS::Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
define_direct_property("global", this, JS::Attribute::Enumerable);
for (auto& entry : s_exposed_global_functions) {
define_native_function(
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
index cef091c1e4..febc8e93a9 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -57,14 +57,12 @@ WindowObject::WindowObject(JS::Realm& realm, HTML::Window& impl)
impl.set_wrapper({}, *this);
}
-void WindowObject::initialize_global_object()
+void WindowObject::initialize_global_object(JS::Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window"));
- auto& realm = *associated_realm();
-
// FIXME: These should be native accessors, not properties
define_direct_property("window", this, JS::Attribute::Enumerable);
define_direct_property("frames", this, JS::Attribute::Enumerable);
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h
index 5d7f187b46..d65673aa33 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.h
@@ -33,7 +33,7 @@ class WindowObject
public:
explicit WindowObject(JS::Realm&, HTML::Window&);
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(JS::Realm&) override;
virtual ~WindowObject() override = default;
HTML::Window& impl() { return *m_impl; }
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);
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 2639206c84..4b19b8094d 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -96,7 +96,7 @@ public:
: GlobalObject(realm)
{
}
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(JS::Realm&) override;
virtual ~ReplObject() override = default;
private:
@@ -117,7 +117,7 @@ public:
: JS::GlobalObject(realm)
{
}
- virtual void initialize_global_object() override;
+ virtual void initialize_global_object(JS::Realm&) override;
virtual ~ScriptObject() override = default;
private:
@@ -1297,9 +1297,9 @@ static JS::ThrowCompletionOr<JS::Value> load_json_impl(JS::VM& vm)
return JS::JSONObject::parse_json_value(vm, json.value());
}
-void ReplObject::initialize_global_object()
+void ReplObject::initialize_global_object(JS::Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
define_direct_property("global", this, JS::Attribute::Enumerable);
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_native_function("exit", exit_interpreter, 0, attr);
@@ -1375,9 +1375,9 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::print)
return JS::js_undefined();
}
-void ScriptObject::initialize_global_object()
+void ScriptObject::initialize_global_object(JS::Realm& realm)
{
- Base::initialize_global_object();
+ Base::initialize_global_object(realm);
define_direct_property("global", this, JS::Attribute::Enumerable);
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
define_native_function("loadINI", load_ini, 1, attr);