1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

LibWeb: Make factory method of DOM::HTMLCollection fallible

This commit is contained in:
Kenneth Myhra 2023-02-14 22:53:08 +01:00 committed by Linus Groh
parent c120c46acc
commit ff875d353b
9 changed files with 28 additions and 28 deletions

View file

@ -1024,7 +1024,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(DeprecatedString
{ {
return HTMLCollection::create(*this, [name](Element const& element) { return HTMLCollection::create(*this, [name](Element const& element) {
return element.name() == name; return element.name() == name;
}); }).release_value_but_fixme_should_propagate_errors();
} }
JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(DeprecatedFlyString const& class_names) 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 false;
} }
return true; return true;
}); }).release_value_but_fixme_should_propagate_errors();
} }
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets // https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-applets
JS::NonnullGCPtr<HTMLCollection> Document::applets() JS::NonnullGCPtr<HTMLCollection> Document::applets()
{ {
if (!m_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; return *m_applets;
} }
@ -1056,7 +1056,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::anchors()
if (!m_anchors) { if (!m_anchors) {
m_anchors = HTMLCollection::create(*this, [](Element const& element) { m_anchors = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name); return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_anchors; return *m_anchors;
} }
@ -1067,7 +1067,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::images()
if (!m_images) { if (!m_images) {
m_images = HTMLCollection::create(*this, [](Element const& element) { m_images = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLImageElement>(element); return is<HTML::HTMLImageElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_images; return *m_images;
} }
@ -1078,7 +1078,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::embeds()
if (!m_embeds) { if (!m_embeds) {
m_embeds = HTMLCollection::create(*this, [](Element const& element) { m_embeds = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLEmbedElement>(element); return is<HTML::HTMLEmbedElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_embeds; return *m_embeds;
} }
@ -1095,7 +1095,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::links()
if (!m_links) { if (!m_links) {
m_links = HTMLCollection::create(*this, [](Element const& element) { m_links = HTMLCollection::create(*this, [](Element const& element) {
return (is<HTML::HTMLAnchorElement>(element) || is<HTML::HTMLAreaElement>(element)) && element.has_attribute(HTML::AttributeNames::href); 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; return *m_links;
} }
@ -1106,7 +1106,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::forms()
if (!m_forms) { if (!m_forms) {
m_forms = HTMLCollection::create(*this, [](Element const& element) { m_forms = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLFormElement>(element); return is<HTML::HTMLFormElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_forms; return *m_forms;
} }
@ -1117,7 +1117,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::scripts()
if (!m_scripts) { if (!m_scripts) {
m_scripts = HTMLCollection::create(*this, [](Element const& element) { m_scripts = HTMLCollection::create(*this, [](Element const& element) {
return is<HTML::HTMLScriptElement>(element); return is<HTML::HTMLScriptElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_scripts; return *m_scripts;
} }
@ -1128,7 +1128,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::all()
if (!m_all) { if (!m_all) {
m_all = HTMLCollection::create(*this, [](Element const&) { m_all = HTMLCollection::create(*this, [](Element const&) {
return true; return true;
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_all; return *m_all;
} }
@ -2004,7 +2004,7 @@ void Document::check_favicon_after_loading_link_resource()
return false; return false;
return static_cast<HTML::HTMLLinkElement const&>(element).has_loaded_icon(); return static_cast<HTML::HTMLLinkElement const&>(element).has_loaded_icon();
}); }).release_value_but_fixme_should_propagate_errors();
if (favicon_link_elements->length() == 0) { if (favicon_link_elements->length() == 0) {
dbgln_if(SPAM_DEBUG, "No favicon found to be used"); dbgln_if(SPAM_DEBUG, "No favicon found to be used");

View file

@ -586,7 +586,7 @@ JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(DeprecatedF
return false; return false;
} }
return true; return true;
}); }).release_value_but_fixme_should_propagate_errors();
} }
// https://dom.spec.whatwg.org/#element-shadow-host // https://dom.spec.whatwg.org/#element-shadow-host

View file

@ -13,9 +13,9 @@
namespace Web::DOM { 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) HTMLCollection::HTMLCollection(ParentNode& root, Function<bool(Element const&)> filter)

View file

@ -29,7 +29,7 @@ class HTMLCollection : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::LegacyPlatformObject); WEB_PLATFORM_OBJECT(HTMLCollection, Bindings::LegacyPlatformObject);
public: 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; virtual ~HTMLCollection() override;

View file

@ -96,7 +96,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::children()
if (!m_children) { if (!m_children) {
m_children = HTMLCollection::create(*this, [this](Element const& element) { m_children = HTMLCollection::create(*this, [this](Element const& element) {
return is_parent_of(element); return is_parent_of(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_children; return *m_children;
} }
@ -109,7 +109,7 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(Deprecated
if (qualified_name == "*") { if (qualified_name == "*") {
return HTMLCollection::create(*this, [](Element const&) { return HTMLCollection::create(*this, [](Element const&) {
return true; return true;
}); }).release_value_but_fixme_should_propagate_errors();
} }
// 2. Otherwise, if roots node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements: // 2. Otherwise, if roots 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. // - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.
return element.qualified_name() == qualified_name; 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. // 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 HTMLCollection::create(*this, [qualified_name](Element const& element) {
return element.qualified_name() == qualified_name; return element.qualified_name() == qualified_name;
}); }).release_value_but_fixme_should_propagate_errors();
} }
// https://dom.spec.whatwg.org/#concept-getelementsbytagnamens // 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 == "*") { if (namespace_ == "*" && local_name == "*") {
return HTMLCollection::create(*this, [](Element const&) { return HTMLCollection::create(*this, [](Element const&) {
return true; 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. // 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_ == "*") { if (namespace_ == "*") {
return HTMLCollection::create(*this, [local_name](Element const& element) { return HTMLCollection::create(*this, [local_name](Element const& element) {
return element.local_name() == local_name; 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. // 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 == "*") { if (local_name == "*") {
return HTMLCollection::create(*this, [namespace_](Element const& element) { return HTMLCollection::create(*this, [namespace_](Element const& element) {
return element.namespace_() == namespace_; 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. // 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 HTMLCollection::create(*this, [namespace_, local_name](Element const& element) {
return element.namespace_() == namespace_ && element.local_name() == local_name; return element.namespace_() == namespace_ && element.local_name() == local_name;
}); }).release_value_but_fixme_should_propagate_errors();
} }
// https://dom.spec.whatwg.org/#dom-parentnode-prepend // https://dom.spec.whatwg.org/#dom-parentnode-prepend

View file

@ -236,7 +236,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
if (!m_elements) { if (!m_elements) {
m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) { m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
return is_form_control(element); return is_form_control(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_elements; return *m_elements;
} }

View file

@ -264,7 +264,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
if (!m_t_bodies) { if (!m_t_bodies) {
m_t_bodies = DOM::HTMLCollection::create(*this, [](DOM::Element const& element) { m_t_bodies = DOM::HTMLCollection::create(*this, [](DOM::Element const& element) {
return element.local_name() == TagNames::tbody; return element.local_name() == TagNames::tbody;
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_t_bodies; return *m_t_bodies;
} }
@ -321,7 +321,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::rows()
} }
return false; return false;
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_rows; return *m_rows;
} }

View file

@ -45,7 +45,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) { m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) {
return element.parent() == this return element.parent() == this
&& is<HTMLTableCellElement>(element); && is<HTMLTableCellElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_cells; return *m_cells;
} }

View file

@ -44,7 +44,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), [this](Element const& element) { m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), [this](Element const& element) {
return element.parent() == this return element.parent() == this
&& is<HTMLTableRowElement>(element); && is<HTMLTableRowElement>(element);
}); }).release_value_but_fixme_should_propagate_errors();
} }
return *m_rows; return *m_rows;
} }