tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e4cc157668baf877d2522084ce8ecc855b37eb3e
parent ad1956128aafd2f0ec08ba0b39b2b272082edd27
Author: longsonr <longsonr@gmail.com>
Date:   Tue, 30 Sep 2025 12:45:21 +0000

Bug 1991462 - Make SVGMatrix::Multiply take a DOMMatrixInit rather than SVGMatrix r=emilio,webidl

Differential Revision: https://phabricator.services.mozilla.com/D266686

Diffstat:
Mdom/svg/SVGMatrix.cpp | 14++++++++++++--
Mdom/svg/SVGMatrix.h | 5++++-
Mdom/svg/test/test_SVGMatrix.xhtml | 40+++++++++++++++++++---------------------
Mdom/webidl/SVGMatrix.webidl | 8+++++---
Mdom/webidl/SVGPoint.webidl | 4+++-
Mdom/webidl/SVGRect.webidl | 4+++-
6 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/dom/svg/SVGMatrix.cpp b/dom/svg/SVGMatrix.cpp @@ -9,6 +9,7 @@ #include <math.h> #include "mozilla/FloatingPoint.h" +#include "mozilla/dom/DOMMatrix.h" #include "mozilla/dom/SVGMatrixBinding.h" #include "nsError.h" @@ -91,8 +92,17 @@ void SVGMatrix::SetF(float aF, ErrorResult& aRv) { SetMatrix(mx); } -already_AddRefed<SVGMatrix> SVGMatrix::Multiply(SVGMatrix& aMatrix) { - return do_AddRef(new SVGMatrix(aMatrix.GetMatrix() * GetMatrix())); +already_AddRefed<SVGMatrix> SVGMatrix::Multiply(const DOMMatrix2DInit& aMatrix, + ErrorResult& aRv) { + auto matrix2D = DOMMatrixReadOnly::ToValidatedMatrixDouble(aMatrix, aRv); + if (aRv.Failed()) { + return nullptr; + } + if (!matrix2D.IsFinite()) { + aRv.ThrowTypeError<MSG_NOT_FINITE>("SVGMatrix::Multiply matrix"); + return nullptr; + } + return do_AddRef(new SVGMatrix(matrix2D * GetMatrix())); } already_AddRefed<SVGMatrix> SVGMatrix::Inverse(ErrorResult& aRv) { diff --git a/dom/svg/SVGMatrix.h b/dom/svg/SVGMatrix.h @@ -45,6 +45,8 @@ namespace mozilla::dom { +struct DOMMatrix2DInit; + /** * DOM wrapper for an SVG matrix. */ @@ -83,7 +85,8 @@ class SVGMatrix final : public nsWrapperCache { void SetE(float aE, ErrorResult& aRv); float F() const { return static_cast<float>(GetMatrix()._32); } void SetF(float aF, ErrorResult& aRv); - already_AddRefed<SVGMatrix> Multiply(SVGMatrix& aMatrix); + already_AddRefed<SVGMatrix> Multiply(const DOMMatrix2DInit& aMatrix, + ErrorResult& aRv); already_AddRefed<SVGMatrix> Inverse(ErrorResult& aRv); already_AddRefed<SVGMatrix> Translate(float x, float y); already_AddRefed<SVGMatrix> Scale(float scaleFactor); diff --git a/dom/svg/test/test_SVGMatrix.xhtml b/dom/svg/test/test_SVGMatrix.xhtml @@ -19,7 +19,7 @@ SimpleTest.waitForExplicitFinish(); function main() { - var tests = + let tests = [ testCreateMatrix, testMultiply, testInverse, @@ -33,19 +33,19 @@ function main() { testSkewX, testSkewY, ]; - for (var i = 0; i < tests.length; i++) { + for (let i = 0; i < tests.length; i++) { tests[i](); } SimpleTest.finish(); } function testCreateMatrix() { - var svg = $("svg"); - var m = svg.createSVGMatrix(); + let svg = $("svg"); + let m = svg.createSVGMatrix(); // Should be initialised to identity cmpMatrix(m, [1, 0, 0, 1, 0, 0], - "createMatrix should produce identity matrix"); + "createSVGMatrix should produce identity matrix"); // Should return a new object each time; ok(m != svg.createSVGMatrix(), @@ -55,10 +55,9 @@ function testCreateMatrix() { // SVGMatrix multiply(in SVGMatrix secondMatrix); function testMultiply() { // This is the example from SVG 1.1 section 7.5 - var m1 = createMatrix(1, 0, 0, 1, 50, 90); - var m2 = createMatrix(0.707, -0.707, 0.707, 0.707, 0, 0); - var m3 = createMatrix(1, 0, 0, 1, 130, 160); - var result = m1.multiply(m2).multiply(m3); + let m1 = createMatrix(1, 0, 0, 1, 50, 90); + let m2 = createMatrix(0.707, -0.707, 0.707, 0.707, 0, 0); + let result = m1.multiply(m2).multiply({a:1, b: 0, c: 0, d: 1, e: 130, f: 160}); roughCmpMatrix(result, [0.707, -0.707, 0.707, 0.707, 255.03, 111.21], "Unexpected result after multiplying matrices"); @@ -66,13 +65,12 @@ function testMultiply() { cmpMatrix(m1, [1, 0, 0, 1, 50, 90], "Matrix changed after multiplication"); roughCmpMatrix(m2, [0.707, -0.707, 0.707, 0.707, 0, 0], "Matrix changed after multiplication"); - cmpMatrix(m3, [1, 0, 0, 1, 130, 160], "Matrix changed after multiplication"); } // SVGMatrix inverse() raises(SVGException); function testInverse() { // Test inversion - var m = createMatrix(2, 0, 0, 4, 110, -50); + let m = createMatrix(2, 0, 0, 4, 110, -50); roughCmpMatrix(m.inverse(), [0.5, 0, 0, 0.25, -55, 12.5], "Unexpected result after inverting matrix"); @@ -89,28 +87,28 @@ function testInverse() { // SVGMatrix translate(in float x, in float y); function testTranslate() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.translate(100, -50), [2, 0, 0, 1, 320, 50], "Unexpected result after translate"); } // SVGMatrix scale(in float scaleFactor); function testScale() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.scale(0.5), [1, 0, 0, 0.5, 120, 100], "Unexpected result after scale"); } // SVGMatrix scaleNonUniform(in float scaleFactorX, in float scaleFactorY); function testScaleNonUniform() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.scaleNonUniform(0.5, -3), [1, 0, 0, -3, 120, 100], "Unexpected result after scaleNonUniform"); } // SVGMatrix rotate(in float angle); function testRotate() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.rotate(45), [2 * Math.cos(Math.PI / 4), Math.sin(Math.PI / 4), 2 * -Math.sin(Math.PI / 4), Math.cos(Math.PI / 4), @@ -120,9 +118,9 @@ function testRotate() { // SVGMatrix rotateFromVector(in float x, in float y) raises(SVGException); function testRotateFromVector() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); // Make a 150 degree angle - var result = m.rotateFromVector(-2, 1.1547); + let result = m.rotateFromVector(-2, 1.1547); roughCmpMatrix(result, [2 * Math.cos(5 * Math.PI / 6), Math.sin(5 * Math.PI / 6), 2 * -Math.sin(5 * Math.PI / 6), Math.cos(5 * Math.PI / 6), @@ -147,26 +145,26 @@ function testRotateFromVector() { // SVGMatrix flipX(); function testFlipX() { - var m = createMatrix(1, 2, 3, 4, 5, 6); + let m = createMatrix(1, 2, 3, 4, 5, 6); cmpMatrix(m.flipX(), [-1, -2, 3, 4, 5, 6], "Unexpected result after flipX"); } // SVGMatrix flipY(); function testFlipY() { - var m = createMatrix(1, 2, 3, 4, 5, 6); + let m = createMatrix(1, 2, 3, 4, 5, 6); cmpMatrix(m.flipY(), [1, 2, -3, -4, 5, 6], "Unexpected result after flipY"); } // SVGMatrix skewX(in float angle); function testSkewX() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.skewX(30), [2, 0, 2 * Math.tan(Math.PI / 6), 1, 120, 100], "Unexpected result after skewX"); } // SVGMatrix skewY(in float angle); function testSkewY() { - var m = createMatrix(2, 0, 0, 1, 120, 100); + let m = createMatrix(2, 0, 0, 1, 120, 100); roughCmpMatrix(m.skewY(30), [2, Math.tan(Math.PI / 6), 0, 1, 120, 100], "Unexpected result after skewY"); } diff --git a/dom/webidl/SVGMatrix.webidl b/dom/webidl/SVGMatrix.webidl @@ -4,7 +4,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://www.w3.org/TR/SVG2/ + * https://www.w3.org/TR/SVG11/ + * SVG 2 proposes that it be removed but see + * https://github.com/w3c/svgwg/issues/706 * * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. @@ -26,8 +28,8 @@ interface SVGMatrix { [SetterThrows] attribute float f; - [NewObject] - SVGMatrix multiply(SVGMatrix secondMatrix); + [NewObject, Throws] + SVGMatrix multiply(optional DOMMatrix2DInit secondMatrix = {}); [NewObject, Throws] SVGMatrix inverse(); [NewObject] diff --git a/dom/webidl/SVGPoint.webidl b/dom/webidl/SVGPoint.webidl @@ -4,7 +4,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://www.w3.org/TR/SVG2/ + * https://www.w3.org/TR/SVG11/ + * SVG 2 proposes that it be removed but see + * https://github.com/w3c/svgwg/issues/706 * * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. diff --git a/dom/webidl/SVGRect.webidl b/dom/webidl/SVGRect.webidl @@ -4,7 +4,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://www.w3.org/TR/SVG2/ + * https://www.w3.org/TR/SVG11/ + * SVG 2 proposes that it be removed but see + * https://github.com/w3c/svgwg/issues/706 * * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply.