diff options
author | MacDue <macdue@dueutil.tech> | 2023-01-28 00:05:10 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-28 00:26:48 +0000 |
commit | f86b66dc2d139ab43efeaada00e741c5227d1b93 (patch) | |
tree | efbd711ac8145f8c57892e1d904459bf03f25207 /Userland | |
parent | 8dc4e05ecfc1d5176acf2d64012685dd52ee12bc (diff) | |
download | serenity-f86b66dc2d139ab43efeaada00e741c5227d1b93.zip |
LibWeb: Throw exception if any canvas radial gradient radius is < 0
As per the specification:
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createradialgradient
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CanvasGradient.h | 2 |
3 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h index 3ed170f201..5ff5703610 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h @@ -55,7 +55,7 @@ public: return my_drawing_state().stroke_style.to_js_fill_or_stoke_style(); } - JS::NonnullGCPtr<CanvasGradient> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1) + WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1) { auto& realm = static_cast<IncludingClass&>(*this).realm(); return CanvasGradient::create_radial(realm, x0, y0, r0, x1, y1, r1); diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp index b53ef96a12..ecb3405e1d 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp @@ -12,8 +12,15 @@ namespace Web::HTML { -JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(JS::Realm& realm, double x0, double y0, double r0, double x1, double y1, double r1) +// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createradialgradient +WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> CanvasGradient::create_radial(JS::Realm& realm, double x0, double y0, double r0, double x1, double y1, double r1) { + // If either of r0 or r1 are negative, then an "IndexSizeError" DOMException must be thrown. + if (r0 < 0) + return WebIDL::IndexSizeError::create(realm, "The r0 passed is less than 0"); + 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); return realm.heap().allocate<CanvasGradient>(realm, realm, *radial_gradient); } diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.h b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h index 583ae088ef..c0ad7a78af 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasGradient.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h @@ -16,7 +16,7 @@ class CanvasGradient final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(CanvasGradient, Bindings::PlatformObject); public: - static JS::NonnullGCPtr<CanvasGradient> create_radial(JS::Realm&, double x0, double y0, double r0, double x1, double y1, double r1); + static WebIDL::ExceptionOr<JS::NonnullGCPtr<CanvasGradient>> create_radial(JS::Realm&, double x0, double y0, double r0, double x1, double y1, double r1); static JS::NonnullGCPtr<CanvasGradient> create_linear(JS::Realm&, double x0, double y0, double x1, double y1); static JS::NonnullGCPtr<CanvasGradient> create_conic(JS::Realm&, double start_angle, double x, double y); |