LibWeb: Make factory method of DOM::NamedNodeMap fallible

This commit is contained in:
Kenneth Myhra 2023-02-14 23:04:29 +01:00 committed by Linus Groh
parent ce18dfc417
commit e3e281addd
Notes: sideshowbarker 2024-07-17 00:12:08 +09:00
3 changed files with 7 additions and 4 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Debug.h>
#include <AK/StringBuilder.h>
#include <LibWeb/Bindings/ElementPrototype.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
@ -66,7 +67,9 @@ JS::ThrowCompletionOr<void> Element::initialize(JS::Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::ElementPrototype>(realm, "Element"));
m_attributes = NamedNodeMap::create(*this);
m_attributes = TRY(Bindings::throw_dom_exception_if_needed(realm.vm(), [&]() {
return NamedNodeMap::create(*this);
}));
return {};
}

View file

@ -13,10 +13,10 @@
namespace Web::DOM {
JS::NonnullGCPtr<NamedNodeMap> NamedNodeMap::create(Element& element)
WebIDL::ExceptionOr<JS::NonnullGCPtr<NamedNodeMap>> NamedNodeMap::create(Element& element)
{
auto& realm = element.realm();
return realm.heap().allocate<NamedNodeMap>(realm, element).release_allocated_value_but_fixme_should_propagate_errors();
return MUST_OR_THROW_OOM(realm.heap().allocate<NamedNodeMap>(realm, element));
}
NamedNodeMap::NamedNodeMap(Element& element)

View file

@ -22,7 +22,7 @@ class NamedNodeMap : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(NamedNodeMap, Bindings::LegacyPlatformObject);
public:
static JS::NonnullGCPtr<NamedNodeMap> create(Element&);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<NamedNodeMap>> create(Element&);
~NamedNodeMap() = default;
virtual bool is_supported_property_index(u32 index) const override;