Skip to content

Commit 2ca954f

Browse files
zcorpansvgeesus
authored andcommitted
Tighten up DOMMatrix's stringifier; throw for NaN/Infinity
Fixes w3c#120. Tests: web-platform-tests/wpt#5885
1 parent 86ab080 commit 2ca954f

File tree

1 file changed

+125
-21
lines changed

1 file changed

+125
-21
lines changed

geometry/Overview.bs

Lines changed: 125 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Default Highlight: javascript
3232

3333
<pre class=anchors>
3434
type: exception; text: SyntaxError; url: https://html.spec.whatwg.org/multipage/infrastructure.html#js-syntaxerror
35+
urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
36+
type: dfn
37+
text: ToString; url: sec-tostring
38+
text: !; url: sec-algorithm-conventions
3539
</pre>
3640

3741
<script src=https://resources.whatwg.org/file-issue.js async data-file-issue-url="https://github.com/w3c/fxtf-drafts/issues/new?title=[geometry]%20"></script>
@@ -935,15 +939,15 @@ must follow these steps:
935939
exception.
936940

937941
<li><p>If <var>init</var> is the empty string, set it to the string
938-
"<code>matrix(1, 0, 0, 1, 0, 0)</code>".
942+
"<code nohighlight>matrix(1, 0, 0, 1, 0, 0)</code>".
939943

940944
<li><p>Parse <var>init</var> into <var>parsedValue</var> by following the syntax description in
941945
<a href=https://drafts.csswg.org/css-transforms-1/#svg-syntax>Syntax of the SVG ‘transform’
942946
attribute</a>” to a <<transform-list>> or the keyword ''transform/none''. If parsing is not
943947
successful, or any <<transform-function>> has <<length>> values without <a
944948
spec=css-values>absolute length</a> units<!--For WD: <a spec=css-values-3>absolute length
945-
units</a>-->, or any keyword other than ''transform/none'' is used, throw a {{SyntaxError}}
946-
exception. [[!CSS3-TRANSFORMS]]
949+
units</a>-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}"
950+
{{DOMException}}. [[!CSS3-TRANSFORMS]]
947951

948952
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
949953
<<transform-list>> containing a single identity matrix
@@ -1405,22 +1409,111 @@ export>is 2D</dfn>. This flag indicates that:
14051409
<dd><p>Returns the serialized 16 elements {{DOMMatrixReadOnly/m11}} to {{DOMMatrixReadOnly/m44}} of
14061410
the current matrix in column-major order as {{Float64Array}}.
14071411

1408-
<dt><dfn>stringifier()</dfn>
1412+
<dt><dfn dfn>stringification behavior</dfn>
14091413
<dd>
1410-
<dl class=switch>
1411-
<dt>If <a for=matrix>is 2D</a> is <code>true</code>
1412-
<dd><p>Return a DOMString in the form of a CSS Transforms <<matrix()>> function where <var
1413-
ignore>a</var> is {{DOMMatrixReadOnly/a}} attribute, <var ignore>b</var> is
1414-
{{DOMMatrixReadOnly/b}} attribute, <var ignore>c</var> is {{DOMMatrixReadOnly/c}} attribute,
1415-
<var ignore>d</var> is {{DOMMatrixReadOnly/d}} attribute, <var ignore>e</var> is
1416-
{{DOMMatrixReadOnly/e}} attribute, <var ignore>f</var> is {{DOMMatrixReadOnly/f}} attribute.
1417-
[[!CSS3-TRANSFORMS]]
1418-
1419-
<dt>Otherwise
1420-
<dd><p>Return a DOMString in the form of a CSS Transforms <<matrix3d()>> function where <var
1421-
ignore>m11</var> to <var ignore>m44</var> are set to {{DOMMatrixReadOnly/m11}} to
1422-
{{DOMMatrixReadOnly/m44}} attributes. [[!CSS3-TRANSFORMS]]
1423-
</dl>
1414+
<ol>
1415+
<li>
1416+
<p>If one or more of <a for=matrix>m11 element</a> through <a for=matrix>m44 element</a> are a
1417+
non-finite value, then throw an "{{InvalidStateError}}" {{DOMException}}.
1418+
1419+
<p class=note>The CSS syntax cannot represent ''NaN'' or ''Infinity'' values.
1420+
1421+
<li><p>Let <var>string</var> be the empty string.
1422+
1423+
<li>
1424+
<p>If <a for=matrix>is 2D</a> is <code>true</code>, then:
1425+
1426+
<ol>
1427+
<li><p>Append "<code nohighlight>matrix(</code>" to <var>string</var>.
1428+
1429+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m11 element</a>) to <var>string</var>.
1430+
1431+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1432+
1433+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m12 element</a>) to <var>string</var>.
1434+
1435+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1436+
1437+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m21 element</a>) to <var>string</var>.
1438+
1439+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1440+
1441+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m22 element</a>) to <var>string</var>.
1442+
1443+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1444+
1445+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m41 element</a>) to <var>string</var>.
1446+
1447+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1448+
1449+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m42 element</a>) to <var>string</var>.
1450+
1451+
<li><p>Append "<code nohighlight>)</code>" to <var>string</var>.
1452+
</ol>
1453+
1454+
<p class=note>The string will be in the form of a a CSS Transforms <<matrix()>> function.
1455+
[[CSS3-TRANSFORMS]]
1456+
1457+
<li>
1458+
<p>Otherwise:
1459+
<ol>
1460+
<li><p>Append "<code nohighlight>matrix3d(</code>" to <var>string</var>.
1461+
1462+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m11 element</a>) to <var>string</var>.
1463+
1464+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1465+
1466+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m12 element</a>) to <var>string</var>.
1467+
1468+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1469+
1470+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m13 element</a>) to <var>string</var>.
1471+
1472+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1473+
1474+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m14 element</a>) to <var>string</var>.
1475+
1476+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1477+
1478+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m21 element</a>) to <var>string</var>.
1479+
1480+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1481+
1482+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m22 element</a>) to <var>string</var>.
1483+
1484+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1485+
1486+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m23 element</a>) to <var>string</var>.
1487+
1488+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1489+
1490+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m24 element</a>) to <var>string</var>.
1491+
1492+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1493+
1494+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m41 element</a>) to <var>string</var>.
1495+
1496+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1497+
1498+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m42 element</a>) to <var>string</var>.
1499+
1500+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1501+
1502+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m43 element</a>) to <var>string</var>.
1503+
1504+
<li><p>Append "<code nohighlight>, </code>" to <var>string</var>.
1505+
1506+
<li><p>Append [=!=] [=ToString=](<a for=matrix>m44 element</a>) to <var>string</var>.
1507+
1508+
<li><p>Append "<code nohighlight>)</code>" to <var>string</var>.
1509+
</ol>
1510+
1511+
<p class=note>The string will be in the form of a a CSS Transforms <<matrix3d()>> function.
1512+
[[CSS3-TRANSFORMS]]
1513+
1514+
<li><p>Return <var>string</var>.
1515+
</ol>
1516+
</dl>
14241517

14251518
<div class=example>
14261519
<p>In this example, a matrix is created and several 2D transformation methods are called:
@@ -1436,7 +1529,9 @@ export>is 2D</dfn>. This flag indicates that:
14361529
<pre><code>
14371530
"matrix(2, 0, 0, 2, 20, 20)"
14381531
</code></pre>
1532+
</div>
14391533

1534+
<div class=example>
14401535
<p>In the following example, a matrix is created and several 3D transformation methods are called:
14411536

14421537
<pre><code>
@@ -1452,6 +1547,15 @@ export>is 2D</dfn>. This flag indicates that:
14521547
"matrix3d(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)"
14531548
</code></pre>
14541549
</div>
1550+
1551+
<div class=example>
1552+
<p>This example will throw an exception because there are non-finite values in the matrix.
1553+
1554+
<pre><code>
1555+
var matrix = new DOMMatrix([NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
1556+
var string = matrix + " Batman!";
1557+
</code></pre>
1558+
</div>
14551559
</dl>
14561560

14571561

@@ -1668,16 +1772,16 @@ user agents.
16681772
<dt><dfn>setMatrixValue(<var>transformList</var>)</dfn>
16691773
<dd>
16701774
<ol>
1671-
<li><p>If <var>transformList</var> is the empty string, set it to the string "<code>matrix(1, 0,
1775+
<li><p>If <var>transformList</var> is the empty string, set it to the string "<code nohighlight>matrix(1, 0,
16721776
0, 1, 0, 0)</code>".
16731777

16741778
<li><p>Parse <var>transformList</var> into <var>parsedValue</var> by following the syntax
16751779
description in “<a href=https://drafts.csswg.org/css-transforms-1/#svg-syntax>Syntax of the SVG
16761780
‘transform’ attribute</a>” to a <<transform-list>> or the keyword ''transform/none''. If parsing
16771781
is not successful, or any <<transform-function>> has <<length>> values without <a
16781782
spec=css-values>absolute length</a> units<!--For WD: <a spec=css-values-3>absolute length
1679-
units</a>-->, or any keyword other than ''transform/none'' is used, throw a {{SyntaxError}}
1680-
exception. [[!CSS3-TRANSFORMS]]
1783+
units</a>-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}"
1784+
{{DOMException}}. [[!CSS3-TRANSFORMS]]
16811785

16821786
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
16831787
<<transform-list>> containing a single identity matrix

0 commit comments

Comments
 (0)