Prechádzať zdrojové kódy

LibWeb: Make factory method of DOM::HTMLCollection fallible

Kenneth Myhra 2 rokov pred
rodič
commit
ff875d353b

+ 11 - 11
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");

+ 1 - 1
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

+ 2 - 2
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)

+ 1 - 1
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;
 

+ 8 - 8
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

+ 1 - 1
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;
 }

+ 2 - 2
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;
 }

+ 1 - 1
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;
 }

+ 1 - 1
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;
 }