LibWeb: Make LiveNodeList store a NonnullGCPtr<Node const> root

This allows us to improve the const-correctness in RadioNodeList, which
has been made possible as of: 5f0ccfb499 now that a GC-visit accepts a
const GC pointer.
This commit is contained in:
Shannon Booth 2023-12-21 22:36:37 +13:00 committed by Andreas Kling
parent 0a7e4a0d22
commit 1defc4595b
Notes: sideshowbarker 2024-07-16 22:54:10 +09:00
7 changed files with 12 additions and 11 deletions

View file

@ -55,6 +55,7 @@ protected:
virtual void initialize(JS::Realm&) override;
JS::NonnullGCPtr<ParentNode> root() { return *m_root; }
JS::NonnullGCPtr<ParentNode const> root() const { return *m_root; }
private:
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -33,7 +33,7 @@ void HTMLFormControlsCollection::initialize(JS::Realm& realm)
}
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlformcontrolscollection-nameditem
Variant<Empty, Element*, JS::Handle<RadioNodeList>> HTMLFormControlsCollection::named_item_or_radio_node_list(FlyString const& name)
Variant<Empty, Element*, JS::Handle<RadioNodeList>> 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())

View file

@ -20,7 +20,7 @@ public:
virtual ~HTMLFormControlsCollection() override;
Variant<Empty, Element*, JS::Handle<RadioNodeList>> named_item_or_radio_node_list(FlyString const& name);
Variant<Empty, Element*, JS::Handle<RadioNodeList>> named_item_or_radio_node_list(FlyString const& name) const;
protected:
virtual void initialize(JS::Realm&) override;

View file

@ -14,12 +14,12 @@ namespace Web::DOM {
JS_DEFINE_ALLOCATOR(LiveNodeList);
JS::NonnullGCPtr<NodeList> LiveNodeList::create(JS::Realm& realm, Node& root, Scope scope, Function<bool(Node const&)> filter)
JS::NonnullGCPtr<NodeList> LiveNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)
{
return realm.heap().allocate<LiveNodeList>(realm, realm, root, scope, move(filter));
}
LiveNodeList::LiveNodeList(JS::Realm& realm, Node& root, Scope scope, Function<bool(Node const&)> filter)
LiveNodeList::LiveNodeList(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)
: NodeList(realm)
, m_root(root)
, m_filter(move(filter))

View file

@ -24,7 +24,7 @@ public:
Descendants,
};
[[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node& root, Scope, Function<bool(Node const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<NodeList> create(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> 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<bool(Node const&)> filter);
LiveNodeList(JS::Realm&, Node const& root, Scope, Function<bool(Node const&)> filter);
Node* first_matching(Function<bool(Node const&)> const& filter) const;
@ -42,7 +42,7 @@ private:
JS::MarkedVector<Node*> collection() const;
JS::NonnullGCPtr<Node> m_root;
JS::NonnullGCPtr<Node const> m_root;
Function<bool(Node const&)> m_filter;
Scope m_scope { Scope::Descendants };
};

View file

@ -14,12 +14,12 @@ namespace Web::DOM {
JS_DEFINE_ALLOCATOR(RadioNodeList);
JS::NonnullGCPtr<RadioNodeList> RadioNodeList::create(JS::Realm& realm, Node& root, Scope scope, Function<bool(Node const&)> filter)
JS::NonnullGCPtr<RadioNodeList> RadioNodeList::create(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)
{
return realm.heap().allocate<RadioNodeList>(realm, realm, root, scope, move(filter));
}
RadioNodeList::RadioNodeList(JS::Realm& realm, Node& root, Scope scope, Function<bool(Node const&)> filter)
RadioNodeList::RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter)
: LiveNodeList(realm, root, scope, move(filter))
{
}

View file

@ -16,7 +16,7 @@ class RadioNodeList : public LiveNodeList {
JS_DECLARE_ALLOCATOR(RadioNodeList);
public:
[[nodiscard]] static JS::NonnullGCPtr<RadioNodeList> create(JS::Realm& realm, Node& root, Scope scope, Function<bool(Node const&)> filter);
[[nodiscard]] static JS::NonnullGCPtr<RadioNodeList> create(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> 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<bool(Node const&)> filter);
explicit RadioNodeList(JS::Realm& realm, Node const& root, Scope scope, Function<bool(Node const&)> filter);
};
}