summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2023-02-14 22:53:08 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-18 00:52:47 +0100
commitff875d353ba632387457826a6fd2dd38f2817d04 (patch)
tree7109affb83a752d5faa26ced6257bf7e932bb34c
parentc120c46acc4bc12fa8f3f9ed5f9f953626d3cf9e (diff)
downloadserenity-ff875d353ba632387457826a6fd2dd38f2817d04.zip
LibWeb: Make factory method of DOM::HTMLCollection fallible
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp22
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp4
-rw-r--r--Userland/Libraries/LibWeb/DOM/HTMLCollection.h2
-rw-r--r--Userland/Libraries/LibWeb/DOM/ParentNode.cpp16
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp2
9 files changed, 28 insertions, 28 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index e28131e2c5..0afe2b1391 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1024,7 +1024,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(DeprecatedString
{
return HTMLCollection::create(*this, [name](Element const& element) {
return element.name() == name;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(DeprecatedFlyString const& class_names)
@@ -1039,14 +1039,14 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(Deprecated
return false;
}
return true;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
JS::NonnullGCPtr<HTMLCollection> Document::applets()
{
if (!m_applets)
- m_applets = HTMLCollection::create(*this, [](auto&) { return false; });
+ m_applets = HTMLCollection::create(*this, [](auto&) { return false; }).release_value_but_fixme_should_propagate_errors();
return *m_applets;
}
@@ -1056,7 +1056,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::anchors()
if (!m_anchors) {
m_anchors = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_anchors;
}
@@ -1067,7 +1067,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::images()
if (!m_images) {
m_images = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLImageElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_images;
}
@@ -1078,7 +1078,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::embeds()
if (!m_embeds) {
m_embeds = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLEmbedElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_embeds;
}
@@ -1095,7 +1095,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::links()
if (!m_links) {
m_links = HTMLCollection::create(*this, [](Element const& element) {
return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_links;
}
@@ -1106,7 +1106,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::forms()
if (!m_forms) {
m_forms = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLFormElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_forms;
}
@@ -1117,7 +1117,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::scripts()
if (!m_scripts) {
m_scripts = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLScriptElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_scripts;
}
@@ -1128,7 +1128,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::all()
if (!m_all) {
m_all = HTMLCollection::create(*this, [](Element const&) {
return true;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_all;
}
@@ -2004,7 +2004,7 @@ void Document::check_favicon_after_loading_link_resource()
return false;
return static_cast<HTML::HTMLLinkElement const&>(element).has_loaded_icon();
- });
+ }).release_value_but_fixme_should_propagate_errors();
if (favicon_link_elements->length() == 0) {
dbgln_if(SPAM_DEBUG, "No favicon found to be used");
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 69f1eabcb8..5a6ab10e52 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -586,7 +586,7 @@ JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(DeprecatedF
return false;
}
return true;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// https://dom.spec.whatwg.org/#element-shadow-host
diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
index 2849e7ac40..45e1b1a4d4 100644
--- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
+++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp
@@ -13,9 +13,9 @@
namespace Web::DOM {
-JS::NonnullGCPtr<HTMLCollection> HTMLCollection::create(ParentNode& root, Function<bool(Element const&)> filter)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLCollection>> HTMLCollection::create(ParentNode& root, Function<bool(Element const&)> filter)
{
- return root.heap().allocate<HTMLCollection>(root.realm(), root, move(filter)).release_allocated_value_but_fixme_should_propagate_errors();
+ return MUST_OR_THROW_OOM(root.heap().allocate<HTMLCollection>(root.realm(), root, move(filter)));
}
HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter)
diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
index 78998f2f4b..8e99f64bf6 100644
--- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
+++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h
@@ -29,7 +29,7 @@ class HTMLCollection : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::LegacyPlatformObject);
public:
- static JS::NonnullGCPtr<HTMLCollection> create(ParentNode& root, Function<bool(Element const&)> filter);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLCollection>> create(ParentNode& root, Function<bool(Element const&)> filter);
virtual ~HTMLCollection() override;
diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
index 8654ac6526..0cce06ddd6 100644
--- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -96,7 +96,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::children()
if (!m_children) {
m_children = HTMLCollection::create(*this, [this](Element const& element) {
return is_parent_of(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_children;
}
@@ -109,7 +109,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(Deprecated
if (qualified_name == "*") {
return HTMLCollection::create(*this, [](Element const&) {
return true;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// 2. Otherwise, if root’s node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements:
@@ -121,13 +121,13 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(Deprecated
// - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.
return element.qualified_name() == qualified_name;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// 3. Otherwise, return a HTMLCollection rooted at root, whose filter matches descendant elements whose qualified name is qualifiedName.
return HTMLCollection::create(*this, [qualified_name](Element const& element) {
return element.qualified_name() == qualified_name;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// https://dom.spec.whatwg.org/#concept-getelementsbytagnamens
@@ -143,27 +143,27 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name_ns(Depreca
if (namespace_ == "*" && local_name == "*") {
return HTMLCollection::create(*this, [](Element const&) {
return true;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// 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_ == "*") {
return HTMLCollection::create(*this, [local_name](Element const& element) {
return element.local_name() == local_name;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// 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 == "*") {
return HTMLCollection::create(*this, [namespace_](Element const& element) {
return element.namespace_() == namespace_;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// 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, [namespace_, local_name](Element const& element) {
return element.namespace_() == namespace_ && element.local_name() == local_name;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
index c5a1a65a7d..7aa01d7aed 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp
@@ -236,7 +236,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
if (!m_elements) {
m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
return is_form_control(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_elements;
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
index a6747dcd13..322c5cff4e 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
@@ -264,7 +264,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
if (!m_t_bodies) {
m_t_bodies = DOM::HTMLCollection::create(*this, [](DOM::Element const& element) {
return element.local_name() == TagNames::tbody;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_t_bodies;
}
@@ -321,7 +321,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::rows()
}
return false;
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_rows;
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index db02190d93..a72941ee6b 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -45,7 +45,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) {
return element.parent() == this
&& is<HTMLTableCellElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_cells;
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
index 5c469839c3..1f4b976526 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp
@@ -44,7 +44,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), [this](Element const& element) {
return element.parent() == this
&& is<HTMLTableRowElement>(element);
- });
+ }).release_value_but_fixme_should_propagate_errors();
}
return *m_rows;
}