mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1364875: Append double in DOMMatrix stringifier r=bzbarsky,jwalden
Fixed the stringifier as the spec mandates [using full double precision](https://github.com/w3c/fxtf-drafts/issues/120#issuecomment-300713781). Differential Revision: https://phabricator.services.mozilla.com/D35593 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
84895794b3
commit
4d85db26bb
@ -19,7 +19,8 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#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(")");
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ class DOMMatrixReadOnly : public nsWrapperCache {
|
||||
ErrorResult& aRv) const;
|
||||
void ToFloat64Array(JSContext* aCx, JS::MutableHandle<JSObject*> aResult,
|
||||
ErrorResult& aRv) const;
|
||||
void Stringify(nsAString& aResult);
|
||||
void Stringify(nsAString& aResult, ErrorResult& aRv);
|
||||
|
||||
bool WriteStructuredClone(JSContext* aCx,
|
||||
JSStructuredCloneWriter* aWriter) const;
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,3 +0,0 @@
|
||||
[spec-examples.html]
|
||||
[DOMMatrix NaN]
|
||||
expected: FAIL
|
Loading…
Reference in New Issue
Block a user