LibWeb: Make factory method of HTML::DOMStringMap fallible

This commit is contained in:
Kenneth Myhra 2023-02-15 19:18:58 +01:00 committed by Linus Groh
parent 809206f50e
commit b604bbaf29
4 changed files with 8 additions and 5 deletions

View file

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

View file

@ -17,7 +17,7 @@ class DOMStringMap final : public Bindings::LegacyPlatformObject {
WEB_PLATFORM_OBJECT(DOMStringMap, Bindings::LegacyPlatformObject); WEB_PLATFORM_OBJECT(DOMStringMap, Bindings::LegacyPlatformObject);
public: public:
static JS::NonnullGCPtr<DOMStringMap> create(DOM::Element&); static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMStringMap>> create(DOM::Element&);
virtual ~DOMStringMap() override; virtual ~DOMStringMap() override;

View file

@ -7,6 +7,7 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibWeb/ARIA/Roles.h> #include <LibWeb/ARIA/Roles.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/IDLEventListener.h> #include <LibWeb/DOM/IDLEventListener.h>
#include <LibWeb/DOM/ShadowRoot.h> #include <LibWeb/DOM/ShadowRoot.h>
@ -45,7 +46,9 @@ JS::ThrowCompletionOr<void> HTMLElement::initialize(JS::Realm& realm)
MUST_OR_THROW_OOM(Base::initialize(realm)); MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLElementPrototype>(realm, "HTMLElement")); set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLElementPrototype>(realm, "HTMLElement"));
m_dataset = DOMStringMap::create(*this); m_dataset = TRY(Bindings::throw_dom_exception_if_needed(realm.vm(), [&]() {
return DOMStringMap::create(*this);
}));
return {}; return {};
} }

View file

@ -12,7 +12,7 @@ namespace Web::SVG {
SVGElement::SVGElement(DOM::Document& document, DOM::QualifiedName qualified_name) SVGElement::SVGElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: Element(document, move(qualified_name)) : Element(document, move(qualified_name))
, m_dataset(HTML::DOMStringMap::create(*this)) , m_dataset(HTML::DOMStringMap::create(*this).release_value_but_fixme_should_propagate_errors())
{ {
} }