mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-27 01:50:24 +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
Notes:
sideshowbarker
2024-07-16 22:54:10 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/1defc4595b Pull-request: https://github.com/SerenityOS/serenity/pull/22376 Reviewed-by: https://github.com/awesomekling
7 changed files with 12 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue