Commit bca17f29 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Path2D.addPath should throw if DOMMatrix validation fails

Step two of [1], invokes [2], whose step 1 invokes [3], which says to
throw a TypeError if the dictionary is not "well-formed".

Also remove some dead code in DOMMatrix/DOMMatrixReadOnly and remove few
unused includes of svg_matrix_tear_off.h.

[1] https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d-addpath
[2] https://drafts.fxtf.org/geometry/#create-a-dommatrix-from-the-2d-dictionary
[3] https://drafts.fxtf.org/geometry/#matrix-validate-and-fixup-2d

Bug: 895244
Change-Id: Icd3f7058ce945d761ab7128e294ccc2e3fd3a879
Reviewed-on: https://chromium-review.googlesource.com/c/1278789Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#599723}
parent 7b5dde84
This is a testharness.js-based test.
Found 184 tests; 172 PASS, 12 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 184 tests; 178 PASS, 6 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS setTransform({a: 1, m11: 2}) (invalid)
FAIL addPath({a: 1, m11: 2}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({a: 1, m11: 2}) (invalid)
PASS setTransform({b: 0, m12: -1}) (invalid)
FAIL addPath({b: 0, m12: -1}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({b: 0, m12: -1}) (invalid)
PASS setTransform({c: Infinity, m21: -Infinity}) (invalid)
FAIL addPath({c: Infinity, m21: -Infinity}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({c: Infinity, m21: -Infinity}) (invalid)
PASS setTransform({d: 0, m22: NaN}) (invalid)
FAIL addPath({d: 0, m22: NaN}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({d: 0, m22: NaN}) (invalid)
PASS setTransform({e: 1, m41: 1.00000001}) (invalid)
FAIL addPath({e: 1, m41: 1.00000001}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({e: 1, m41: 1.00000001}) (invalid)
PASS setTransform({f: 0, m42: 5e-324}) (invalid)
FAIL addPath({f: 0, m42: 5e-324}) (invalid) assert_throws: function "() => drawRectWithAddPathTransform(ctx, dict)" did not throw
PASS addPath({f: 0, m42: 5e-324}) (invalid)
PASS setTransform (Sanity check without dictionary)
PASS addPath (Sanity check without second parameter)
PASS setTransform({m13: 1, is2D: true})
......
......@@ -97,15 +97,6 @@ DOMMatrix::DOMMatrix(T sequence, int size)
DOMMatrix::DOMMatrix(const TransformationMatrix& matrix, bool is2d)
: DOMMatrixReadOnly(matrix, is2d) {}
DOMMatrix* DOMMatrix::fromMatrix2D(DOMMatrix2DInit& other) {
if (!ValidateAndFixup2D(other)) {
return nullptr;
}
return new DOMMatrix({other.m11(), other.m12(), other.m21(), other.m22(),
other.m41(), other.m42()},
true);
}
DOMMatrix* DOMMatrix::fromMatrix(DOMMatrixInit& other,
ExceptionState& exception_state) {
if (!ValidateAndFixup(other, exception_state)) {
......
......@@ -33,8 +33,6 @@ class CORE_EXPORT DOMMatrix : public DOMMatrixReadOnly {
ExceptionState&);
static DOMMatrix* fromMatrix(DOMMatrixInit&, ExceptionState&);
static DOMMatrix* CreateForSerialization(double[], int size);
// Used by Canvas2D, not defined on the IDL.
static DOMMatrix* fromMatrix2D(DOMMatrix2DInit&);
void setA(double value) { matrix_->SetM11(value); }
void setB(double value) { matrix_->SetM12(value); }
......
......@@ -182,15 +182,6 @@ DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix2D(
return new DOMMatrixReadOnly(args, 6);
}
DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix2D(DOMMatrix2DInit& other) {
if (!ValidateAndFixup2D(other)) {
return nullptr;
}
double args[] = {other.m11(), other.m12(), other.m21(),
other.m22(), other.m41(), other.m42()};
return new DOMMatrixReadOnly(args, 6);
}
DOMMatrixReadOnly* DOMMatrixReadOnly::fromMatrix(
DOMMatrixInit& other,
ExceptionState& exception_state) {
......
......@@ -40,8 +40,6 @@ class CORE_EXPORT DOMMatrixReadOnly : public ScriptWrappable {
static DOMMatrixReadOnly* fromMatrix2D(DOMMatrix2DInit&, ExceptionState&);
static DOMMatrixReadOnly* CreateForSerialization(double[], int size);
~DOMMatrixReadOnly() override;
// Used by Canvas2D, not defined on the IDL.
static DOMMatrixReadOnly* fromMatrix2D(DOMMatrix2DInit&);
double a() const { return matrix_->M11(); }
double b() const { return matrix_->M12(); }
......
......@@ -27,9 +27,9 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_PATTERN_H_
#include "third_party/blink/renderer/core/geometry/dom_matrix_2d_init.h"
#include "third_party/blink/renderer/core/svg/svg_matrix_tear_off.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/graphics/pattern.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
......
......@@ -31,7 +31,6 @@
#include "third_party/blink/renderer/bindings/modules/v8/path_2d_or_string.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix_2d_init.h"
#include "third_party/blink/renderer/core/svg/svg_matrix_tear_off.h"
#include "third_party/blink/renderer/core/svg/svg_path_utilities.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_path.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
......@@ -40,6 +39,8 @@
namespace blink {
class ExceptionState;
class MODULES_EXPORT Path2D final : public ScriptWrappable, public CanvasPath {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(Path2D);
......@@ -59,17 +60,14 @@ class MODULES_EXPORT Path2D final : public ScriptWrappable, public CanvasPath {
const Path& GetPath() const { return path_; }
void addPath(Path2D* path) {
DOMMatrix2DInit transform;
addPath(path, transform);
}
void addPath(Path2D* path, DOMMatrix2DInit& transform) {
Path src = path->GetPath();
DOMMatrixReadOnly* m = nullptr;
m = DOMMatrixReadOnly::fromMatrix2D(transform);
path_.AddPath(
src, m ? m->GetAffineTransform() : AffineTransform(1, 0, 0, 1, 0, 0));
void addPath(Path2D* path,
DOMMatrix2DInit& transform,
ExceptionState& exception_state) {
DOMMatrixReadOnly* matrix =
DOMMatrixReadOnly::fromMatrix2D(transform, exception_state);
if (!matrix)
return;
path_.AddPath(path->GetPath(), matrix->GetAffineTransform());
}
~Path2D() override = default;
......
......@@ -32,8 +32,7 @@
Constructor(optional (Path2D or DOMString) path),
Exposed(Worker OffscreenCanvas, Window StableBlinkFeatures, PaintWorklet StableBlinkFeatures)
] interface Path2D {
void addPath(Path2D path, optional DOMMatrix2DInit transform);
[RaisesException] void addPath(Path2D path, optional DOMMatrix2DInit transform);
};
Path2D implements CanvasPath;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment