LibWeb: Check radius sign in CanvasRenderingContext2D::{arc, ellipse}

As required by the specification: 'If either radiusX or radiusY are
negative, then throw an "IndexSizeError" DOMException.'
This commit is contained in:
Idan Horowitz 2021-04-15 20:38:43 +03:00 committed by Andreas Kling
parent 00114ab01d
commit c5769a7033
Notes: sideshowbarker 2024-07-18 20:17:56 +09:00
2 changed files with 14 additions and 5 deletions

View File

@ -204,13 +204,21 @@ void CanvasRenderingContext2D::quadratic_curve_to(float cx, float cy, float x, f
m_path.quadratic_bezier_curve_to({ cx, cy }, { x, y });
}
void CanvasRenderingContext2D::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise)
DOM::ExceptionOr<void> CanvasRenderingContext2D::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise)
{
ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise);
if (radius < 0)
return DOM::IndexSizeError::create(String::formatted("The radius provided ({}) is negative.", radius));
return ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise);
}
void CanvasRenderingContext2D::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise)
DOM::ExceptionOr<void> CanvasRenderingContext2D::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise)
{
if (radius_x < 0)
return DOM::IndexSizeError::create(String::formatted("The major-axis radius provided ({}) is negative.", radius_x));
if (radius_y < 0)
return DOM::IndexSizeError::create(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
if ((!counter_clockwise && (end_angle - start_angle) >= M_TAU)
|| (counter_clockwise && (start_angle - end_angle) >= M_TAU)) {
start_angle = 0;
@ -261,6 +269,7 @@ void CanvasRenderingContext2D::ellipse(float x, float y, float radius_x, float r
m_path.elliptical_arc_to(end_point, { radius_x, radius_y }, rotation, delta_theta > M_PI, !counter_clockwise);
m_path.close();
return {};
}
void CanvasRenderingContext2D::rect(float x, float y, float width, float height)

View File

@ -75,8 +75,8 @@ public:
void line_to(float x, float y);
void quadratic_curve_to(float cx, float cy, float x, float y);
void arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise);
void ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise);
DOM::ExceptionOr<void> arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise);
DOM::ExceptionOr<void> ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise);
void rect(float x, float y, float width, float height);
void stroke();