diff options
author | Linus Groh <mail@linusgroh.de> | 2022-08-28 14:42:50 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-28 16:36:56 +0100 |
commit | cfa588585512540be5738b9b02511560a1126612 (patch) | |
tree | 059013bc0b3bb81c4d7bc792f326fc3402ffac51 /Userland/Libraries | |
parent | 867ad039959e92b05b728f7a45d6793c34aa853f (diff) | |
download | serenity-cfa588585512540be5738b9b02511560a1126612.zip |
LibJS: Turn initialize_global_object() into a regular initialize()
There's nothing special about global object initialization anymore, this
can just work the same way as for any other object now.
Diffstat (limited to 'Userland/Libraries')
10 files changed, 17 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp index b70b70abf9..bca046a5cc 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp +++ b/Userland/Libraries/LibJS/Contrib/Test262/$262Object.cpp @@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm) auto* realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm); VERIFY(realm_global_object); realm->set_global_object(realm_global_object, nullptr); - realm_global_object->initialize_global_object(*realm); + realm_global_object->initialize(*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 2129fcfa04..95d7c3867b 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.cpp @@ -14,9 +14,9 @@ namespace JS::Test262 { -void GlobalObject::initialize_global_object(Realm& realm) +void GlobalObject::initialize(Realm& realm) { - Base::initialize_global_object(realm); + Base::initialize(realm); m_$262 = vm().heap().allocate<$262Object>(realm, realm); diff --git a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h index 168467d0b6..f095233c1a 100644 --- a/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h +++ b/Userland/Libraries/LibJS/Contrib/Test262/GlobalObject.h @@ -19,7 +19,7 @@ public: : JS::GlobalObject(realm) { } - virtual void initialize_global_object(Realm&) override; + virtual void initialize(Realm&) override; virtual ~GlobalObject() override = default; $262Object* $262() const { return m_$262; } diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 3464b6b34a..5d147d37eb 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -88,8 +88,10 @@ GlobalObject::GlobalObject(Realm& realm) } // 9.3.4 SetDefaultGlobalBindings ( realmRec ), https://tc39.es/ecma262/#sec-setdefaultglobalbindings -void GlobalObject::initialize_global_object(Realm& realm) +void GlobalObject::initialize(Realm& realm) { + Base::initialize(realm); + auto& vm = this->vm(); ensure_shape_is_unique(); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index e1704b9c70..0557038477 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -18,8 +18,7 @@ class GlobalObject : public Object { public: explicit GlobalObject(Realm&); - virtual void initialize_global_object(Realm&); - + virtual void initialize(Realm&) override; virtual ~GlobalObject() override; private: diff --git a/Userland/Libraries/LibJS/Runtime/Realm.cpp b/Userland/Libraries/LibJS/Runtime/Realm.cpp index a855589793..10d48b4d8d 100644 --- a/Userland/Libraries/LibJS/Runtime/Realm.cpp +++ b/Userland/Libraries/LibJS/Runtime/Realm.cpp @@ -75,7 +75,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); + realm->global_object().initialize(*realm); // 12. Return unused. return new_context; diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmConstructor.cpp index d0a384ddf0..2ea3f75bd7 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(*realm); + new_global_object->initialize(*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 eef825661d..d4658eabfa 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -194,15 +194,14 @@ public: : JS::GlobalObject(realm) { } - + virtual void initialize(JS::Realm&) override; virtual ~TestRunnerGlobalObject() override = default; - - virtual void initialize_global_object(JS::Realm&) override; }; -inline void TestRunnerGlobalObject::initialize_global_object(JS::Realm& realm) +inline void TestRunnerGlobalObject::initialize(JS::Realm& realm) { - Base::initialize_global_object(realm); + Base::initialize(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 4c58147063..3ac4ff6ba7 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -57,9 +57,9 @@ WindowObject::WindowObject(JS::Realm& realm, HTML::Window& impl) impl.set_wrapper({}, *this); } -void WindowObject::initialize_global_object(JS::Realm& realm) +void WindowObject::initialize(JS::Realm& realm) { - Base::initialize_global_object(realm); + Base::initialize(realm); Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window")); diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h index df346b8f44..7e7a8bac78 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(JS::Realm&) override; + virtual void initialize(JS::Realm&) override; virtual ~WindowObject() override = default; HTML::Window& impl() { return *m_impl; } |