LibWeb: Make factory method of SVG::SVGAnimatedLength fallible

This commit is contained in:
Kenneth Myhra 2023-02-15 08:43:44 +01:00 committed by Linus Groh
parent 200d22c650
commit 63b69f3672
Notes: sideshowbarker 2024-07-17 04:57:23 +09:00
7 changed files with 35 additions and 24 deletions

View file

@ -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)

View file

@ -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; }

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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 {};
}

View file

@ -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();
}
}

View file

@ -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();
}
}