From 1defc4595b1994cbddd3d7bcec6a641ea416e206 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 21 Dec 2023 22:36:37 +1300 Subject: [PATCH] LibWeb: Make LiveNodeList store a NonnullGCPtr root This allows us to improve the const-correctness in RadioNodeList, which has been made possible as of: 5f0ccfb4993 now that a GC-visit accepts a const GC pointer. --- Userland/Libraries/LibWeb/DOM/HTMLCollection.h | 1 + .../Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp | 2 +- Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h | 2 +- Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp | 4 ++-- Userland/Libraries/LibWeb/DOM/LiveNodeList.h | 6 +++--- Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp | 4 ++-- Userland/Libraries/LibWeb/DOM/RadioNodeList.h | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h index 803b9157db8..c18dd7bc97d 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h @@ -55,6 +55,7 @@ protected: virtual void initialize(JS::Realm&) override; JS::NonnullGCPtr root() { return *m_root; } + JS::NonnullGCPtr root() const { return *m_root; } private: virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp index 47642e6f096..42e4f2cf8ee 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp @@ -33,7 +33,7 @@ void HTMLFormControlsCollection::initialize(JS::Realm& realm) } // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlformcontrolscollection-nameditem -Variant> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) +Variant> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name) const { // 1. If name is the empty string, return null and stop the algorithm. if (name.is_empty()) diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h index aa20f0c540a..aba67236f7c 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.h @@ -20,7 +20,7 @@ public: virtual ~HTMLFormControlsCollection() override; - Variant> named_item_or_radio_node_list(FlyString const& name); + Variant> named_item_or_radio_node_list(FlyString const& name) const; protected: virtual void initialize(JS::Realm&) override; diff --git a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp index 10b6169ab61..c03ba4ec183 100644 --- a/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/LiveNodeList.cpp @@ -14,12 +14,12 @@ namespace Web::DOM { JS_DEFINE_ALLOCATOR(LiveNodeList); -JS::NonnullGCPtr LiveNodeList::create(JS::Realm& realm, Node& root, Scope scope, Function filter) +JS::NonnullGCPtr LiveNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function filter) { return realm.heap().allocate(realm, realm, root, scope, move(filter)); } -LiveNodeList::LiveNodeList(JS::Realm& realm, Node& root, Scope scope, Function filter) +LiveNodeList::LiveNodeList(JS::Realm& realm, Node const& root, Scope scope, Function filter) : NodeList(realm) , m_root(root) , m_filter(move(filter)) diff --git a/Userland/Libraries/LibWeb/DOM/LiveNodeList.h b/Userland/Libraries/LibWeb/DOM/LiveNodeList.h index 99de8533f46..4084c16a5eb 100644 --- a/Userland/Libraries/LibWeb/DOM/LiveNodeList.h +++ b/Userland/Libraries/LibWeb/DOM/LiveNodeList.h @@ -24,7 +24,7 @@ public: Descendants, }; - [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Node& root, Scope, Function filter); + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, Node const& root, Scope, Function filter); virtual ~LiveNodeList() override; virtual u32 length() const override; @@ -33,7 +33,7 @@ public: virtual bool is_supported_property_index(u32) const override; protected: - LiveNodeList(JS::Realm&, Node& root, Scope, Function filter); + LiveNodeList(JS::Realm&, Node const& root, Scope, Function filter); Node* first_matching(Function const& filter) const; @@ -42,7 +42,7 @@ private: JS::MarkedVector collection() const; - JS::NonnullGCPtr m_root; + JS::NonnullGCPtr m_root; Function m_filter; Scope m_scope { Scope::Descendants }; }; diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp b/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp index 56e29f996d8..24b563dab5a 100644 --- a/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp +++ b/Userland/Libraries/LibWeb/DOM/RadioNodeList.cpp @@ -14,12 +14,12 @@ namespace Web::DOM { JS_DEFINE_ALLOCATOR(RadioNodeList); -JS::NonnullGCPtr RadioNodeList::create(JS::Realm& realm, Node& root, Scope scope, Function filter) +JS::NonnullGCPtr RadioNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function filter) { return realm.heap().allocate(realm, realm, root, scope, move(filter)); } -RadioNodeList::RadioNodeList(JS::Realm& realm, Node& root, Scope scope, Function filter) +RadioNodeList::RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function filter) : LiveNodeList(realm, root, scope, move(filter)) { } diff --git a/Userland/Libraries/LibWeb/DOM/RadioNodeList.h b/Userland/Libraries/LibWeb/DOM/RadioNodeList.h index bcf1991b5f8..ab7ecf548b4 100644 --- a/Userland/Libraries/LibWeb/DOM/RadioNodeList.h +++ b/Userland/Libraries/LibWeb/DOM/RadioNodeList.h @@ -16,7 +16,7 @@ class RadioNodeList : public LiveNodeList { JS_DECLARE_ALLOCATOR(RadioNodeList); public: - [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm, Node& root, Scope scope, Function filter); + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm& realm, Node const& root, Scope scope, Function filter); virtual ~RadioNodeList() override; @@ -27,7 +27,7 @@ protected: virtual void initialize(JS::Realm&) override; private: - explicit RadioNodeList(JS::Realm& realm, Node& root, Scope scope, Function filter); + explicit RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function filter); }; }