Skip to content

Truly independent web browser

LibWeb: Keep the filters of live collections in GC::Functions

Andreas Klingcccd89d5f553
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index d9572a7c019..18cd81ddd44 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -3762,19 +3762,19 @@ void Document::dispatch_boundary_events(GC::Ptr<Node> old_hovered_node, GC::Ptr<
GC::Ref<NodeList> Document::get_elements_by_name(Utf16View name)
{
auto name_copy = Utf16String::from_utf16(name);
- return LiveNodeList::create(*this, LiveNodeList::Scope::Descendants, [name = move(name_copy)](auto const& node) {
+ return LiveNodeList::create(*this, LiveNodeList::Scope::Descendants, GC::create_function(heap(), GC::captures(move(name_copy)), [](auto const& name, Node const& node) {
if (!is<HTML::HTMLElement>(node))
return false;
auto element_name = as<DOM::Element>(node).get_attribute(HTML::AttributeNames::name);
return element_name.has_value() && !element_name->is_empty() && element_name->utf16_view() == name.utf16_view();
- });
+ }));
}
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
GC::Ref<HTMLCollection> Document::applets()
{
if (!m_applets)
- m_applets = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](auto&) { return false; }, HTMLCollection::AttributeInvalidationType::None);
+ m_applets = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const&) { return false; }), HTMLCollection::AttributeInvalidationType::None);
return *m_applets;
}
@@ -3782,7 +3782,7 @@ GC::Ref<HTMLCollection> Document::applets()
GC::Ref<HTMLCollection> Document::anchors()
{
if (!m_anchors) {
- m_anchors = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLAnchorElement>(element) && element.name().has_value(); }, HTMLCollection::AttributeInvalidationType::Name);
+ m_anchors = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLAnchorElement>(element) && element.name().has_value(); }), HTMLCollection::AttributeInvalidationType::Name);
}
return *m_anchors;
}
@@ -3791,7 +3791,7 @@ GC::Ref<HTMLCollection> Document::anchors()
GC::Ref<HTMLCollection> Document::images()
{
if (!m_images) {
- m_images = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLImageElement>(element); }, HTMLCollection::AttributeInvalidationType::None);
+ m_images = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLImageElement>(element); }), HTMLCollection::AttributeInvalidationType::None);
}
return *m_images;
}
@@ -3800,7 +3800,7 @@ GC::Ref<HTMLCollection> Document::images()
GC::Ref<HTMLCollection> Document::embeds()
{
if (!m_embeds) {
- m_embeds = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLEmbedElement>(element); }, HTMLCollection::AttributeInvalidationType::None);
+ m_embeds = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLEmbedElement>(element); }), HTMLCollection::AttributeInvalidationType::None);
}
return *m_embeds;
}
@@ -3815,7 +3815,7 @@ GC::Ref<HTMLCollection> Document::plugins()
GC::Ref<HTMLCollection> Document::links()
{
if (!m_links) {
- m_links = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href); }, HTMLCollection::AttributeInvalidationType::Href);
+ m_links = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href); }), HTMLCollection::AttributeInvalidationType::Href);
}
return *m_links;
}
@@ -3824,7 +3824,7 @@ GC::Ref<HTMLCollection> Document::links()
GC::Ref<HTMLCollection> Document::forms()
{
if (!m_forms) {
- m_forms = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLFormElement>(element); }, HTMLCollection::AttributeInvalidationType::None);
+ m_forms = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLFormElement>(element); }), HTMLCollection::AttributeInvalidationType::None);
}
return *m_forms;
}
@@ -3833,7 +3833,7 @@ GC::Ref<HTMLCollection> Document::forms()
GC::Ref<HTMLCollection> Document::scripts()
{
if (!m_scripts) {
- m_scripts = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLScriptElement>(element); }, HTMLCollection::AttributeInvalidationType::None);
+ m_scripts = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLScriptElement>(element); }), HTMLCollection::AttributeInvalidationType::None);
}
return *m_scripts;
}
@@ -6404,10 +6404,10 @@ void Document::check_favicon_after_loading_link_resource()
if (!head_element)
return;
- auto favicon_link_elements = HTMLCollection::create(*head_element, HTMLCollection::Scope::Descendants, [](Element const& element) {
+ auto favicon_link_elements = HTMLCollection::create(*head_element, HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) {
if (auto const* link_element = as_if<HTML::HTMLLinkElement>(element))
return link_element->has_loaded_icon();
- return false; }, HTMLCollection::AttributeInvalidationType::None);
+ return false; }), HTMLCollection::AttributeInvalidationType::None);
if (favicon_link_elements->length() == 0) {
dbgln_if(SPAM_DEBUG, "No favicon found to be used");
@@ -13479,7 +13479,7 @@ JS::Value document_named_item_value(WrapperWorld& wrapper_world, JS::Realm& real
return wrap(wrapper_world, realm, elements.first()).ptr();
// 4. Otherwise return an HTMLCollection rooted at the Document node, whose filter matches only named elements with the name name.
- auto collection = DOM::HTMLCollection::create(*const_cast<DOM::Document*>(&document), DOM::HTMLCollection::Scope::Descendants, [name](auto& element) { return DOM::Document::is_named_element_with_name(element, name); }, DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
+ auto collection = DOM::HTMLCollection::create(*const_cast<DOM::Document*>(&document), DOM::HTMLCollection::Scope::Descendants, GC::create_function(document.heap(), GC::captures(name), [](auto const& name, DOM::Element const& element) { return DOM::Document::is_named_element_with_name(element, name); }), DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
return wrap(wrapper_world, realm, collection);
}
diff --git a/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Libraries/LibWeb/DOM/HTMLCollection.cpp
index ab1dad2c61e..be76af6727a 100644
--- a/Libraries/LibWeb/DOM/HTMLCollection.cpp
+++ b/Libraries/LibWeb/DOM/HTMLCollection.cpp
@@ -19,16 +19,16 @@ namespace Web::DOM {
GC_DEFINE_ALLOCATOR(HTMLCollection);
-GC::Ref<HTMLCollection> HTMLCollection::create(ParentNode& root, Scope scope, Function<bool(Element const&)> filter, AttributeInvalidationType attribute_invalidation_type, Function<bool(Element const&, Element const&)> sort, Kind kind)
+GC::Ref<HTMLCollection> HTMLCollection::create(ParentNode& root, Scope scope, Filter filter, AttributeInvalidationType attribute_invalidation_type, Sort sort, Kind kind)
{
- return GC::Heap::the().allocate<HTMLCollection>(root, scope, move(filter), attribute_invalidation_type, move(sort), kind);
+ return GC::Heap::the().allocate<HTMLCollection>(root, scope, filter, attribute_invalidation_type, sort, kind);
}
-HTMLCollection::HTMLCollection(ParentNode& root, Scope scope, Function<bool(Element const&)> filter, AttributeInvalidationType attribute_invalidation_type, Function<bool(Element const&, Element const&)> sort, Kind kind)
+HTMLCollection::HTMLCollection(ParentNode& root, Scope scope, Filter filter, AttributeInvalidationType attribute_invalidation_type, Sort sort, Kind kind)
: GC::WeakContainer(heap())
, m_root(root)
- , m_filter(move(filter))
- , m_sort(move(sort))
+ , m_filter(filter)
+ , m_sort(sort)
, m_cache_registration(*this)
, m_scope(scope)
, m_kind(kind)
@@ -48,8 +48,8 @@ void HTMLCollection::visit_edges(GC::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_root);
- visitor.visit_possible_values(m_filter.raw_capture_range());
- visitor.visit_possible_values(m_sort.raw_capture_range());
+ visitor.visit(m_filter);
+ visitor.visit(m_sort);
}
GC::Cell const& HTMLCollection::owner_cell(Badge<GC::Heap>) const
@@ -98,13 +98,13 @@ void HTMLCollection::collect_elements_into(Vector<GC::RawPtr<Element>>& elements
{
if (m_scope == Scope::Descendants) {
m_root->for_each_in_subtree_of_type<Element>([&](auto& element) {
- if (m_filter(element))
+ if ((*m_filter)(element))
elements.append(element);
return TraversalDecision::Continue;
});
} else {
m_root->for_each_child_of_type<Element>([&](auto& element) {
- if (m_filter(element))
+ if ((*m_filter)(element))
elements.append(element);
return IterationDecision::Continue;
});
@@ -130,7 +130,7 @@ void HTMLCollection::update_cache_if_needed() const
if (m_sort) {
insertion_sort(m_cached_elements, [this](auto const& a, auto const& b) {
- return this->m_sort(*a, *b);
+ return (*this->m_sort)(*a, *b);
});
}
@@ -190,7 +190,7 @@ void HTMLCollection::invalidate_cache_for_attribute_change(Element const& elemen
// OPTIMIZATION: The cache still records whether the element matched before the attribute
// change. Keep the element vector when reevaluating the filter produces the same result.
bool was_matching = m_cached_elements.contains([&](auto const& cached_element) { return cached_element.ptr() == &element; });
- if (was_matching != m_filter(element)) {
+ if (was_matching != (*m_filter)(element)) {
invalidate_cache();
return;
}
diff --git a/Libraries/LibWeb/DOM/HTMLCollection.h b/Libraries/LibWeb/DOM/HTMLCollection.h
index bb01fe29e84..04d75f0821e 100644
--- a/Libraries/LibWeb/DOM/HTMLCollection.h
+++ b/Libraries/LibWeb/DOM/HTMLCollection.h
@@ -7,7 +7,7 @@
#pragma once
-#include <AK/Function.h>
+#include <LibGC/Function.h>
#include <LibGC/Ptr.h>
#include <LibGC/Weak.h>
#include <LibGC/WeakContainer.h>
@@ -51,7 +51,10 @@ public:
using AttributeInvalidationType = HTMLCollectionCacheRegistration::AttributeInvalidationType;
using AttributeInvalidationTypes = HTMLCollectionCacheRegistration::AttributeInvalidationTypes;
- [[nodiscard]] static GC::Ref<HTMLCollection> create(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter, AttributeInvalidationType, ESCAPING Function<bool(Element const&, Element const&)> sort = nullptr, Kind = Kind::Generic);
+ using Filter = GC::Ref<GC::Function<bool(Element const&)>>;
+ using Sort = GC::Ptr<GC::Function<bool(Element const&, Element const&)>>;
+
+ [[nodiscard]] static GC::Ref<HTMLCollection> create(ParentNode& root, Scope, Filter, AttributeInvalidationType, Sort = nullptr, Kind = Kind::Generic);
virtual ~HTMLCollection() override;
@@ -65,11 +68,11 @@ public:
virtual bool is_supported_property_name(Utf16FlyString const&) const override;
protected:
- HTMLCollection(ParentNode& root, Scope, ESCAPING Function<bool(Element const&)> filter, AttributeInvalidationType, ESCAPING Function<bool(Element const&, Element const&)> sort = nullptr, Kind = Kind::Generic);
+ HTMLCollection(ParentNode& root, Scope, Filter, AttributeInvalidationType, Sort = nullptr, Kind = Kind::Generic);
GC::Ref<ParentNode> root() { return *m_root; }
GC::Ref<ParentNode const> root() const { return *m_root; }
- bool element_matches_filter(Element const& element) const { return m_filter(element); }
+ bool element_matches_filter(Element const& element) const { return (*m_filter)(element); }
virtual void collect_elements_into(Vector<GC::RawPtr<Element>>&) const;
@@ -100,8 +103,8 @@ private:
mutable OwnPtr<OrderedHashMap<Utf16FlyString, GC::RawPtr<Element>>> m_cached_name_to_element_mappings;
GC::Ref<ParentNode> m_root;
- Function<bool(Element const&)> m_filter;
- Function<bool(Element const&, Element const&)> m_sort;
+ Filter m_filter;
+ Sort m_sort;
mutable HTMLCollectionCacheRegistration m_cache_registration;
diff --git a/Libraries/LibWeb/DOM/LiveNodeList.cpp b/Libraries/LibWeb/DOM/LiveNodeList.cpp
index 5df1c965f59..0e95d1b6bac 100644
--- a/Libraries/LibWeb/DOM/LiveNodeList.cpp
+++ b/Libraries/LibWeb/DOM/LiveNodeList.cpp
@@ -16,16 +16,16 @@ namespace Web::DOM {
GC_DEFINE_ALLOCATOR(LiveNodeList);
-GC::Ref<NodeList> LiveNodeList::create(Node const& root, Scope scope, Function<bool(Node const&)> filter, Kind kind)
+GC::Ref<NodeList> LiveNodeList::create(Node const& root, Scope scope, Filter filter, Kind kind)
{
- return GC::Heap::the().allocate<LiveNodeList>(root, scope, move(filter), kind);
+ return GC::Heap::the().allocate<LiveNodeList>(root, scope, filter, kind);
}
-LiveNodeList::LiveNodeList(Node const& root, Scope scope, Function<bool(Node const&)> filter, Kind kind)
+LiveNodeList::LiveNodeList(Node const& root, Scope scope, Filter filter, Kind kind)
: NodeList()
, GC::WeakContainer(heap())
, m_root(root)
- , m_filter(move(filter))
+ , m_filter(filter)
, m_scope(scope)
, m_kind(kind)
{
@@ -37,7 +37,7 @@ void LiveNodeList::visit_edges(GC::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_root);
- visitor.visit_possible_values(m_filter.raw_capture_range());
+ visitor.visit(m_filter);
}
GC::Cell const& LiveNodeList::owner_cell(Badge<GC::Heap>) const
@@ -66,13 +66,13 @@ void LiveNodeList::update_cache_if_needed() const
m_cached_nodes.clear_with_capacity();
if (m_scope == Scope::Descendants) {
m_root->for_each_in_subtree([&](auto& node) {
- if (m_filter(node))
+ if ((*m_filter)(node))
m_cached_nodes.append(const_cast<Node&>(node));
return TraversalDecision::Continue;
});
} else {
m_root->for_each_child([&](auto& node) {
- if (m_filter(node))
+ if ((*m_filter)(node))
m_cached_nodes.append(const_cast<Node&>(node));
return IterationDecision::Continue;
});
diff --git a/Libraries/LibWeb/DOM/LiveNodeList.h b/Libraries/LibWeb/DOM/LiveNodeList.h
index 8707a2e71d8..74465f5fe3b 100644
--- a/Libraries/LibWeb/DOM/LiveNodeList.h
+++ b/Libraries/LibWeb/DOM/LiveNodeList.h
@@ -8,6 +8,7 @@
#pragma once
#include <AK/Function.h>
+#include <LibGC/Function.h>
#include <LibGC/Weak.h>
#include <LibGC/WeakContainer.h>
#include <LibWeb/DOM/NodeList.h>
@@ -34,14 +35,16 @@ public:
FormControls,
};
- [[nodiscard]] static GC::Ref<NodeList> create(Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter, Kind = Kind::Generic);
+ using Filter = GC::Ref<GC::Function<bool(Node const&)>>;
+
+ [[nodiscard]] static GC::Ref<NodeList> create(Node const& root, Scope, Filter, Kind = Kind::Generic);
virtual ~LiveNodeList() override;
virtual u32 length() const override;
virtual Node const* item(u32 index) const override;
protected:
- LiveNodeList(Node const& root, Scope, ESCAPING Function<bool(Node const&)> filter, Kind = Kind::Generic);
+ LiveNodeList(Node const& root, Scope, Filter, Kind = Kind::Generic);
Node* first_matching(Function<bool(Node const&)> const& filter) const;
@@ -59,7 +62,7 @@ private:
mutable Vector<GC::RawPtr<Node>> m_cached_nodes;
GC::Ref<Node const> m_root;
- Function<bool(Node const&)> m_filter;
+ Filter m_filter;
Scope m_scope { Scope::Descendants };
Kind m_kind { Kind::Generic };
};
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 42e82b66d3e..f6670e3cbb2 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -3048,9 +3048,9 @@ GC::Ref<NodeList> Node::child_nodes()
{
auto& child_nodes = ensure_rare_data().child_nodes;
if (!child_nodes) {
- child_nodes = LiveNodeList::create(*this, LiveNodeList::Scope::Children, [](auto&) {
+ child_nodes = LiveNodeList::create(*this, LiveNodeList::Scope::Children, GC::create_function(heap(), [](Node const&) {
return true;
- });
+ }));
}
return *child_nodes;
}
diff --git a/Libraries/LibWeb/DOM/ParentNode.cpp b/Libraries/LibWeb/DOM/ParentNode.cpp
index 893f59f0943..bf16cca1720 100644
--- a/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -85,7 +85,7 @@ GC::Ref<HTMLCollection> ParentNode::children()
// The children getter steps are to return an HTMLCollection collection rooted at this matching only element children.
auto& children = ensure_rare_data().children;
if (!children) {
- children = HTMLCollection::create(*this, HTMLCollection::Scope::Children, [](Element const&) { return true; }, HTMLCollection::AttributeInvalidationType::None);
+ children = HTMLCollection::create(*this, HTMLCollection::Scope::Children, GC::create_function(heap(), [](Element const&) { return true; }), HTMLCollection::AttributeInvalidationType::None);
}
return *children;
}
@@ -123,23 +123,23 @@ GC::Ref<HTMLCollection> ParentNode::create_elements_by_tag_name_collection(Utf16
{
// 1. If qualifiedName is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches only descendant elements.
if (qualified_name == u"*"sv) {
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const&) { return true; }, HTMLCollection::AttributeInvalidationType::None);
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), [](Element const&) { return true; }), HTMLCollection::AttributeInvalidationType::None);
}
// 2. Otherwise, if root’s node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements:
if (root().document().document_type() == Document::Type::HTML) {
auto lowercase_qualified_name = qualified_name.to_ascii_lowercase();
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name, lowercase_qualified_name = move(lowercase_qualified_name)](Element const& element) {
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(qualified_name, move(lowercase_qualified_name)), [](auto const& qualified_name, auto const& lowercase_qualified_name, Element const& element) {
// - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase.
if (element.namespace_uri() == Namespace::HTML)
return element.qualified_name() == lowercase_qualified_name;
// - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.
- return element.qualified_name() == qualified_name; }, HTMLCollection::AttributeInvalidationType::None);
+ return element.qualified_name() == qualified_name; }), HTMLCollection::AttributeInvalidationType::None);
}
// 3. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose qualified name is qualifiedName.
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name](Element const& element) { return element.qualified_name() == qualified_name; }, HTMLCollection::AttributeInvalidationType::None);
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(qualified_name), [](auto const& qualified_name, Element const& element) { return element.qualified_name() == qualified_name; }), HTMLCollection::AttributeInvalidationType::None);
}
// https://dom.spec.whatwg.org/#concept-getelementsbytagnamens
@@ -152,30 +152,30 @@ GC::Ref<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(Optional<Utf16Fl
// 2. If both namespace and localName are "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements.
if (namespace_ == u"*"sv && local_name == u"*"sv) {
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const&) { return true; }, HTMLCollection::AttributeInvalidationType::None);
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), [](Element const&) { return true; }), HTMLCollection::AttributeInvalidationType::None);
}
// 3. Otherwise, if namespace is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements whose local name is localName.
if (namespace_ == u"*"sv) {
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [local_name](Element const& element) { return element.local_name().view() == local_name.view(); }, HTMLCollection::AttributeInvalidationType::None);
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(local_name), [](auto const& local_name, Element const& element) { return element.local_name().view() == local_name.view(); }), HTMLCollection::AttributeInvalidationType::None);
}
// 4. Otherwise, if localName is "*" (U+002A), return a HTMLCollection rooted at root, whose filter matches descendant elements whose namespace is namespace.
if (local_name == u"*"sv) {
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [namespace_](Element const& element) {
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(namespace_), [](auto const& namespace_, Element const& element) {
auto element_namespace = element.namespace_uri();
if (element_namespace.has_value() != namespace_.has_value())
return false;
- return !namespace_.has_value() || element_namespace->view() == namespace_->view(); }, HTMLCollection::AttributeInvalidationType::None);
+ return !namespace_.has_value() || element_namespace->view() == namespace_->view(); }), HTMLCollection::AttributeInvalidationType::None);
}
// 5. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose namespace is namespace and local name is localName.
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [namespace_, local_name](Element const& element) {
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(namespace_, local_name), [](auto const& namespace_, auto const& local_name, Element const& element) {
auto element_namespace = element.namespace_uri();
if (element_namespace.has_value() != namespace_.has_value())
return false;
return (!namespace_.has_value() || element_namespace->view() == namespace_->view())
- && element.local_name().view() == local_name.view(); }, HTMLCollection::AttributeInvalidationType::None);
+ && element.local_name().view() == local_name.view(); }), HTMLCollection::AttributeInvalidationType::None);
}
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
@@ -281,12 +281,12 @@ GC::Ref<HTMLCollection> ParentNode::get_elements_by_class_name(Utf16View class_n
if (token_start.has_value())
append_class_name(class_names.substring_view(*token_start));
- return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
+ return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(move(list_of_class_names), document().in_quirks_mode()), [](auto const& list_of_class_names, auto quirks_mode, Element const& element) {
for (auto& name : list_of_class_names) {
if (!element.has_class(name.utf16_view(), quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
return false;
}
- return !list_of_class_names.is_empty(); }, HTMLCollection::AttributeInvalidationType::Class);
+ return !list_of_class_names.is_empty(); }), HTMLCollection::AttributeInvalidationType::Class);
}
GC::Ptr<Element> ParentNode::get_element_by_id(Utf16View id) const
diff --git a/Libraries/LibWeb/HTML/HTMLAllCollection.cpp b/Libraries/LibWeb/HTML/HTMLAllCollection.cpp
index 645e4f9edc6..e4397987c7f 100644
--- a/Libraries/LibWeb/HTML/HTMLAllCollection.cpp
+++ b/Libraries/LibWeb/HTML/HTMLAllCollection.cpp
@@ -125,7 +125,7 @@ static AllNamedElementsLookupResult find_all_named_elements(DOM::ParentNode& roo
static GC::Ref<DOM::HTMLCollection> create_all_named_elements_sub_collection(DOM::ParentNode& root, Utf16String name)
{
// 2. Let subCollection be an HTMLCollection object rooted at the same Document as collection, whose filter matches only elements that are either:
- return DOM::HTMLCollection::create(root, DOM::HTMLCollection::Scope::Descendants, [name = move(name)](DOM::Element const& element) { return all_collection_element_matches_name(element, name); }, DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
+ return DOM::HTMLCollection::create(root, DOM::HTMLCollection::Scope::Descendants, GC::create_function(root.heap(), GC::captures(move(name)), [](Utf16String const& name, DOM::Element const& element) { return all_collection_element_matches_name(element, name); }), DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
}
static Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> get_the_all_named_elements(DOM::ParentNode& root, Utf16View name)
diff --git a/Libraries/LibWeb/HTML/HTMLDataListElement.cpp b/Libraries/LibWeb/HTML/HTMLDataListElement.cpp
index def05761c9f..350a92dc74e 100644
--- a/Libraries/LibWeb/HTML/HTMLDataListElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLDataListElement.cpp
@@ -31,7 +31,7 @@ GC::Ref<DOM::HTMLCollection> HTMLDataListElement::options()
{
// The options IDL attribute must return an HTMLCollection rooted at the datalist node, whose filter matches option elements.
if (!m_options) {
- m_options = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLOptionElement>(element); }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ m_options = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLOptionElement>(element); }), DOM::HTMLCollection::AttributeInvalidationType::None);
}
return *m_options;
}
diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp
index 403b9236fd0..cc12beb55eb 100644
--- a/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -1293,11 +1293,11 @@ GC::Ptr<DOM::NodeList> HTMLElement::labels()
auto& labels = ensure_html_element_rare_data().labels;
if (!labels) {
- auto filter = [&](DOM::Node const& node) {
+ auto filter = GC::create_function(heap(), GC::captures(*this), [](HTMLElement const& element, DOM::Node const& node) {
auto const* label_element = as_if<HTMLLabelElement>(node);
- return label_element && label_element->control().ptr() == this;
- };
- labels = DOM::LiveNodeList::create(root(), DOM::LiveNodeList::Scope::Descendants, move(filter), DOM::LiveNodeList::Kind::Labels);
+ return label_element && label_element->control().ptr() == &element;
+ });
+ labels = DOM::LiveNodeList::create(root(), DOM::LiveNodeList::Scope::Descendants, filter, DOM::LiveNodeList::Kind::Labels);
}
return labels;
diff --git a/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp b/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp
index 51a7409f9e4..12dd34aa8f4 100644
--- a/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLFieldSetElement.cpp
@@ -98,13 +98,13 @@ GC::Ptr<DOM::HTMLCollection> const& HTMLFieldSetElement::elements()
{
// The elements IDL attribute must return an HTMLCollection rooted at the fieldset element, whose filter matches listed elements.
if (!m_elements) {
- auto filter = [](DOM::Element const& element) {
+ auto filter = GC::create_function(heap(), [](DOM::Element const& element) {
if (auto const* form_associated_element = as_if<FormAssociatedElement>(element); form_associated_element && form_associated_element->is_listed())
return true;
return false;
- };
- m_elements = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, move(filter), DOM::HTMLCollection::AttributeInvalidationType::FormControls, nullptr, DOM::HTMLCollection::Kind::FormControls);
+ });
+ m_elements = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, filter, DOM::HTMLCollection::AttributeInvalidationType::FormControls, nullptr, DOM::HTMLCollection::Kind::FormControls);
}
return m_elements;
}
diff --git a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp
index 8f3da3be05f..0fabb3cd6f6 100644
--- a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp
+++ b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.cpp
@@ -27,13 +27,13 @@ static bool radio_node_list_element_matches_name(DOM::Element const& element, Ut
GC_DEFINE_ALLOCATOR(HTMLFormControlsCollection);
-GC::Ref<HTMLFormControlsCollection> HTMLFormControlsCollection::create(DOM::ParentNode& root, Scope scope, HTMLFormElement& form, Function<bool(DOM::Element const&)> filter)
+GC::Ref<HTMLFormControlsCollection> HTMLFormControlsCollection::create(DOM::ParentNode& root, Scope scope, HTMLFormElement& form, Filter filter)
{
- return GC::Heap::the().allocate<HTMLFormControlsCollection>(root, scope, form, move(filter));
+ return GC::Heap::the().allocate<HTMLFormControlsCollection>(root, scope, form, filter);
}
-HTMLFormControlsCollection::HTMLFormControlsCollection(DOM::ParentNode& root, Scope scope, HTMLFormElement& form, Function<bool(DOM::Element const&)> filter)
- : DOM::HTMLCollection(root, scope, move(filter), AttributeInvalidationType::FormControls, nullptr, Kind::FormControls)
+HTMLFormControlsCollection::HTMLFormControlsCollection(DOM::ParentNode& root, Scope scope, HTMLFormElement& form, Filter filter)
+ : DOM::HTMLCollection(root, scope, filter, AttributeInvalidationType::FormControls, nullptr, Kind::FormControls)
, m_form(form)
{
}
@@ -89,15 +89,15 @@ Variant<Empty, GC::Ref<DOM::Element>, GC::Ref<RadioNodeList>> HTMLFormControlsCo
// RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree
// order. Return that RadioNodeList object.
auto name_copy = Utf16String::from_utf16(name);
- auto filter = [collection = GC::Ref { *this }, name = move(name_copy)](auto const& node) {
+ auto filter = GC::create_function(heap(), GC::captures(*this, move(name_copy)), [](HTMLFormControlsCollection const& collection, Utf16String const& name, DOM::Node const& node) {
if (!is<DOM::Element>(node))
return false;
auto const& element = as<DOM::Element>(node);
- return collection->element_matches_filter(element)
+ return collection.element_matches_filter(element)
&& radio_node_list_element_matches_name(element, radio_node_list_name_view(name));
- };
- return RadioNodeList::create(root(), DOM::LiveNodeList::Scope::Descendants, move(filter), DOM::LiveNodeList::Kind::FormControls);
+ });
+ return RadioNodeList::create(root(), DOM::LiveNodeList::Scope::Descendants, filter, DOM::LiveNodeList::Kind::FormControls);
}
}
diff --git a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h
index 59b88874e57..0cfbd9129e7 100644
--- a/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h
+++ b/Libraries/LibWeb/HTML/HTMLFormControlsCollection.h
@@ -17,14 +17,14 @@ class HTMLFormControlsCollection : public DOM::HTMLCollection {
GC_DECLARE_ALLOCATOR(HTMLFormControlsCollection);
public:
- [[nodiscard]] static GC::Ref<HTMLFormControlsCollection> create(DOM::ParentNode& root, Scope, HTMLFormElement& form, ESCAPING Function<bool(DOM::Element const&)> filter);
+ [[nodiscard]] static GC::Ref<HTMLFormControlsCollection> create(DOM::ParentNode& root, Scope, HTMLFormElement& form, Filter filter);
virtual ~HTMLFormControlsCollection() override;
Variant<Empty, GC::Ref<DOM::Element>, GC::Ref<RadioNodeList>> named_item_or_radio_node_list(Utf16View name) const;
private:
- HTMLFormControlsCollection(DOM::ParentNode& root, Scope, HTMLFormElement& form, ESCAPING Function<bool(DOM::Element const&)> filter);
+ HTMLFormControlsCollection(DOM::ParentNode& root, Scope, HTMLFormElement& form, Filter filter);
virtual void collect_elements_into(Vector<GC::RawPtr<DOM::Element>>&) const override;
diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index cc5ada1c135..77bf039761c 100644
--- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -627,9 +627,9 @@ GC::Ref<HTMLFormControlsCollection> HTMLFormElement::elements() const
{
if (!m_elements) {
auto& root = as<ParentNode>(const_cast<HTMLFormElement*>(this)->root());
- m_elements = HTMLFormControlsCollection::create(root, DOM::HTMLCollection::Scope::Descendants, const_cast<HTMLFormElement&>(*this), [this](Element const& element) {
- return is_form_control(element, *this);
- });
+ m_elements = HTMLFormControlsCollection::create(root, DOM::HTMLCollection::Scope::Descendants, const_cast<HTMLFormElement&>(*this), GC::create_function(heap(), GC::captures(*this), [](HTMLFormElement const& form, Element const& element) {
+ return is_form_control(element, form);
+ }));
}
return *m_elements;
}
@@ -1224,14 +1224,14 @@ Variant<Empty, GC::Ref<DOM::Node>, GC::Ref<RadioNodeList>> HTMLFormElement::name
// 1. Let candidates be a live RadioNodeList object containing all the listed elements, whose form owner is the form
// element, that have either an id attribute or a name attribute equal to name, with the exception of input
// elements whose type attribute is in the Image Button state, in tree order.
- auto filter = [this, name](DOM::Node const& node) -> bool {
+ auto filter = [](HTMLFormElement const& form, Utf16FlyString const& name, DOM::Node const& node) -> bool {
auto const* element = as_if<DOM::Element>(node);
if (!element)
return false;
// Form controls are defined as listed elements, with the exception of input elements in the Image Button state,
// whose form owner is the form element.
- if (!is_form_control(*element, *this))
+ if (!is_form_control(*element, form))
return false;
return name == element->id() || name == element->name();
@@ -1240,12 +1240,12 @@ Variant<Empty, GC::Ref<DOM::Node>, GC::Ref<RadioNodeList>> HTMLFormElement::name
// 2. If candidates is empty, let candidates be a live RadioNodeList object containing all the img elements,
// whose form owner is the form element, that have either an id attribute or a name attribute equal to name,
// in tree order.
- auto image_filter = [this, name](DOM::Node const& node) -> bool {
+ auto image_filter = [](HTMLFormElement const& form, Utf16FlyString const& name, DOM::Node const& node) -> bool {
auto const* element = as_if<HTMLImageElement>(node);
if (!element)
return false;
- if (element->form() != this)
+ if (element->form() != &form)
return false;
return name == element->id() || name == element->name();
@@ -1260,7 +1260,7 @@ Variant<Empty, GC::Ref<DOM::Node>, GC::Ref<RadioNodeList>> HTMLFormElement::name
first_candidate = nullptr;
candidate_count = 0;
for (auto const& element : m_associated_elements_in_tree_order) {
- if (!candidate_filter(*element))
+ if (!candidate_filter(*this, name, *element))
continue;
if (!first_candidate)
first_candidate = element;
@@ -1284,8 +1284,8 @@ Variant<Empty, GC::Ref<DOM::Node>, GC::Ref<RadioNodeList>> HTMLFormElement::name
// 4. If candidates contains more than one node, return candidates.
if (candidate_count > 1) {
if (candidates_are_images)
- return RadioNodeList::create(root, DOM::LiveNodeList::Scope::Descendants, move(image_filter));
- return RadioNodeList::create(root, DOM::LiveNodeList::Scope::Descendants, move(filter), DOM::LiveNodeList::Kind::FormControls);
+ return RadioNodeList::create(root, DOM::LiveNodeList::Scope::Descendants, GC::create_function(heap(), GC::captures(*this, name), image_filter));
+ return RadioNodeList::create(root, DOM::LiveNodeList::Scope::Descendants, GC::create_function(heap(), GC::captures(*this, name), filter), DOM::LiveNodeList::Kind::FormControls);
}
// 5. Otherwise, candidates contains exactly one node. Add a mapping from name to the node in candidates in the form
diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
index 9d03d5c8315..3803849ca30 100644
--- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
@@ -1691,11 +1691,11 @@ void HTMLLinkElement::load_fallback_favicon_if_needed(GC::Ref<DOM::Document> doc
return;
if (!document->url().scheme().is_one_of("http"sv, "https"sv))
return;
- auto icon_link_elements = DOM::HTMLCollection::create(*document, DOM::HTMLCollection::Scope::Descendants, [](DOM::Element const& element) {
+ auto icon_link_elements = DOM::HTMLCollection::create(*document, DOM::HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](DOM::Element const& element) {
if (!is<HTMLLinkElement>(element))
return false;
- return static_cast<HTMLLinkElement const&>(element).has_icon_keyword(); }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ return static_cast<HTMLLinkElement const&>(element).has_icon_keyword(); }), DOM::HTMLCollection::AttributeInvalidationType::None);
if (icon_link_elements->length() != 0)
return;
diff --git a/Libraries/LibWeb/HTML/HTMLMapElement.cpp b/Libraries/LibWeb/HTML/HTMLMapElement.cpp
index 7da0ace7d85..a36f2558c6d 100644
--- a/Libraries/LibWeb/HTML/HTMLMapElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMapElement.cpp
@@ -75,7 +75,7 @@ GC::Ref<DOM::HTMLCollection> HTMLMapElement::areas()
{
// The areas attribute must return an HTMLCollection rooted at the map element, whose filter matches only area elements.
if (!m_areas) {
- m_areas = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [](Element const& element) { return is<HTML::HTMLAreaElement>(element); }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ m_areas = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTML::HTMLAreaElement>(element); }), DOM::HTMLCollection::AttributeInvalidationType::None);
}
return *m_areas;
}
diff --git a/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
index a1656c28ec4..339656c61e0 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
+++ b/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp
@@ -17,13 +17,13 @@ namespace Web::HTML {
GC_DEFINE_ALLOCATOR(HTMLOptionsCollection);
-GC::Ref<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
+GC::Ref<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::ParentNode& root, Filter filter)
{
- return GC::Heap::the().allocate<HTMLOptionsCollection>(root, move(filter));
+ return GC::Heap::the().allocate<HTMLOptionsCollection>(root, filter);
}
-HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
- : DOM::HTMLCollection(root, Scope::Descendants, move(filter), AttributeInvalidationType::None)
+HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Filter filter)
+ : DOM::HTMLCollection(root, Scope::Descendants, filter, AttributeInvalidationType::None)
{
}
diff --git a/Libraries/LibWeb/HTML/HTMLOptionsCollection.h b/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
index be63820ffc2..31026e68d3a 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
+++ b/Libraries/LibWeb/HTML/HTMLOptionsCollection.h
@@ -22,7 +22,7 @@ class HTMLOptionsCollection final : public DOM::HTMLCollection {
GC_DECLARE_ALLOCATOR(HTMLOptionsCollection);
public:
- [[nodiscard]] static GC::Ref<HTMLOptionsCollection> create(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
+ [[nodiscard]] static GC::Ref<HTMLOptionsCollection> create(DOM::ParentNode& root, Filter filter);
virtual ~HTMLOptionsCollection() override;
WebIDL::ExceptionOr<void> set_value_of_indexed_property(u32, Optional<GC::Ref<DOM::Element>>);
@@ -37,7 +37,7 @@ public:
WebIDL::ExceptionOr<void> set_selected_index(WebIDL::Long);
private:
- HTMLOptionsCollection(DOM::ParentNode& root, ESCAPING Function<bool(DOM::Element const&)> filter);
+ HTMLOptionsCollection(DOM::ParentNode& root, Filter filter);
};
}
diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
index 8668b291ba8..5fe9156d4c8 100644
--- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp
@@ -125,10 +125,10 @@ GC::Ptr<HTMLOptionsCollection> const& HTMLSelectElement::options() const
// The options IDL attribute must return an HTMLOptionsCollection rooted at the select node,
// whose filter matches the elements in the list of options.
if (!m_options) {
- m_options = HTMLOptionsCollection::create(const_cast<HTMLSelectElement&>(*this), [this](DOM::Element const& element) {
+ m_options = HTMLOptionsCollection::create(const_cast<HTMLSelectElement&>(*this), GC::create_function(heap(), GC::captures(*this), [](HTMLSelectElement const& select, DOM::Element const& element) {
auto const* maybe_option = as_if<HTML::HTMLOptionElement>(element);
- return maybe_option && maybe_option->nearest_select_element().ptr() == this;
- });
+ return maybe_option && maybe_option->nearest_select_element().ptr() == &select;
+ }));
}
return m_options;
}
@@ -200,14 +200,14 @@ GC::Ref<DOM::HTMLCollection> HTMLSelectElement::selected_options()
// The selectedOptions IDL attribute must return an HTMLCollection rooted at the select node,
// whose filter matches the elements in the list of options that have their selectedness set to true.
if (!m_selected_options) {
- auto filter = [this](Element const& element) {
+ auto filter = GC::create_function(heap(), GC::captures(*this), [](HTMLSelectElement const& select, Element const& element) {
auto const* maybe_option = as_if<HTML::HTMLOptionElement>(element);
- if (maybe_option && maybe_option->nearest_select_element().ptr() == this) {
+ if (maybe_option && maybe_option->nearest_select_element().ptr() == &select) {
return maybe_option->selected();
}
return false;
- };
- m_selected_options = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, move(filter), DOM::HTMLCollection::AttributeInvalidationType::None, nullptr, DOM::HTMLCollection::Kind::SelectedOptions);
+ });
+ m_selected_options = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, filter, DOM::HTMLCollection::AttributeInvalidationType::None, nullptr, DOM::HTMLCollection::Kind::SelectedOptions);
}
return *m_selected_options;
}
diff --git a/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Libraries/LibWeb/HTML/HTMLTableElement.cpp
index 8ff810a9598..452fc92aa44 100644
--- a/Libraries/LibWeb/HTML/HTMLTableElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTableElement.cpp
@@ -357,7 +357,7 @@ GC::Ref<DOM::HTMLCollection> HTMLTableElement::t_bodies()
// The tBodies attribute must return an HTMLCollection rooted at the table node,
// whose filter matches only tbody elements that are children of the table element.
if (!m_t_bodies) {
- m_t_bodies = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Children, [](DOM::Element const& element) { return element.local_name() == TagNames::tbody; }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ m_t_bodies = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Children, GC::create_function(GC::Heap::the(), [](DOM::Element const& element) { return element.local_name() == TagNames::tbody; }), DOM::HTMLCollection::AttributeInvalidationType::None);
}
return *m_t_bodies;
}
@@ -389,7 +389,6 @@ GC::Ref<HTMLTableSectionElement> HTMLTableElement::create_t_body()
// https://html.spec.whatwg.org/multipage/tables.html#dom-table-rows
GC::Ref<DOM::HTMLCollection> HTMLTableElement::rows()
{
- HTMLTableElement* table_node = this;
// The elements in the collection must be ordered such that those elements whose parent is a thead are included
// first, in tree order, followed by those elements whose parent is either a table or tbody element, again in tree
// order, followed finally by those elements whose parent is a tfoot element, still in tree order.
@@ -397,22 +396,22 @@ GC::Ref<DOM::HTMLCollection> HTMLTableElement::rows()
m_rows = DOM::HTMLCollection::create(
*this,
DOM::HTMLCollection::Scope::Descendants,
- [table_node](DOM::Element const& element) {
+ GC::create_function(heap(), GC::captures(*this), [](HTMLTableElement const& table_node, DOM::Element const& element) {
// Only match TR elements which are:
// * children of the table element
// * children of the thead, tbody, or tfoot elements that are themselves children of the table element
if (!is<HTMLTableRowElement>(element)) {
return false;
}
- if (element.parent_element().ptr() == table_node)
+ if (element.parent_element().ptr() == &table_node)
return true;
- if (element.parent_element() && element.parent_element()->local_name().is_one_of(TagNames::thead, TagNames::tbody, TagNames::tfoot) && element.parent()->parent() == table_node)
+ if (element.parent_element() && element.parent_element()->local_name().is_one_of(TagNames::thead, TagNames::tbody, TagNames::tfoot) && element.parent()->parent() == &table_node)
return true;
- return false; },
+ return false; }),
DOM::HTMLCollection::AttributeInvalidationType::None,
- [](Element const& a, Element const& b) -> bool {
+ GC::create_function(heap(), [](Element const& a, Element const& b) -> bool {
auto static sort_priority = [](Element const& element) {
auto const& parent_tag = element.parent_element()->local_name();
if (parent_tag == TagNames::thead)
@@ -430,7 +429,7 @@ GC::Ref<DOM::HTMLCollection> HTMLTableElement::rows()
if (prio_a != prio_b)
return prio_a < prio_b;
- return false; });
+ return false; }));
}
return *m_rows;
}
diff --git a/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index 28020b2b930..a7b056206b7 100644
--- a/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -82,7 +82,7 @@ GC::Ref<DOM::HTMLCollection> HTMLTableRowElement::cells() const
// The cells attribute must return an HTMLCollection rooted at this tr element,
// whose filter matches only td and th elements that are children of the tr element.
if (!m_cells) {
- m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), DOM::HTMLCollection::Scope::Children, [](Element const& element) { return is<HTMLTableCellElement>(element); }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), DOM::HTMLCollection::Scope::Children, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTMLTableCellElement>(element); }), DOM::HTMLCollection::AttributeInvalidationType::None);
}
return *m_cells;
}
diff --git a/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
index 7472db324bd..ca66b314c2e 100644
--- a/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
@@ -40,7 +40,7 @@ GC::Ref<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
// The rows attribute must return an HTMLCollection rooted at this element,
// whose filter matches only tr elements that are children of this element.
if (!m_rows) {
- m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), DOM::HTMLCollection::Scope::Children, [](Element const& element) { return is<HTMLTableRowElement>(element); }, DOM::HTMLCollection::AttributeInvalidationType::None);
+ m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), DOM::HTMLCollection::Scope::Children, GC::create_function(GC::Heap::the(), [](Element const& element) { return is<HTMLTableRowElement>(element); }), DOM::HTMLCollection::AttributeInvalidationType::None);
}
return *m_rows;
}
diff --git a/Libraries/LibWeb/HTML/RadioNodeList.cpp b/Libraries/LibWeb/HTML/RadioNodeList.cpp
index 4e3085f44cd..08ec6fb9629 100644
--- a/Libraries/LibWeb/HTML/RadioNodeList.cpp
+++ b/Libraries/LibWeb/HTML/RadioNodeList.cpp
@@ -13,13 +13,13 @@ namespace Web::HTML {
GC_DEFINE_ALLOCATOR(RadioNodeList);
-GC::Ref<RadioNodeList> RadioNodeList::create(DOM::Node const& root, Scope scope, Function<bool(DOM::Node const&)> filter, Kind kind)
+GC::Ref<RadioNodeList> RadioNodeList::create(DOM::Node const& root, Scope scope, Filter filter, Kind kind)
{
- return GC::Heap::the().allocate<RadioNodeList>(root, scope, move(filter), kind);
+ return GC::Heap::the().allocate<RadioNodeList>(root, scope, filter, kind);
}
-RadioNodeList::RadioNodeList(DOM::Node const& root, Scope scope, Function<bool(DOM::Node const&)> filter, Kind kind)
- : DOM::LiveNodeList(root, scope, move(filter), kind)
+RadioNodeList::RadioNodeList(DOM::Node const& root, Scope scope, Filter filter, Kind kind)
+ : DOM::LiveNodeList(root, scope, filter, kind)
{
}
diff --git a/Libraries/LibWeb/HTML/RadioNodeList.h b/Libraries/LibWeb/HTML/RadioNodeList.h
index bf4e3e360bb..000dd5d1bb6 100644
--- a/Libraries/LibWeb/HTML/RadioNodeList.h
+++ b/Libraries/LibWeb/HTML/RadioNodeList.h
@@ -17,7 +17,7 @@ class RadioNodeList : public DOM::LiveNodeList {
GC_DECLARE_ALLOCATOR(RadioNodeList);
public:
- [[nodiscard]] static GC::Ref<RadioNodeList> create(DOM::Node const& root, Scope scope, ESCAPING Function<bool(DOM::Node const&)> filter, Kind = Kind::Generic);
+ [[nodiscard]] static GC::Ref<RadioNodeList> create(DOM::Node const& root, Scope scope, Filter filter, Kind = Kind::Generic);
virtual ~RadioNodeList() override;
@@ -25,7 +25,7 @@ public:
void set_value(Utf16View);
private:
- explicit RadioNodeList(DOM::Node const& root, Scope scope, ESCAPING Function<bool(DOM::Node const&)> filter, Kind);
+ explicit RadioNodeList(DOM::Node const& root, Scope scope, Filter filter, Kind);
};
}
diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp
index c4caa4b36aa..6bf8c1d8fea 100644
--- a/Libraries/LibWeb/HTML/Window.cpp
+++ b/Libraries/LibWeb/HTML/Window.cpp
@@ -2471,10 +2471,10 @@ Variant<Empty, GC::Ref<WindowProxy>, GC::Ref<DOM::Element>, GC::Ref<DOM::HTMLCol
// 4. Otherwise return an HTMLCollection rooted at window's associated Document,
// whose filter matches only named objects of window with the name name. (By definition, these will all be elements.)
- auto collection = DOM::HTMLCollection::create(mutable_this.associated_document(), DOM::HTMLCollection::Scope::Descendants, [name](auto& element) -> bool {
+ auto collection = DOM::HTMLCollection::create(mutable_this.associated_document(), DOM::HTMLCollection::Scope::Descendants, GC::create_function(heap(), GC::captures(name), [](Utf16FlyString const& name, DOM::Element const& element) -> bool {
if (is_named_element_by_name(element) && element.name() == name)
return true;
- return element.id() == name; }, DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
+ return element.id() == name; }), DOM::HTMLCollection::AttributeInvalidationType::IdOrName);
return collection;
}