From af75493883762b5726da825a01f5ec305a6c3e56 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 10 Jan 2023 06:56:59 -0500 Subject: [PATCH] LibWeb: Move passing of Web object prototypes out of constructors --- .../LibWeb/Bindings/LegacyPlatformObject.cpp | 4 ++-- .../LibWeb/Bindings/LegacyPlatformObject.h | 2 +- .../LibWeb/Bindings/WindowPrototype.cpp | 23 +++++++++++++++++++ .../LibWeb/Bindings/WindowPrototype.h | 8 +++---- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp | 8 ++++++- Userland/Libraries/LibWeb/CSS/CSSRuleList.h | 1 + Userland/Libraries/LibWeb/CSS/MediaList.cpp | 8 ++++++- Userland/Libraries/LibWeb/CSS/MediaList.h | 2 ++ .../Libraries/LibWeb/CSS/StyleSheetList.cpp | 8 ++++++- .../Libraries/LibWeb/CSS/StyleSheetList.h | 1 + .../Libraries/LibWeb/DOM/AbstractRange.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/AbstractRange.h | 1 + .../LibWeb/DOM/DOMImplementation.cpp | 8 ++++++- .../Libraries/LibWeb/DOM/DOMImplementation.h | 1 + .../Libraries/LibWeb/DOM/DOMTokenList.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/DOMTokenList.h | 1 + Userland/Libraries/LibWeb/DOM/Event.cpp | 10 ++++++-- Userland/Libraries/LibWeb/DOM/Event.h | 2 ++ .../Libraries/LibWeb/DOM/HTMLCollection.cpp | 8 ++++++- .../Libraries/LibWeb/DOM/HTMLCollection.h | 2 ++ .../Libraries/LibWeb/DOM/NamedNodeMap.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/NamedNodeMap.h | 1 + .../Libraries/LibWeb/DOM/NodeIterator.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/NodeIterator.h | 1 + Userland/Libraries/LibWeb/DOM/NodeList.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/NodeList.h | 2 ++ Userland/Libraries/LibWeb/DOM/TreeWalker.cpp | 8 ++++++- Userland/Libraries/LibWeb/DOM/TreeWalker.h | 1 + .../Libraries/LibWeb/FileAPI/FileList.cpp | 8 ++++++- Userland/Libraries/LibWeb/FileAPI/FileList.h | 1 + .../Libraries/LibWeb/Geometry/DOMRectList.cpp | 8 ++++++- .../Libraries/LibWeb/Geometry/DOMRectList.h | 2 ++ .../Libraries/LibWeb/HTML/DOMStringMap.cpp | 8 ++++++- Userland/Libraries/LibWeb/HTML/DOMStringMap.h | 1 + 35 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 Userland/Libraries/LibWeb/Bindings/WindowPrototype.cpp diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp index 0c6776141e..e9cc0228d9 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.cpp @@ -10,8 +10,8 @@ namespace Web::Bindings { -LegacyPlatformObject::LegacyPlatformObject(JS::Object& prototype) - : PlatformObject(prototype) +LegacyPlatformObject::LegacyPlatformObject(JS::Realm& realm) + : PlatformObject(realm) { } diff --git a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h index bf8955fb3c..eb1aa37f6c 100644 --- a/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LegacyPlatformObject.h @@ -34,7 +34,7 @@ public: virtual bool is_supported_property_index(u32) const; protected: - explicit LegacyPlatformObject(JS::Object& prototype); + explicit LegacyPlatformObject(JS::Realm& realm); }; } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.cpp b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.cpp new file mode 100644 index 0000000000..23c88d7f26 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Bindings { + +WindowPrototype::WindowPrototype(JS::Realm& realm) + : JS::Object(realm, nullptr) +{ +} + +void WindowPrototype::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "EventTarget")); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h index 495f18a18d..e26ad57d4c 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowPrototype.h @@ -16,10 +16,10 @@ class WindowPrototype final : public JS::Object { JS_OBJECT(WindowPrototype, JS::Object); public: - explicit WindowPrototype(JS::Realm& realm) - : JS::Object(ConstructWithPrototypeTag::Tag, cached_web_prototype(realm, "EventTarget")) - { - } + explicit WindowPrototype(JS::Realm& realm); + +private: + virtual void initialize(JS::Realm&) override; }; } diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 7dbbdac4f1..12c274163a 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -14,6 +14,7 @@ set(SOURCES Bindings/OptionConstructor.cpp Bindings/PlatformObject.cpp Bindings/WindowConstructor.cpp + Bindings/WindowPrototype.cpp Crypto/Crypto.cpp Crypto/SubtleCrypto.cpp CSS/Angle.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index e6a8e2f1e0..9451b6aef1 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -26,7 +26,7 @@ CSSRuleList* CSSRuleList::create(JS::Realm& realm, JS::MarkedVector co } CSSRuleList::CSSRuleList(JS::Realm& realm) - : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype(realm, "CSSRuleList")) + : Bindings::LegacyPlatformObject(realm) { } @@ -35,6 +35,12 @@ CSSRuleList* CSSRuleList::create_empty(JS::Realm& realm) return realm.heap().allocate(realm, realm); } +void CSSRuleList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "CSSRuleList")); +} + void CSSRuleList::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h index dc5537891f..af8de394c2 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h @@ -66,6 +66,7 @@ public: private: explicit CSSRuleList(JS::Realm&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; Vector m_rules; diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index 0bec469e23..ab25824513 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -18,11 +18,17 @@ MediaList* MediaList::create(JS::Realm& realm, NonnullRefPtrVector&& } MediaList::MediaList(JS::Realm& realm, NonnullRefPtrVector&& media) - : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype(realm, "MediaList")) + : Bindings::LegacyPlatformObject(realm) , m_media(move(media)) { } +void MediaList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "MediaList")); +} + // https://www.w3.org/TR/cssom-1/#dom-medialist-mediatext DeprecatedString MediaList::media_text() const { diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.h b/Userland/Libraries/LibWeb/CSS/MediaList.h index e82cb4037a..1f42ba0298 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.h +++ b/Userland/Libraries/LibWeb/CSS/MediaList.h @@ -39,6 +39,8 @@ public: private: MediaList(JS::Realm&, NonnullRefPtrVector&&); + virtual void initialize(JS::Realm&) override; + NonnullRefPtrVector m_media; }; diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp index 0a59d5552a..c31d1b30a2 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -52,11 +52,17 @@ StyleSheetList* StyleSheetList::create(DOM::Document& document) } StyleSheetList::StyleSheetList(DOM::Document& document) - : Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype(document.realm(), "StyleSheetList")) + : Bindings::LegacyPlatformObject(document.realm()) , m_document(document) { } +void StyleSheetList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "StyleSheetList")); +} + void StyleSheetList::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h index f768ba87a1..ec09052ac3 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h @@ -41,6 +41,7 @@ public: private: explicit StyleSheetList(DOM::Document&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; void sort_sheets(); diff --git a/Userland/Libraries/LibWeb/DOM/AbstractRange.cpp b/Userland/Libraries/LibWeb/DOM/AbstractRange.cpp index 084586e76a..8c22be6b1a 100644 --- a/Userland/Libraries/LibWeb/DOM/AbstractRange.cpp +++ b/Userland/Libraries/LibWeb/DOM/AbstractRange.cpp @@ -11,7 +11,7 @@ namespace Web::DOM { AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset) - : Bindings::PlatformObject(Bindings::cached_web_prototype(start_container.realm(), "AbstractRange")) + : Bindings::PlatformObject(start_container.realm()) , m_start_container(start_container) , m_start_offset(start_offset) , m_end_container(end_container) @@ -21,6 +21,12 @@ AbstractRange::AbstractRange(Node& start_container, u32 start_offset, Node& end_ AbstractRange::~AbstractRange() = default; +void AbstractRange::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "AbstractRange")); +} + void AbstractRange::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/AbstractRange.h b/Userland/Libraries/LibWeb/DOM/AbstractRange.h index badada6443..af8b04bad3 100644 --- a/Userland/Libraries/LibWeb/DOM/AbstractRange.h +++ b/Userland/Libraries/LibWeb/DOM/AbstractRange.h @@ -36,6 +36,7 @@ public: protected: AbstractRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; JS::NonnullGCPtr m_start_container; diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp index 71f0df6967..acd7a7c398 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.cpp @@ -24,13 +24,19 @@ JS::NonnullGCPtr DOMImplementation::create(Document& document } DOMImplementation::DOMImplementation(Document& document) - : PlatformObject(Bindings::cached_web_prototype(document.realm(), "DOMImplementation")) + : PlatformObject(document.realm()) , m_document(document) { } DOMImplementation::~DOMImplementation() = default; +void DOMImplementation::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "DOMImplementation")); +} + void DOMImplementation::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h index d4ea690ac3..569f650f17 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMImplementation.h +++ b/Userland/Libraries/LibWeb/DOM/DOMImplementation.h @@ -30,6 +30,7 @@ public: private: explicit DOMImplementation(Document&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; Document& document() { return m_document; } diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp index 768dc3fa57..43241d34dd 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.cpp @@ -60,7 +60,7 @@ DOMTokenList* DOMTokenList::create(Element const& associated_element, Deprecated // https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2 DOMTokenList::DOMTokenList(Element const& associated_element, DeprecatedFlyString associated_attribute) - : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(associated_element.realm(), "DOMTokenList")) + : Bindings::LegacyPlatformObject(associated_element.realm()) , m_associated_element(associated_element) , m_associated_attribute(move(associated_attribute)) { @@ -68,6 +68,12 @@ DOMTokenList::DOMTokenList(Element const& associated_element, DeprecatedFlyStrin associated_attribute_changed(value); } +void DOMTokenList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "DOMTokenList")); +} + void DOMTokenList::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/DOMTokenList.h b/Userland/Libraries/LibWeb/DOM/DOMTokenList.h index 4be3d0a2b7..62c9c6a6c7 100644 --- a/Userland/Libraries/LibWeb/DOM/DOMTokenList.h +++ b/Userland/Libraries/LibWeb/DOM/DOMTokenList.h @@ -45,6 +45,7 @@ public: private: DOMTokenList(Element const& associated_element, DeprecatedFlyString associated_attribute); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; WebIDL::ExceptionOr validate_token(StringView token) const; diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index a42a587e52..ae6e12692a 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -25,14 +25,14 @@ JS::NonnullGCPtr Event::construct_impl(JS::Realm& realm, DeprecatedFlyStr } Event::Event(JS::Realm& realm, DeprecatedFlyString const& type) - : PlatformObject(Bindings::cached_web_prototype(realm, "Event")) + : PlatformObject(realm) , m_type(type) , m_initialized(true) { } Event::Event(JS::Realm& realm, DeprecatedFlyString const& type, EventInit const& event_init) - : PlatformObject(Bindings::cached_web_prototype(realm, "Event")) + : PlatformObject(realm) , m_type(type) , m_bubbles(event_init.bubbles) , m_cancelable(event_init.cancelable) @@ -41,6 +41,12 @@ Event::Event(JS::Realm& realm, DeprecatedFlyString const& type, EventInit const& { } +void Event::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "Event")); +} + void Event::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/Event.h b/Userland/Libraries/LibWeb/DOM/Event.h index 53b8f3279c..027ebc7c1f 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.h +++ b/Userland/Libraries/LibWeb/DOM/Event.h @@ -145,6 +145,8 @@ public: protected: void initialize_event(DeprecatedString const&, bool, bool); + + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor&) override; private: diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index 0a9e03b1cc..59715879aa 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -19,7 +19,7 @@ JS::NonnullGCPtr HTMLCollection::create(ParentNode& root, Functi } HTMLCollection::HTMLCollection(ParentNode& root, Function filter) - : LegacyPlatformObject(Bindings::cached_web_prototype(root.realm(), "HTMLCollection")) + : LegacyPlatformObject(root.realm()) , m_root(root) , m_filter(move(filter)) { @@ -27,6 +27,12 @@ HTMLCollection::HTMLCollection(ParentNode& root, Function HTMLCollection::~HTMLCollection() = default; +void HTMLCollection::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "HTMLCollection")); +} + void HTMLCollection::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h index a221e6b34a..909c8c18f1 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h @@ -47,6 +47,8 @@ public: protected: HTMLCollection(ParentNode& root, Function filter); + virtual void initialize(JS::Realm&) override; + JS::NonnullGCPtr root() { return *m_root; } private: diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp index 634613a2d5..2c7ef4fb23 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.cpp @@ -20,11 +20,17 @@ JS::NonnullGCPtr NamedNodeMap::create(Element& element) } NamedNodeMap::NamedNodeMap(Element& element) - : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(element.realm(), "NamedNodeMap")) + : Bindings::LegacyPlatformObject(element.realm()) , m_element(element) { } +void NamedNodeMap::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "NamedNodeMap")); +} + void NamedNodeMap::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h index 2cb81271b1..6c64c6ca43 100644 --- a/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h +++ b/Userland/Libraries/LibWeb/DOM/NamedNodeMap.h @@ -56,6 +56,7 @@ public: private: explicit NamedNodeMap(Element&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; Element& associated_element() { return *m_element; } diff --git a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp index b9fbaa256f..642fe60e92 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp +++ b/Userland/Libraries/LibWeb/DOM/NodeIterator.cpp @@ -12,7 +12,7 @@ namespace Web::DOM { NodeIterator::NodeIterator(Node& root) - : PlatformObject(Bindings::cached_web_prototype(root.realm(), "NodeIterator")) + : PlatformObject(root.realm()) , m_root(root) , m_reference({ root }) { @@ -21,6 +21,12 @@ NodeIterator::NodeIterator(Node& root) NodeIterator::~NodeIterator() = default; +void NodeIterator::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "NodeIterator")); +} + void NodeIterator::finalize() { Base::finalize(); diff --git a/Userland/Libraries/LibWeb/DOM/NodeIterator.h b/Userland/Libraries/LibWeb/DOM/NodeIterator.h index 876e77c1c6..0186bc78a0 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeIterator.h +++ b/Userland/Libraries/LibWeb/DOM/NodeIterator.h @@ -37,6 +37,7 @@ public: private: explicit NodeIterator(Node& root); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; virtual void finalize() override; diff --git a/Userland/Libraries/LibWeb/DOM/NodeList.cpp b/Userland/Libraries/LibWeb/DOM/NodeList.cpp index ed866d2c63..b1a5c6bb97 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/NodeList.cpp @@ -11,12 +11,18 @@ namespace Web::DOM { NodeList::NodeList(JS::Realm& realm) - : LegacyPlatformObject(Bindings::cached_web_prototype(realm, "NodeList")) + : LegacyPlatformObject(realm) { } NodeList::~NodeList() = default; +void NodeList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "NodeList")); +} + JS::Value NodeList::item_value(size_t index) const { auto* node = item(index); diff --git a/Userland/Libraries/LibWeb/DOM/NodeList.h b/Userland/Libraries/LibWeb/DOM/NodeList.h index 9e8327f30b..70c87a270f 100644 --- a/Userland/Libraries/LibWeb/DOM/NodeList.h +++ b/Userland/Libraries/LibWeb/DOM/NodeList.h @@ -26,6 +26,8 @@ public: protected: explicit NodeList(JS::Realm&); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp index fbaa0245eb..419cd7fd80 100644 --- a/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp +++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.cpp @@ -14,7 +14,7 @@ namespace Web::DOM { TreeWalker::TreeWalker(Node& root) - : PlatformObject(Bindings::cached_web_prototype(root.realm(), "TreeWalker")) + : PlatformObject(root.realm()) , m_root(root) , m_current(root) { @@ -22,6 +22,12 @@ TreeWalker::TreeWalker(Node& root) TreeWalker::~TreeWalker() = default; +void TreeWalker::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "TreeWalker")); +} + void TreeWalker::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/TreeWalker.h b/Userland/Libraries/LibWeb/DOM/TreeWalker.h index 4e43535e34..6281bfc108 100644 --- a/Userland/Libraries/LibWeb/DOM/TreeWalker.h +++ b/Userland/Libraries/LibWeb/DOM/TreeWalker.h @@ -39,6 +39,7 @@ public: private: explicit TreeWalker(Node& root); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; enum class ChildTraversalType { diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp index 248a1234c0..d0eb3bad21 100644 --- a/Userland/Libraries/LibWeb/FileAPI/FileList.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/FileList.cpp @@ -17,13 +17,19 @@ JS::NonnullGCPtr FileList::create(JS::Realm& realm, Vector>&& files) - : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(realm, "FileList")) + : Bindings::LegacyPlatformObject(realm) , m_files(move(files)) { } FileList::~FileList() = default; +void FileList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "FileList")); +} + // https://w3c.github.io/FileAPI/#dfn-item bool FileList::is_supported_property_index(u32 index) const { diff --git a/Userland/Libraries/LibWeb/FileAPI/FileList.h b/Userland/Libraries/LibWeb/FileAPI/FileList.h index 82f4a989cf..8b049dc791 100644 --- a/Userland/Libraries/LibWeb/FileAPI/FileList.h +++ b/Userland/Libraries/LibWeb/FileAPI/FileList.h @@ -35,6 +35,7 @@ public: private: FileList(JS::Realm&, Vector>&&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; Vector> m_files; diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp index 9dbf69dd14..ece3ce8a06 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp @@ -20,13 +20,19 @@ JS::NonnullGCPtr DOMRectList::create(JS::Realm& realm, Vector> rects) - : Bindings::LegacyPlatformObject(Bindings::cached_web_prototype(realm, "DOMRectList")) + : Bindings::LegacyPlatformObject(realm) , m_rects(move(rects)) { } DOMRectList::~DOMRectList() = default; +void DOMRectList::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "DOMRectList")); +} + // https://drafts.fxtf.org/geometry-1/#dom-domrectlist-length u32 DOMRectList::length() const { diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h index 0eaccfcee9..cc98b0e284 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h @@ -30,6 +30,8 @@ public: private: DOMRectList(JS::Realm&, Vector>); + virtual void initialize(JS::Realm&) override; + Vector> m_rects; }; diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp index a9b2f6b503..271ba6160a 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp @@ -19,13 +19,19 @@ JS::NonnullGCPtr DOMStringMap::create(DOM::Element& element) } DOMStringMap::DOMStringMap(DOM::Element& element) - : LegacyPlatformObject(Bindings::cached_web_prototype(element.realm(), "DOMStringMap")) + : LegacyPlatformObject(element.realm()) , m_associated_element(element) { } DOMStringMap::~DOMStringMap() = default; +void DOMStringMap::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "DOMStringMap")); +} + void DOMStringMap::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h index c8d12cab72..5b77c072f0 100644 --- a/Userland/Libraries/LibWeb/HTML/DOMStringMap.h +++ b/Userland/Libraries/LibWeb/HTML/DOMStringMap.h @@ -31,6 +31,7 @@ public: private: explicit DOMStringMap(DOM::Element&); + virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; // ^LegacyPlatformObject