mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:12:08 +00:00
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:
parent
0a7e4a0d22
commit
1defc4595b
7 changed files with 12 additions and 11 deletions
|
@ -55,6 +55,7 @@ protected:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
JS::NonnullGCPtr<ParentNode> root() { return *m_root; }
|
JS::NonnullGCPtr<ParentNode> root() { return *m_root; }
|
||||||
|
JS::NonnullGCPtr<ParentNode const> root() const { return *m_root; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
|
@ -33,7 +33,7 @@ void HTMLFormControlsCollection::initialize(JS::Realm& realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlformcontrolscollection-nameditem
|
// 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.
|
// 1. If name is the empty string, return null and stop the algorithm.
|
||||||
if (name.is_empty())
|
if (name.is_empty())
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
|
|
||||||
virtual ~HTMLFormControlsCollection() override;
|
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:
|
protected:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
|
@ -14,12 +14,12 @@ namespace Web::DOM {
|
||||||
|
|
||||||
JS_DEFINE_ALLOCATOR(LiveNodeList);
|
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));
|
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)
|
: NodeList(realm)
|
||||||
, m_root(root)
|
, m_root(root)
|
||||||
, m_filter(move(filter))
|
, m_filter(move(filter))
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
Descendants,
|
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 ~LiveNodeList() override;
|
||||||
|
|
||||||
virtual u32 length() const override;
|
virtual u32 length() const override;
|
||||||
|
@ -33,7 +33,7 @@ public:
|
||||||
virtual bool is_supported_property_index(u32) const override;
|
virtual bool is_supported_property_index(u32) const override;
|
||||||
|
|
||||||
protected:
|
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;
|
Node* first_matching(Function<bool(Node const&)> const& filter) const;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ private:
|
||||||
|
|
||||||
JS::MarkedVector<Node*> collection() const;
|
JS::MarkedVector<Node*> collection() const;
|
||||||
|
|
||||||
JS::NonnullGCPtr<Node> m_root;
|
JS::NonnullGCPtr<Node const> m_root;
|
||||||
Function<bool(Node const&)> m_filter;
|
Function<bool(Node const&)> m_filter;
|
||||||
Scope m_scope { Scope::Descendants };
|
Scope m_scope { Scope::Descendants };
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,12 +14,12 @@ namespace Web::DOM {
|
||||||
|
|
||||||
JS_DEFINE_ALLOCATOR(RadioNodeList);
|
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));
|
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))
|
: LiveNodeList(realm, root, scope, move(filter))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class RadioNodeList : public LiveNodeList {
|
||||||
JS_DECLARE_ALLOCATOR(RadioNodeList);
|
JS_DECLARE_ALLOCATOR(RadioNodeList);
|
||||||
|
|
||||||
public:
|
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;
|
virtual ~RadioNodeList() override;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ protected:
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
private:
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue