Przeglądaj źródła

LibWeb: Make factory method of SVG::SVGAnimatedLength fallible

Kenneth Myhra 2 lat temu
rodzic
commit
63b69f3672

+ 2 - 2
Userland/Libraries/LibWeb/SVG/SVGAnimatedLength.cpp

@@ -9,9 +9,9 @@
 
 namespace Web::SVG {
 
-JS::NonnullGCPtr<SVGAnimatedLength> SVGAnimatedLength::create(JS::Realm& realm, JS::NonnullGCPtr<SVGLength> base_val, JS::NonnullGCPtr<SVGLength> anim_val)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> SVGAnimatedLength::create(JS::Realm& realm, JS::NonnullGCPtr<SVGLength> base_val, JS::NonnullGCPtr<SVGLength> anim_val)
 {
-    return realm.heap().allocate<SVGAnimatedLength>(realm, realm, move(base_val), move(anim_val)).release_allocated_value_but_fixme_should_propagate_errors();
+    return MUST_OR_THROW_OOM(realm.heap().allocate<SVGAnimatedLength>(realm, realm, move(base_val), move(anim_val)));
 }
 
 SVGAnimatedLength::SVGAnimatedLength(JS::Realm& realm, JS::NonnullGCPtr<SVGLength> base_val, JS::NonnullGCPtr<SVGLength> anim_val)

+ 1 - 1
Userland/Libraries/LibWeb/SVG/SVGAnimatedLength.h

@@ -16,7 +16,7 @@ class SVGAnimatedLength final : public Bindings::PlatformObject {
     WEB_PLATFORM_OBJECT(SVGAnimatedLength, Bindings::PlatformObject);
 
 public:
-    static JS::NonnullGCPtr<SVGAnimatedLength> create(JS::Realm&, JS::NonnullGCPtr<SVGLength> base_val, JS::NonnullGCPtr<SVGLength> anim_val);
+    static WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGAnimatedLength>> create(JS::Realm&, JS::NonnullGCPtr<SVGLength> base_val, JS::NonnullGCPtr<SVGLength> anim_val);
     virtual ~SVGAnimatedLength() override;
 
     JS::NonnullGCPtr<SVGLength> base_val() const { return m_base_val; }

+ 3 - 3
Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp

@@ -86,7 +86,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::cx() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#CircleElementCYAttribute
@@ -96,7 +96,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::cy() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#CircleElementRAttribute
@@ -106,7 +106,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::r() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 }

+ 4 - 4
Userland/Libraries/LibWeb/SVG/SVGEllipseElement.cpp

@@ -91,7 +91,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGEllipseElement::cx() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#EllipseElementCYAttribute
@@ -101,7 +101,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGEllipseElement::cy() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#EllipseElementRXAttribute
@@ -111,7 +111,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGEllipseElement::rx() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#EllipseElementRYAttribute
@@ -121,7 +121,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGEllipseElement::ry() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 }

+ 15 - 4
Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include <LibWeb/Bindings/ExceptionOrUtils.h>
 #include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/HTML/Parser/HTMLParser.h>
 #include <LibWeb/Layout/BlockContainer.h>
@@ -23,14 +24,24 @@ SVGForeignObjectElement::~SVGForeignObjectElement() = default;
 
 JS::ThrowCompletionOr<void> SVGForeignObjectElement::initialize(JS::Realm& realm)
 {
+    auto& vm = realm.vm();
+
     MUST_OR_THROW_OOM(Base::initialize(realm));
     set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGForeignObjectElementPrototype>(realm, "SVGForeignObjectElement"));
 
     // FIXME: These never actually get updated!
-    m_x = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
-    m_y = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
-    m_width = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
-    m_height = SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), SVGLength::create(realm, 0, 0));
+    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_y = 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, [&]() {
+        return SVGAnimatedLength::create(realm, SVGLength::create(realm, 0, 0), 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));
+    }));
 
     return {};
 }

+ 4 - 4
Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp

@@ -71,7 +71,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGLineElement::x1() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#LineElementY1Attribute
@@ -81,7 +81,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGLineElement::y1() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#LineElementX2Attribute
@@ -91,7 +91,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGLineElement::x2() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#LineElementY2Attribute
@@ -101,7 +101,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGLineElement::y2() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 }

+ 6 - 6
Userland/Libraries/LibWeb/SVG/SVGRectElement.cpp

@@ -168,7 +168,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::x() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#RectElementYAttribute
@@ -178,7 +178,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::y() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#RectElementWidthAttribute
@@ -188,7 +188,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::width() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#RectElementHeightAttribute
@@ -198,7 +198,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::height() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#RectElementRXAttribute
@@ -208,7 +208,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::rx() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 // https://www.w3.org/TR/SVG11/shapes.html#RectElementRYAttribute
@@ -218,7 +218,7 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGRectElement::ry() const
     // 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));
-    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length));
+    return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)).release_value_but_fixme_should_propagate_errors();
 }
 
 }