From 081bbe70e5a789c3115666fb1d45b0af7c1d0351 Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Wed, 10 May 2017 19:31:38 +0200 Subject: [PATCH] [geometry] Tighten up DOMMatrix's stringifier; throw for NaN/Infinity Fixes #120. Tests: https://github.com/w3c/web-platform-tests/issues/5885 --- geometry/Overview.bs | 146 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 125 insertions(+), 21 deletions(-) diff --git a/geometry/Overview.bs b/geometry/Overview.bs index 2245b822..ef0c42f1 100644 --- a/geometry/Overview.bs +++ b/geometry/Overview.bs @@ -32,6 +32,10 @@ Default Highlight: javascript
 type: exception; text: SyntaxError; url: https://html.spec.whatwg.org/multipage/infrastructure.html#js-syntaxerror
+urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
+    type: dfn
+        text: ToString; url: sec-tostring
+        text: !; url: sec-algorithm-conventions
 
@@ -928,15 +932,15 @@ must follow these steps: exception.
  • If init is the empty string, set it to the string - "matrix(1, 0, 0, 1, 0, 0)". + "matrix(1, 0, 0, 1, 0, 0)".

  • Parse init into parsedValue by following the syntax description in “Syntax of the SVG ‘transform’ attribute” to a <> or the keyword ''transform/none''. If parsing is not successful, or any <> has <> values without absolute length units, or any keyword other than ''transform/none'' is used, throw a {{SyntaxError}} - exception. [[!CSS3-TRANSFORMS]] + units-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}" + {{DOMException}}. [[!CSS3-TRANSFORMS]]

  • If parsedValue is ''transform/none'', set parsedValue to a <> containing a single identity matrix @@ -1398,22 +1402,111 @@ export>is 2D. This flag indicates that:

    Returns the serialized 16 elements {{DOMMatrixReadOnly/m11}} to {{DOMMatrixReadOnly/m44}} of the current matrix in column-major order as {{Float64Array}}. -

    stringifier() +
    stringification behavior
    -
    -
    If is 2D is true -

    Return a DOMString in the form of a CSS Transforms <> function where a is {{DOMMatrixReadOnly/a}} attribute, b is - {{DOMMatrixReadOnly/b}} attribute, c is {{DOMMatrixReadOnly/c}} attribute, - d is {{DOMMatrixReadOnly/d}} attribute, e is - {{DOMMatrixReadOnly/e}} attribute, f is {{DOMMatrixReadOnly/f}} attribute. - [[!CSS3-TRANSFORMS]] - -

    Otherwise -

    Return a DOMString in the form of a CSS Transforms <> function where m11 to m44 are set to {{DOMMatrixReadOnly/m11}} to - {{DOMMatrixReadOnly/m44}} attributes. [[!CSS3-TRANSFORMS]] -

    +
      +
    1. +

      If one or more of m11 element through m44 element are a + non-finite value, then throw an "{{InvalidStateError}}" {{DOMException}}. + +

      The CSS syntax cannot represent ''NaN'' or ''Infinity'' values. + +

    2. Let string be the empty string. + +

    3. +

      If is 2D is true, then: + +

        +
      1. Append "matrix(" to string. + +

      2. Append [=!=] [=ToString=](m11 element) to string. + +

      3. Append ", " to string. + +

      4. Append [=!=] [=ToString=](m12 element) to string. + +

      5. Append ", " to string. + +

      6. Append [=!=] [=ToString=](m21 element) to string. + +

      7. Append ", " to string. + +

      8. Append [=!=] [=ToString=](m22 element) to string. + +

      9. Append ", " to string. + +

      10. Append [=!=] [=ToString=](m41 element) to string. + +

      11. Append ", " to string. + +

      12. Append [=!=] [=ToString=](m42 element) to string. + +

      13. Append ")" to string. +

      + +

      The string will be in the form of a a CSS Transforms <> function. + [[CSS3-TRANSFORMS]] + +

    4. +

      Otherwise: +

        +
      1. Append "matrix3d(" to string. + +

      2. Append [=!=] [=ToString=](m11 element) to string. + +

      3. Append ", " to string. + +

      4. Append [=!=] [=ToString=](m12 element) to string. + +

      5. Append ", " to string. + +

      6. Append [=!=] [=ToString=](m13 element) to string. + +

      7. Append ", " to string. + +

      8. Append [=!=] [=ToString=](m14 element) to string. + +

      9. Append ", " to string. + +

      10. Append [=!=] [=ToString=](m21 element) to string. + +

      11. Append ", " to string. + +

      12. Append [=!=] [=ToString=](m22 element) to string. + +

      13. Append ", " to string. + +

      14. Append [=!=] [=ToString=](m23 element) to string. + +

      15. Append ", " to string. + +

      16. Append [=!=] [=ToString=](m24 element) to string. + +

      17. Append ", " to string. + +

      18. Append [=!=] [=ToString=](m41 element) to string. + +

      19. Append ", " to string. + +

      20. Append [=!=] [=ToString=](m42 element) to string. + +

      21. Append ", " to string. + +

      22. Append [=!=] [=ToString=](m43 element) to string. + +

      23. Append ", " to string. + +

      24. Append [=!=] [=ToString=](m44 element) to string. + +

      25. Append ")" to string. +

      + +

      The string will be in the form of a a CSS Transforms <> function. + [[CSS3-TRANSFORMS]] + +

    5. Return string. +

    +

    In this example, a matrix is created and several 2D transformation methods are called: @@ -1429,7 +1522,9 @@ export>is 2D. This flag indicates that:

    
        "matrix(2, 0, 0, 2, 20, 20)"
        
    +
    +

    In the following example, a matrix is created and several 3D transformation methods are called:

    
    @@ -1445,6 +1540,15 @@ export>is 2D. This flag indicates that:
        "matrix3d(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)"
        
    + +
    +

    This example will throw an exception because there are non-finite values in the matrix. + +

    
    +   var matrix = new DOMMatrix([NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
    +   var string = matrix + " Batman!";
    +   
    +
    @@ -1660,7 +1764,7 @@ user agents.
    setMatrixValue(transformList)
      -
    1. If transformList is the empty string, set it to the string "matrix(1, 0, +

    2. If transformList is the empty string, set it to the string "matrix(1, 0, 0, 1, 0, 0)".

    3. Parse transformList into parsedValue by following the syntax @@ -1668,8 +1772,8 @@ user agents. ‘transform’ attribute” to a <> or the keyword ''transform/none''. If parsing is not successful, or any <> has <> values without absolute length units, or any keyword other than ''transform/none'' is used, throw a {{SyntaxError}} - exception. [[!CSS3-TRANSFORMS]] + units-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}" + {{DOMException}}. [[!CSS3-TRANSFORMS]]

    4. If parsedValue is ''transform/none'', set parsedValue to a <> containing a single identity matrix