diff --git a/Userland/Libraries/LibGfx/PaintStyle.h b/Userland/Libraries/LibGfx/PaintStyle.h index ad0e2d39c3..6d377af03f 100644 --- a/Userland/Libraries/LibGfx/PaintStyle.h +++ b/Userland/Libraries/LibGfx/PaintStyle.h @@ -43,9 +43,9 @@ private: class SolidColorPaintStyle final : public PaintStyle { public: - static NonnullRefPtr create(Color color) + static ErrorOr> create(Color color) { - return adopt_ref(*new SolidColorPaintStyle(color)); + return adopt_nonnull_ref_or_enomem(new (nothrow) SolidColorPaintStyle(color)); } virtual Color sample_color(IntPoint) const override { return m_color; } @@ -91,9 +91,9 @@ private: class LinearGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(float angle = 0.0f) + static ErrorOr>> create(float angle = 0.0f) { - return adopt_ref(*new LinearGradientPaintStyle(angle)); + return adopt_nonnull_ref_or_enomem(new (nothrow) LinearGradientPaintStyle(angle)); } private: @@ -109,9 +109,9 @@ private: class ConicGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(IntPoint center, float start_angle = 0.0f) + static ErrorOr> create(IntPoint center, float start_angle = 0.0f) { - return adopt_ref(*new ConicGradientPaintStyle(center, start_angle)); + return adopt_nonnull_ref_or_enomem(new (nothrow) ConicGradientPaintStyle(center, start_angle)); } private: @@ -129,9 +129,9 @@ private: class RadialGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(IntPoint center, IntSize size) + static ErrorOr> create(IntPoint center, IntSize size) { - return adopt_ref(*new RadialGradientPaintStyle(center, size)); + return adopt_nonnull_ref_or_enomem(new (nothrow) RadialGradientPaintStyle(center, size)); } private: @@ -153,9 +153,9 @@ private: class CanvasLinearGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(FloatPoint p0, FloatPoint p1) + static ErrorOr> create(FloatPoint p0, FloatPoint p1) { - return adopt_ref(*new CanvasLinearGradientPaintStyle(p0, p1)); + return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasLinearGradientPaintStyle(p0, p1)); } private: @@ -173,9 +173,9 @@ private: class CanvasConicGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(FloatPoint center, float start_angle = 0.0f) + static ErrorOr> create(FloatPoint center, float start_angle = 0.0f) { - return adopt_ref(*new CanvasConicGradientPaintStyle(center, start_angle)); + return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasConicGradientPaintStyle(center, start_angle)); } private: @@ -193,9 +193,9 @@ private: class CanvasRadialGradientPaintStyle final : public GradientPaintStyle { public: - static NonnullRefPtr create(FloatPoint start_center, float start_radius, FloatPoint end_center, float end_radius) + static ErrorOr> create(FloatPoint start_center, float start_radius, FloatPoint end_center, float end_radius) { - return adopt_ref(*new CanvasRadialGradientPaintStyle(start_center, start_radius, end_center, end_radius)); + return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasRadialGradientPaintStyle(start_center, start_radius, end_center, end_radius)); } private: diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp index d20f69542b..c6a7a594a8 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp @@ -45,7 +45,7 @@ NonnullRefPtr CanvasState::FillOrStrokeStyle::to_gfx_paint_styl return m_fill_or_stroke_style.visit( [&](Gfx::Color color) -> NonnullRefPtr { if (!m_color_paint_style) - m_color_paint_style = Gfx::SolidColorPaintStyle::create(color); + m_color_paint_style = Gfx::SolidColorPaintStyle::create(color).release_value_but_fixme_should_propagate_errors(); return m_color_paint_style.release_nonnull(); }, [&](auto handle) { diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp index b471f8f328..0fa6e87789 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp @@ -21,21 +21,21 @@ WebIDL::ExceptionOr> CanvasGradient::create_rad if (r1 < 0) return WebIDL::IndexSizeError::create(realm, "The r1 passed is less than 0"); - auto radial_gradient = Gfx::CanvasRadialGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, r0, Gfx::FloatPoint { x1, y1 }, r1); + auto radial_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasRadialGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, r0, Gfx::FloatPoint { x1, y1 }, r1)); return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, *radial_gradient)); } // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createlineargradient WebIDL::ExceptionOr> CanvasGradient::create_linear(JS::Realm& realm, double x0, double y0, double x1, double y1) { - auto linear_gradient = Gfx::CanvasLinearGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, Gfx::FloatPoint { x1, y1 }); + auto linear_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasLinearGradientPaintStyle::create(Gfx::FloatPoint { x0, y0 }, Gfx::FloatPoint { x1, y1 })); return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, *linear_gradient)); } // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createconicgradient WebIDL::ExceptionOr> CanvasGradient::create_conic(JS::Realm& realm, double start_angle, double x, double y) { - auto conic_gradient = Gfx::CanvasConicGradientPaintStyle::create(Gfx::FloatPoint { x, y }, start_angle); + auto conic_gradient = TRY_OR_THROW_OOM(realm.vm(), Gfx::CanvasConicGradientPaintStyle::create(Gfx::FloatPoint { x, y }, start_angle)); return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, *conic_gradient)); } diff --git a/Userland/Libraries/LibWeb/HTML/CanvasPattern.cpp b/Userland/Libraries/LibWeb/HTML/CanvasPattern.cpp index 2fa1a89ee8..7bb2cd4077 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasPattern.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasPattern.cpp @@ -125,7 +125,7 @@ WebIDL::ExceptionOr> CanvasPattern::create(JS::Realm& r auto const& bitmap = *image.visit([](auto const& source) -> Gfx::Bitmap const* { return source->bitmap(); }); // 6. Let pattern be a new CanvasPattern object with the image image and the repetition behavior given by repetition. - auto pattern = CanvasPatternPaintStyle::create(bitmap, *repetition_value); + auto pattern = TRY_OR_THROW_OOM(realm.vm(), CanvasPatternPaintStyle::create(bitmap, *repetition_value)); // FIXME: 7. If image is not origin-clean, then mark pattern as not origin-clean. diff --git a/Userland/Libraries/LibWeb/HTML/CanvasPattern.h b/Userland/Libraries/LibWeb/HTML/CanvasPattern.h index d8c7fc10f8..7bfb11192d 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasPattern.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasPattern.h @@ -21,9 +21,9 @@ public: NoRepeat }; - static NonnullRefPtr create(Gfx::Bitmap const& bitmap, Repetition repetition) + static ErrorOr> create(Gfx::Bitmap const& bitmap, Repetition repetition) { - return adopt_ref(*new CanvasPatternPaintStyle(bitmap, repetition)); + return adopt_nonnull_ref_or_enomem(new (nothrow) CanvasPatternPaintStyle(bitmap, repetition)); } virtual void paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const override;