diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp index b74163f4ae070..d97c2ece17fe7 100644 --- a/dom/base/DOMMatrix.cpp +++ b/dom/base/DOMMatrix.cpp @@ -19,7 +19,8 @@ #include -#include "js/Equality.h" // JS::SameValueZero +#include "js/Conversions.h" // JS::NumberToString +#include "js/Equality.h" // JS::SameValueZero namespace mozilla { namespace dom { @@ -470,65 +471,47 @@ void DOMMatrixReadOnly::ToFloat64Array(JSContext* aCx, aResult.set(&value.toObject()); } -// Convenient way to append things as floats, not doubles. We use this because -// we only want to output about 6 digits of precision for our matrix() -// functions, to preserve the behavior we used to have when we used -// AppendPrintf. -static void AppendFloat(nsAString& aStr, float f) { aStr.AppendFloat(f); } - -void DOMMatrixReadOnly::Stringify(nsAString& aResult) { +void DOMMatrixReadOnly::Stringify(nsAString& aResult, ErrorResult& aRv) { + char cbuf[JS::MaximumNumberToStringLength]; nsAutoString matrixStr; + auto AppendDouble = [&aRv, &cbuf, &matrixStr](double d, + bool isLastItem = false) { + if (!mozilla::IsFinite(d)) { + aRv.ThrowDOMException( + NS_ERROR_DOM_INVALID_STATE_ERR, + NS_LITERAL_CSTRING( + "Matrix with a non-finite element cannot be stringified.")); + return false; + } + JS::NumberToString(d, cbuf); + matrixStr.AppendASCII(cbuf); + if (!isLastItem) { + matrixStr.AppendLiteral(", "); + } + return true; + }; + if (mMatrix3D) { // We can't use AppendPrintf here, because it does locale-specific // formatting of floating-point values. matrixStr.AssignLiteral("matrix3d("); - AppendFloat(matrixStr, M11()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M12()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M13()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M14()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M21()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M22()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M23()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M24()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M31()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M32()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M33()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M34()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M41()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M42()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M43()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, M44()); + if (!AppendDouble(M11()) || !AppendDouble(M12()) || !AppendDouble(M13()) || + !AppendDouble(M14()) || !AppendDouble(M21()) || !AppendDouble(M22()) || + !AppendDouble(M23()) || !AppendDouble(M24()) || !AppendDouble(M31()) || + !AppendDouble(M32()) || !AppendDouble(M33()) || !AppendDouble(M34()) || + !AppendDouble(M41()) || !AppendDouble(M42()) || !AppendDouble(M43()) || + !AppendDouble(M44(), true)) { + return; + } matrixStr.AppendLiteral(")"); } else { // We can't use AppendPrintf here, because it does locale-specific // formatting of floating-point values. matrixStr.AssignLiteral("matrix("); - AppendFloat(matrixStr, A()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, B()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, C()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, D()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, E()); - matrixStr.AppendLiteral(", "); - AppendFloat(matrixStr, F()); + if (!AppendDouble(A()) || !AppendDouble(B()) || !AppendDouble(C()) || + !AppendDouble(D()) || !AppendDouble(E()) || !AppendDouble(F(), true)) { + return; + } matrixStr.AppendLiteral(")"); } diff --git a/dom/base/DOMMatrix.h b/dom/base/DOMMatrix.h index a7f42fd285a64..0646fdd1013a4 100644 --- a/dom/base/DOMMatrix.h +++ b/dom/base/DOMMatrix.h @@ -203,7 +203,7 @@ class DOMMatrixReadOnly : public nsWrapperCache { ErrorResult& aRv) const; void ToFloat64Array(JSContext* aCx, JS::MutableHandle aResult, ErrorResult& aRv) const; - void Stringify(nsAString& aResult); + void Stringify(nsAString& aResult, ErrorResult& aRv); bool WriteStructuredClone(JSContext* aCx, JSStructuredCloneWriter* aWriter) const; diff --git a/dom/webidl/DOMMatrix.webidl b/dom/webidl/DOMMatrix.webidl index 954c9cf7406ac..26a7c1207c661 100644 --- a/dom/webidl/DOMMatrix.webidl +++ b/dom/webidl/DOMMatrix.webidl @@ -83,7 +83,7 @@ interface DOMMatrixReadOnly { DOMPoint transformPoint(optional DOMPointInit point = {}); [Throws] Float32Array toFloat32Array(); [Throws] Float64Array toFloat64Array(); - [Exposed=Window] stringifier; + [Exposed=Window, Throws] stringifier; [Default] object toJSON(); }; diff --git a/testing/web-platform/meta/css/geometry/DOMMatrix-stringifier.html.ini b/testing/web-platform/meta/css/geometry/DOMMatrix-stringifier.html.ini deleted file mode 100644 index ded71288721ed..0000000000000 --- a/testing/web-platform/meta/css/geometry/DOMMatrix-stringifier.html.ini +++ /dev/null @@ -1,199 +0,0 @@ -[DOMMatrix-stringifier.html] - [DOMMatrix stringifier: NaN (2d)] - expected: FAIL - - [DOMMatrix stringifier: NaN (3d)] - expected: FAIL - - [DOMMatrix stringifier: Infinity (2d)] - expected: FAIL - - [DOMMatrix stringifier: Infinity (3d)] - expected: FAIL - - [DOMMatrix stringifier: -Infinity (2d)] - expected: FAIL - - [DOMMatrix stringifier: -Infinity (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/3 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/3 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000000 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000000 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [DOMMatrix stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: NaN (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: NaN (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Infinity (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Infinity (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: -Infinity (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: -Infinity (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/3 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/3 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000000 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000000 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: NaN (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: NaN (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Infinity (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Infinity (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: -Infinity (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: -Infinity (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/3 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/3 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000000 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000000 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - diff --git a/testing/web-platform/meta/css/geometry/spec-examples.html.ini b/testing/web-platform/meta/css/geometry/spec-examples.html.ini deleted file mode 100644 index c72ec617503ec..0000000000000 --- a/testing/web-platform/meta/css/geometry/spec-examples.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[spec-examples.html] - [DOMMatrix NaN] - expected: FAIL