From 71316614b87713aeb2f952fda6635a980c8431eb Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Wed, 15 Feb 2023 20:25:50 +0100 Subject: [PATCH] LibWeb: Make factory method of SVG::SVGLength fallible --- .../Libraries/LibWeb/SVG/SVGCircleElement.cpp | 12 +++++----- .../LibWeb/SVG/SVGEllipseElement.cpp | 16 ++++++------- .../LibWeb/SVG/SVGForeignObjectElement.cpp | 16 ++++++------- Userland/Libraries/LibWeb/SVG/SVGLength.cpp | 4 ++-- Userland/Libraries/LibWeb/SVG/SVGLength.h | 2 +- .../Libraries/LibWeb/SVG/SVGLineElement.cpp | 16 ++++++------- .../Libraries/LibWeb/SVG/SVGRectElement.cpp | 24 +++++++++---------- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp index 5af992448f..efb0a645e3 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp @@ -84,8 +84,8 @@ JS::NonnullGCPtr SVGCircleElement::cx() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -94,8 +94,8 @@ JS::NonnullGCPtr SVGCircleElement::cy() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -104,8 +104,8 @@ JS::NonnullGCPtr SVGCircleElement::r() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_radius.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_radius.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_radius.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_radius.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } diff --git a/Userland/Libraries/LibWeb/SVG/SVGEllipseElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGEllipseElement.cpp index 26a4f11a34..0bb5a9f453 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGEllipseElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGEllipseElement.cpp @@ -89,8 +89,8 @@ JS::NonnullGCPtr SVGEllipseElement::cx() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_center_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -99,8 +99,8 @@ JS::NonnullGCPtr SVGEllipseElement::cy() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_center_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -109,8 +109,8 @@ JS::NonnullGCPtr SVGEllipseElement::rx() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -119,8 +119,8 @@ JS::NonnullGCPtr SVGEllipseElement::ry() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } diff --git a/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp index ecd217dee7..6ad9d19c36 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp @@ -30,17 +30,17 @@ JS::ThrowCompletionOr SVGForeignObjectElement::initialize(JS::Realm& realm set_prototype(&Bindings::ensure_web_prototype(realm, "SVGForeignObjectElement")); // FIXME: These never actually get updated! - m_x = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { - return SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0)); + m_x = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr> { + return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); })); - m_y = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { - return SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0)); + m_y = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr> { + return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); })); - m_width = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { - return SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0)); + m_width = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr> { + return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); })); - m_height = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() { - return SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0)); + m_height = TRY(Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr> { + return SVGAnimatedLength::create(realm, TRY(SVGLength::create(realm, 0, 0)), TRY(SVGLength::create(realm, 0, 0))); })); return {}; diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.cpp b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp index 56f6f6e537..488c9a6146 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLength.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.cpp @@ -9,9 +9,9 @@ namespace Web::SVG { -JS::NonnullGCPtr SVGLength::create(JS::Realm& realm, u8 unit_type, float value) +WebIDL::ExceptionOr> SVGLength::create(JS::Realm& realm, u8 unit_type, float value) { - return realm.heap().allocate(realm, realm, unit_type, value).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, unit_type, value)); } SVGLength::SVGLength(JS::Realm& realm, u8 unit_type, float value) diff --git a/Userland/Libraries/LibWeb/SVG/SVGLength.h b/Userland/Libraries/LibWeb/SVG/SVGLength.h index 400fb7ae41..5e9c469aa2 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLength.h +++ b/Userland/Libraries/LibWeb/SVG/SVGLength.h @@ -16,7 +16,7 @@ class SVGLength : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(SVGLength, Bindings::PlatformObject); public: - static JS::NonnullGCPtr create(JS::Realm&, u8 unit_type, float value); + static WebIDL::ExceptionOr> create(JS::Realm&, u8 unit_type, float value); virtual ~SVGLength() override; u8 unit_type() const { return m_unit_type; } diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp index 8f6d3da945..8fa06e4799 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp @@ -69,8 +69,8 @@ JS::NonnullGCPtr SVGLineElement::x1() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_x1.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_x1.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_x1.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_x1.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -79,8 +79,8 @@ JS::NonnullGCPtr SVGLineElement::y1() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_y1.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_y1.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_y1.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_y1.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -89,8 +89,8 @@ JS::NonnullGCPtr SVGLineElement::x2() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_x2.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_x2.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_x2.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_x2.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -99,8 +99,8 @@ JS::NonnullGCPtr SVGLineElement::y2() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_y2.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_y2.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_y2.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_y2.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } diff --git a/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp index f2c3cf83c1..005a4325c1 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp @@ -166,8 +166,8 @@ JS::NonnullGCPtr SVGRectElement::x() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_x.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_x.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -176,8 +176,8 @@ JS::NonnullGCPtr SVGRectElement::y() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_y.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_y.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -186,8 +186,8 @@ JS::NonnullGCPtr SVGRectElement::width() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_width.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_width.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_width.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_width.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -196,8 +196,8 @@ JS::NonnullGCPtr SVGRectElement::height() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_height.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_height.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_height.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_height.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -206,8 +206,8 @@ JS::NonnullGCPtr SVGRectElement::rx() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_radius_x.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); } @@ -216,8 +216,8 @@ JS::NonnullGCPtr SVGRectElement::ry() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); + auto anim_length = SVGLength::create(realm(), 0, m_radius_y.value_or(0)).release_value_but_fixme_should_propagate_errors(); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors(); }