From 9b190b9509ad6d05a564bf88cbe3345cd2364afe Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sun, 19 Feb 2023 18:16:49 +0100 Subject: [PATCH] LibWeb: Make factory method of Geometry::DOMRectList fallible --- Userland/Libraries/LibWeb/DOM/Element.cpp | 4 ++-- Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp | 5 +++-- Userland/Libraries/LibWeb/Geometry/DOMRectList.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 14e00f2165..fc6f32f160 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -675,7 +675,7 @@ JS::NonnullGCPtr Element::get_client_rects() const // 1. If the element on which it was invoked does not have an associated layout box return an empty DOMRectList object and stop this algorithm. if (!layout_node() || !layout_node()->is_box()) - return Geometry::DOMRectList::create(realm(), move(rects)); + return Geometry::DOMRectList::create(realm(), move(rects)).release_value_but_fixme_should_propagate_errors(); // FIXME: 2. If the element has an associated SVG layout box return a DOMRectList object containing a single DOMRect object that describes // the bounding box of the element as defined by the SVG specification, applying the transforms that apply to the element and its ancestors. @@ -689,7 +689,7 @@ JS::NonnullGCPtr Element::get_client_rects() const auto bounding_rect = get_bounding_client_rect(); rects.append(*bounding_rect); - return Geometry::DOMRectList::create(realm(), move(rects)); + return Geometry::DOMRectList::create(realm(), move(rects)).release_value_but_fixme_should_propagate_errors(); } int Element::client_top() const diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp index 788e6ce56c..ea0436fe51 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp @@ -8,15 +8,16 @@ #include #include #include +#include namespace Web::Geometry { -JS::NonnullGCPtr DOMRectList::create(JS::Realm& realm, Vector> rect_handles) +WebIDL::ExceptionOr> DOMRectList::create(JS::Realm& realm, Vector> rect_handles) { Vector> rects; for (auto& rect : rect_handles) rects.append(*rect); - return realm.heap().allocate(realm, realm, move(rects)).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, move(rects))); } DOMRectList::DOMRectList(JS::Realm& realm, Vector> rects) diff --git a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h index cf43ff88c0..89d3dfe12f 100644 --- a/Userland/Libraries/LibWeb/Geometry/DOMRectList.h +++ b/Userland/Libraries/LibWeb/Geometry/DOMRectList.h @@ -17,7 +17,7 @@ class DOMRectList final : public Bindings::LegacyPlatformObject { WEB_PLATFORM_OBJECT(DOMRectList, Bindings::LegacyPlatformObject); public: - static JS::NonnullGCPtr create(JS::Realm&, Vector>); + static WebIDL::ExceptionOr> create(JS::Realm&, Vector>); virtual ~DOMRectList() override;