From f1367e0e4cd1018fa7026b6431b1d3da66751849 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 30 Sep 2022 17:40:20 -0600 Subject: [PATCH] LibWeb: Use prototype and constructor methods from new Intrinsics This will let us remove the helpers from Window that simply defer to the Intrinsics that are hanging off the [[HostDefined]] slot on the realm --- Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp | 3 +-- Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp | 5 ++--- Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp | 6 ++---- Userland/Libraries/LibWeb/Bindings/LocationObject.cpp | 6 +++--- .../Libraries/LibWeb/Bindings/NavigatorConstructor.cpp | 6 ++---- Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp | 4 ++-- Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp | 5 ++--- Userland/Libraries/LibWeb/Bindings/PlatformObject.h | 2 +- Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp | 6 ++---- Userland/Libraries/LibWeb/Bindings/WindowPrototype.h | 7 ++----- 10 files changed, 19 insertions(+), 31 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp index aa3b0e34ba..9cefc75285 100644 --- a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp @@ -21,10 +21,9 @@ AudioConstructor::AudioConstructor(JS::Realm& realm) void AudioConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLAudioElement"), 0); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "HTMLAudioElement"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 4d1f313ed6..e5ff56eada 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -21,10 +21,9 @@ ImageConstructor::ImageConstructor(JS::Realm& realm) void ImageConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); - NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLImageElement"), 0); + NativeFunction::initialize(realm); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "HTMLImageElement"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp index d7f8dbc37b..8934e19777 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationConstructor.cpp @@ -4,10 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include -#include namespace Web::Bindings { @@ -31,10 +30,9 @@ JS::ThrowCompletionOr LocationConstructor::construct(FunctionObject void LocationConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("Location"), 0); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "Location"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 86b7eca376..531856bdd4 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -24,7 +24,7 @@ namespace Web::Bindings { LocationObject::LocationObject(JS::Realm& realm) : PlatformObject(realm) { - set_prototype(&verify_cast(realm.global_object()).cached_web_prototype("Location")); + set_prototype(&cached_web_prototype(realm, "Location")); } LocationObject::~LocationObject() = default; @@ -315,7 +315,7 @@ JS::ThrowCompletionOr LocationObject::internal_define_own_property(JS::Pro } // 2. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(global_object(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(realm(), String::formatted("Can't define property '{}' on cross-origin object", property_key))); } // 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get @@ -352,7 +352,7 @@ JS::ThrowCompletionOr LocationObject::internal_delete(JS::PropertyKey cons return JS::Object::internal_delete(property_key); // 2. Throw a "SecurityError" DOMException. - return throw_completion(WebIDL::SecurityError::create(global_object(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); + return throw_completion(WebIDL::SecurityError::create(realm(), String::formatted("Can't delete property '{}' on cross-origin object", property_key))); } // 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeys diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp index 262303051e..605df333c2 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorConstructor.cpp @@ -4,10 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include -#include namespace Web::Bindings { @@ -31,10 +30,9 @@ JS::ThrowCompletionOr NavigatorConstructor::construct(FunctionObjec void NavigatorConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("Navigator"), 0); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "Navigator"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp index a85e72ddd4..e7d3ceae22 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -14,7 +14,7 @@ namespace Web { namespace Bindings { NavigatorObject::NavigatorObject(JS::Realm& realm) - : Object(verify_cast(realm.global_object()).cached_web_prototype("Navigator")) + : Object(cached_web_prototype(realm, "Navigator")) { } diff --git a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp index c320213326..b9f0408075 100644 --- a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp @@ -23,10 +23,9 @@ OptionConstructor::OptionConstructor(JS::Realm& realm) void OptionConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); - NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLOptionElement"), 0); + NativeFunction::initialize(realm); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "HTMLOptionElement"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h index 5fa6ddefd0..c3fd70aaf3 100644 --- a/Userland/Libraries/LibWeb/Bindings/PlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/PlatformObject.h @@ -31,7 +31,7 @@ public: HTML::Window& global_object() const; protected: - PlatformObject(JS::Realm&); + explicit PlatformObject(JS::Realm&); explicit PlatformObject(JS::Object& prototype); }; diff --git a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp index de00ee8b3e..b83c62d828 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowConstructor.cpp @@ -4,10 +4,9 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include -#include namespace Web::Bindings { @@ -31,10 +30,9 @@ JS::ThrowCompletionOr WindowConstructor::construct(FunctionObject&) void WindowConstructor::initialize(JS::Realm& realm) { auto& vm = this->vm(); - auto& window = verify_cast(realm.global_object()); NativeFunction::initialize(realm); - define_direct_property(vm.names.prototype, &window.cached_web_prototype("Window"), 0); + define_direct_property(vm.names.prototype, &cached_web_prototype(realm, "Window"), 0); define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h index 013ded9522..3562303fcd 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h @@ -6,12 +6,9 @@ #pragma once -#include #include -#include -#include +#include #include -#include namespace Web::Bindings { @@ -20,7 +17,7 @@ class WindowPrototype final : public JS::Object { public: explicit WindowPrototype(JS::Realm& realm) - : JS::Object(verify_cast(realm.global_object()).cached_web_prototype("EventTarget")) + : JS::Object(cached_web_prototype(realm, "EventTarget")) { } };