Title: [283434] trunk
Revision
283434
Author
commit-qu...@webkit.org
Date
2021-10-01 23:22:54 -0700 (Fri, 01 Oct 2021)

Log Message

Allow NaN, infinity, and -infinity in calc
https://bugs.webkit.org/show_bug.cgi?id=231044

Patch by Nikos Mouchtaris <nmouchta...@apple.com> on 2021-10-01
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize-expected.txt:
* web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize.html:
* web-platform-tests/css/css-values/exp-log-serialize-expected.txt:
* web-platform-tests/css/css-values/exp-log-serialize.html:
* web-platform-tests/css/css-values/round-mod-rem-serialize.html:
* web-platform-tests/css/css-values/signs-abs-serialize-expected.txt:
* web-platform-tests/css/css-values/signs-abs-serialize.html:
* web-platform-tests/css/css-values/sin-cos-tan-serialize-expected.txt:
* web-platform-tests/css/css-values/sin-cos-tan-serialize.html:

Source/WebCore:

Modified existing serialization tests.

Added support for NaN, infinity and -infinity keywords in calc. Involved removing checks for
inputs that would result in these values and introduction of new CSSKeywords for these three
constants. Spec for this: https://drafts.csswg.org/css-values-4/#calc-error-constants.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::formatNumberValue const):
* css/CSSValueKeywords.in:
* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::createValue):
* css/calc/CSSCalcExpressionNodeParser.cpp:
(WebCore::getConstantTable):
* css/calc/CSSCalcOperationNode.cpp:
(WebCore::determineCategory):
(WebCore::CSSCalcOperationNode::createLog):
(WebCore::CSSCalcOperationNode::createStep):
(WebCore::CSSCalcOperationNode::createRound):
* css/calc/CSSCalcPrimitiveValueNode.cpp:
(WebCore::CSSCalcPrimitiveValueNode::invert):

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/css3/calc/calc-errors-expected.txt (283433 => 283434)


--- trunk/LayoutTests/css3/calc/calc-errors-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/css3/calc/calc-errors-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -3,7 +3,6 @@
 unclosed calc => PASS
 unclosed calc with garbage => PASS
 garbage => PASS
-zero division => PASS
 non length => PASS
 number + length => PASS
 length + number => PASS

Modified: trunk/LayoutTests/css3/calc/calc-errors.html (283433 => 283434)


--- trunk/LayoutTests/css3/calc/calc-errors.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/css3/calc/calc-errors.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -17,10 +17,6 @@
 <div style="width: 100px; width: calc( flim;">unclosed calc with garbage</div>
 <div style="width: 100px; width: calc( flim );">garbage</div>
 
-
-<!-- zero division -->
-<div style="width: 100px; width: calc(1ex / 0);">zero division</div>
-
 <!-- wrong combination -->
 <div style="width: 100px; width: calc(200);">non length</div>
 <div style="width: 100px; width: calc(10 + 10px);">number + length</div>

Deleted: trunk/LayoutTests/css3/calc/catch-divide-by-0-expected.txt (283433 => 283434)


--- trunk/LayoutTests/css3/calc/catch-divide-by-0-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/css3/calc/catch-divide-by-0-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -1,11 +0,0 @@
-This tests catching of divide by 0 in calc() at parse time
-
-100px / 0 =>
-100px / (0) =>
-100px / (2 - 2) =>
-100px / (2 - (-62 + 64)) =>
-100px * (1 / 0) =>
-100px * (1 / (0)) =>
-100px * (1 / (2 - 2)) =>
-100px * (1 / (2 - (-62 + 64))) =>
-

Deleted: trunk/LayoutTests/css3/calc/catch-divide-by-0.html (283433 => 283434)


--- trunk/LayoutTests/css3/calc/catch-divide-by-0.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/css3/calc/catch-divide-by-0.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -1,26 +0,0 @@
-<!DOCTYPE HTML>
-<div id="dummy"></div>
-<div id="results">This tests catching of divide by 0 in calc() at parse time<br><br></div>
-<script>
-if (window.testRunner)
-    window.testRunner.dumpAsText();
-
-var tests = [
-    "100px / 0",
-    "100px / (0)",
-    "100px / (2 - 2)",
-    "100px / (2 - (-62 + 64))",
-    "100px * (1 / 0)",
-    "100px * (1 / (0))",
-    "100px * (1 / (2 - 2))",
-    "100px * (1 / (2 - (-62 + 64)))",
-];
-
-var results = document.getElementById("results");
-var dummy = document.getElementById("dummy");
-for (var i = 0; i < tests.length; ++i) {
-    var _expression_ = tests[i];
-    dummy.style.width = 'calc(' + _expression_ + ')';
-    results.innerHTML += _expression_ + " => " + dummy.style.width + "<br>";
-}
-</script>
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-02 06:22:54 UTC (rev 283434)
@@ -1,3 +1,20 @@
+2021-10-01  Nikos Mouchtaris  <nmouchta...@apple.com>
+
+        Allow NaN, infinity, and -infinity in calc
+        https://bugs.webkit.org/show_bug.cgi?id=231044
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize-expected.txt:
+        * web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize.html:
+        * web-platform-tests/css/css-values/exp-log-serialize-expected.txt:
+        * web-platform-tests/css/css-values/exp-log-serialize.html:
+        * web-platform-tests/css/css-values/round-mod-rem-serialize.html:
+        * web-platform-tests/css/css-values/signs-abs-serialize-expected.txt:
+        * web-platform-tests/css/css-values/signs-abs-serialize.html:
+        * web-platform-tests/css/css-values/sin-cos-tan-serialize-expected.txt:
+        * web-platform-tests/css/css-values/sin-cos-tan-serialize.html:
+
 2021-10-01  Yusuke Suzuki  <ysuz...@apple.com>
 
         Disable new incumbent-window until it is fully implemented

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -7,4 +7,6 @@
 PASS 'rotate(calc(acos(pi - pi)))' as a computed value should serialize as 'matrix(6.123233995736766e-17, 1, -1, 6.123233995736766e-17, 0, 0)'.
 PASS 'rotate(calc(asin(pi - pi + 1)))' as a specified value should serialize as 'rotate(calc(90deg))'.
 PASS 'rotate(calc(asin(pi - pi + 1)))' as a computed value should serialize as 'matrix(6.123233995736766e-17, 1, -1, 6.123233995736766e-17, 0, 0)'.
+PASS 'rotate(calc(atan(infinity)))' as a specified value should serialize as 'rotate(calc(90deg))'.
+PASS 'rotate(calc(atan(infinity)))' as a computed value should serialize as 'matrix(6.123233995736766e-17, 1, -1, 6.123233995736766e-17, 0, 0)'.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize.html (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/acos-asin-atan-atan2-serialize.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -43,4 +43,9 @@
     'calc(asin(pi - pi + 1))',
     'calc(90deg)',
     rotateMatrix);
+
+test_serialization(
+    'calc(atan(infinity))',
+    'calc(90deg)',
+    rotateMatrix);
 </script>
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -15,4 +15,8 @@
 PASS 'scale(calc(log(1) + 0.5))' as a specified value should serialize as 'scale(calc(0.5))'.
 PASS 'calc(log(1) + 0.5)' as a computed value should serialize as '0.5'.
 PASS 'scale(calc(log(1) + 0.5))' as a computed value should serialize as 'matrix(0.5, 0, 0, 0.5, 0, 0)'.
+PASS 'calc(log(0))' as a specified value should serialize as 'calc(-infinity)'.
+PASS 'scale(calc(log(0)))' as a specified value should serialize as 'scale(calc(-infinity))'.
+FAIL 'calc(log(0))' as a computed value should serialize as '-infinity'. assert_equals: '-infinity' should round-trip exactly in computed values. expected "-infinity" but got "1"
+FAIL 'scale(calc(log(0)))' as a computed value should serialize as 'matrix(-infinity, 0, 0, -infinity, 0, 0)'. assert_equals: 'matrix(-infinity, 0, 0, -infinity, 0, 0)' should round-trip exactly in computed values. expected "matrix(-infinity, 0, 0, -infinity, 0, 0)" but got "none"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize.html (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/exp-log-serialize.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -33,4 +33,8 @@
     'calc(log(1) + 0.5)',
     'calc(0.5)',
     '0.5');
+test_serialization(
+    'calc(log(0))',
+    'calc(-infinity)',
+    '-infinity');
 </script>
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-function-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-function-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-function-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -49,20 +49,20 @@
 PASS round(infinity, -5) should be used-value-equivalent to calc(infinity)
 PASS round(-infinity, 5) should be used-value-equivalent to calc(-infinity)
 PASS round(-infinity, -5) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(5, infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(5, -infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(-5, infinity)) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(-5, -infinity)) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(to-zero, 5, infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(to-zero, 5, -infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(to-zero, -5, infinity)) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(to-zero, -5, -infinity)) should be used-value-equivalent to calc(-infinity)
-PASS round(up, 1, infinity) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(up, 0, infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(up, -1 * 0, infinity) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(up, -1, infinity) should be used-value-equivalent to calc(-infinity)
-PASS round(down, -1, infinity) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(down, -1 * 0, infinity)) should be used-value-equivalent to calc(-infinity)
-PASS calc(1 / round(down, 0, infinity)) should be used-value-equivalent to calc(infinity)
-PASS calc(1 / round(down, 1, infinity)) should be used-value-equivalent to calc(infinity)
+FAIL calc(1 / round(5, infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(5, infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(5, -infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(5, -infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(-5, infinity)) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(-5, infinity)) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(-5, -infinity)) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(-5, -infinity)) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(to-zero, 5, infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(to-zero, 5, infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(to-zero, 5, -infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(to-zero, 5, -infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(to-zero, -5, infinity)) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(to-zero, -5, infinity)) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(to-zero, -5, -infinity)) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(to-zero, -5, -infinity)) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL round(up, 1, infinity) should be used-value-equivalent to calc(infinity) assert_equals: round(up, 1, infinity) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(up, 0, infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(up, 0, infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(up, -1 * 0, infinity) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(up, -1 * 0, infinity) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(up, -1, infinity) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(up, -1, infinity) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL round(down, -1, infinity) should be used-value-equivalent to calc(-infinity) assert_equals: round(down, -1, infinity) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(down, -1 * 0, infinity)) should be used-value-equivalent to calc(-infinity) assert_equals: calc(1 / round(down, -1 * 0, infinity)) and calc(-infinity) serialize to the same thing in used values. expected "matrix3d(-infinity, NaN, NaN, NaN, NaN, -infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(down, 0, infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(down, 0, infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
+FAIL calc(1 / round(down, 1, infinity)) should be used-value-equivalent to calc(infinity) assert_equals: calc(1 / round(down, 1, infinity)) and calc(infinity) serialize to the same thing in used values. expected "matrix3d(infinity, NaN, NaN, NaN, NaN, infinity, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)" but got "matrix3d(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 0, 0, 1, 0, 0, 0, 0, 1)"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -11,4 +11,16 @@
 FAIL 'scale(rem(1,1))' as a specified value should serialize as 'scale(calc(0))'. assert_equals: 'scale(rem(1,1))' and 'scale(calc(0))' should serialize the same in specified values. expected "scale(calc(0))" but got "scale(rem(1, 1))"
 PASS 'rem(1,1)' as a computed value should serialize as '0'.
 PASS 'scale(rem(1,1))' as a computed value should serialize as 'matrix(0, 0, 0, 0, 0, 0)'.
+PASS 'calc(round(1,0))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(round(1,0)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(round(1,0))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(round(1,0)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
+PASS 'calc(mod(1,0))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(mod(1,0)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(mod(1,0))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(mod(1,0)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
+PASS 'calc(rem(1,0))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(rem(1,0)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(rem(1,0))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(rem(1,0)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize.html (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-mod-rem-serialize.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -28,4 +28,17 @@
     'rem(1,1)',
     'calc(0)',
     '0');
+
+test_serialization(
+    'calc(round(1,0))',
+    'calc(NaN)',
+    'NaN');
+test_serialization(
+    'calc(mod(1,0))',
+    'calc(NaN)',
+    'NaN');
+test_serialization(
+    'calc(rem(1,0))',
+    'calc(NaN)',
+    'NaN');
 </script>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -31,4 +31,28 @@
 PASS 'scale(calc(sign(.1) + 1))' as a specified value should serialize as 'scale(calc(2))'.
 FAIL 'calc(sign(.1) + 1)' as a computed value should serialize as '2'. assert_equals: '2' should round-trip exactly in computed values. expected "2" but got "1"
 PASS 'scale(calc(sign(.1) + 1))' as a computed value should serialize as 'matrix(2, 0, 0, 2, 0, 0)'.
+FAIL 'calc(abs(inFinity))' as a specified value should serialize as 'calc(inFinity)'. assert_equals: 'calc(inFinity)' should round-trip exactly in specified values. expected "calc(inFinity)" but got "calc(infinity)"
+PASS 'scale(calc(abs(inFinity)))' as a specified value should serialize as 'scale(calc(infinity))'.
+FAIL 'calc(abs(inFinity))' as a computed value should serialize as 'infinity'. assert_equals: 'infinity' should round-trip exactly in computed values. expected "infinity" but got "1"
+FAIL 'scale(calc(abs(inFinity)))' as a computed value should serialize as 'matrix(infinity, 0, 0, infinity, 0, 0)'. assert_equals: 'matrix(infinity, 0, 0, infinity, 0, 0)' should round-trip exactly in computed values. expected "matrix(infinity, 0, 0, infinity, 0, 0)" but got "none"
+PASS 'calc(abs(infinity))' as a specified value should serialize as 'calc(infinity)'.
+PASS 'scale(calc(abs(infinity)))' as a specified value should serialize as 'scale(calc(infinity))'.
+FAIL 'calc(abs(infinity))' as a computed value should serialize as 'infinity'. assert_equals: 'infinity' should round-trip exactly in computed values. expected "infinity" but got "1"
+FAIL 'scale(calc(abs(infinity)))' as a computed value should serialize as 'matrix(infinity, 0, 0, infinity, 0, 0)'. assert_equals: 'matrix(infinity, 0, 0, infinity, 0, 0)' should round-trip exactly in computed values. expected "matrix(infinity, 0, 0, infinity, 0, 0)" but got "none"
+PASS 'calc(sign(infinity))' as a specified value should serialize as 'calc(1)'.
+PASS 'scale(calc(sign(infinity)))' as a specified value should serialize as 'scale(calc(1))'.
+PASS 'calc(sign(infinity))' as a computed value should serialize as '1'.
+PASS 'scale(calc(sign(infinity)))' as a computed value should serialize as 'matrix(1, 0, 0, 1, 0, 0)'.
+FAIL 'abs(infinity)' as a specified value should serialize as 'calc(infinity)'. assert_equals: 'abs(infinity)' and 'calc(infinity)' should serialize the same in specified values. expected "calc(infinity)" but got "abs(infinity)"
+FAIL 'scale(abs(infinity))' as a specified value should serialize as 'scale(calc(infinity))'. assert_equals: 'scale(abs(infinity))' and 'scale(calc(infinity))' should serialize the same in specified values. expected "scale(calc(infinity))" but got "scale(abs(infinity))"
+FAIL 'abs(infinity)' as a computed value should serialize as 'infinity'. assert_equals: 'infinity' should round-trip exactly in computed values. expected "infinity" but got "1"
+FAIL 'scale(abs(infinity))' as a computed value should serialize as 'matrix(infinity, 0, 0, infinity, 0, 0)'. assert_equals: 'matrix(infinity, 0, 0, infinity, 0, 0)' should round-trip exactly in computed values. expected "matrix(infinity, 0, 0, infinity, 0, 0)" but got "none"
+PASS 'calc(abs(-infinity))' as a specified value should serialize as 'calc(infinity)'.
+PASS 'scale(calc(abs(-infinity)))' as a specified value should serialize as 'scale(calc(infinity))'.
+FAIL 'calc(abs(-infinity))' as a computed value should serialize as 'infinity'. assert_equals: 'infinity' should round-trip exactly in computed values. expected "infinity" but got "1"
+FAIL 'scale(calc(abs(-infinity)))' as a computed value should serialize as 'matrix(infinity, 0, 0, infinity, 0, 0)'. assert_equals: 'matrix(infinity, 0, 0, infinity, 0, 0)' should round-trip exactly in computed values. expected "matrix(infinity, 0, 0, infinity, 0, 0)" but got "none"
+PASS 'calc(sign(-1 * infinity))' as a specified value should serialize as 'calc(-1)'.
+PASS 'scale(calc(sign(-1 * infinity)))' as a specified value should serialize as 'scale(calc(-1))'.
+FAIL 'calc(sign(-1 * infinity))' as a computed value should serialize as '-1'. assert_equals: '-1' should round-trip exactly in computed values. expected "-1" but got "0"
+PASS 'scale(calc(sign(-1 * infinity)))' as a computed value should serialize as 'matrix(-1, 0, 0, -1, 0, 0)'.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize.html (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/signs-abs-serialize.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -50,4 +50,31 @@
     'calc(sign(.1) + 1)',
     'calc(2)',
     '2');
+
+test_serialization(
+    'calc(abs(inFinity))',
+    'calc(inFinity)',
+    'infinity');
+
+test_serialization(
+    'calc(abs(infinity))',
+    'calc(infinity)',
+    'infinity');
+test_serialization(
+    'calc(sign(infinity))',
+    'calc(1)',
+    '1');
+test_serialization(
+    'abs(infinity)',
+    'calc(infinity)',
+    'infinity');
+    
+test_serialization(
+    'calc(abs(-infinity))',
+    'calc(infinity)',
+    'infinity');
+test_serialization(
+    'calc(sign(-1 * infinity))',
+    'calc(-1)',
+    '-1');
 </script>
\ No newline at end of file

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize-expected.txt (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize-expected.txt	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize-expected.txt	2021-10-02 06:22:54 UTC (rev 283434)
@@ -27,4 +27,16 @@
 PASS 'scale(calc(tan(0) + 0.5))' as a specified value should serialize as 'scale(calc(0.5))'.
 PASS 'calc(tan(0) + 0.5)' as a computed value should serialize as '0.5'.
 PASS 'scale(calc(tan(0) + 0.5))' as a computed value should serialize as 'matrix(0.5, 0, 0, 0.5, 0, 0)'.
+PASS 'calc(sin(infinity))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(sin(infinity)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(sin(infinity))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(sin(infinity)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
+PASS 'calc(cos(infinity))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(cos(infinity)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(cos(infinity))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(cos(infinity)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
+PASS 'calc(tan(infinity))' as a specified value should serialize as 'calc(NaN)'.
+PASS 'scale(calc(tan(infinity)))' as a specified value should serialize as 'scale(calc(NaN))'.
+FAIL 'calc(tan(infinity))' as a computed value should serialize as 'NaN'. assert_equals: 'NaN' should round-trip exactly in computed values. expected "NaN" but got "1"
+FAIL 'scale(calc(tan(infinity)))' as a computed value should serialize as 'matrix(NaN, 0, 0, NaN, 0, 0)'. assert_equals: 'matrix(NaN, 0, 0, NaN, 0, 0)' should round-trip exactly in computed values. expected "matrix(NaN, 0, 0, NaN, 0, 0)" but got "none"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize.html (283433 => 283434)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize.html	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/sin-cos-tan-serialize.html	2021-10-02 06:22:54 UTC (rev 283434)
@@ -45,4 +45,17 @@
     'calc(tan(0) + 0.5)',
     'calc(0.5)',
     '0.5');
+
+test_serialization(
+    'calc(sin(infinity))',
+    'calc(NaN)',
+    'NaN');
+test_serialization(
+    'calc(cos(infinity))',
+    'calc(NaN)',
+    'NaN');
+test_serialization(
+    'calc(tan(infinity))',
+    'calc(NaN)',
+    'NaN');
 </script>

Modified: trunk/Source/WebCore/ChangeLog (283433 => 283434)


--- trunk/Source/WebCore/ChangeLog	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/ChangeLog	2021-10-02 06:22:54 UTC (rev 283434)
@@ -1,3 +1,32 @@
+2021-10-01  Nikos Mouchtaris  <nmouchta...@apple.com>
+
+        Allow NaN, infinity, and -infinity in calc
+        https://bugs.webkit.org/show_bug.cgi?id=231044
+
+        Reviewed by Simon Fraser.
+
+        Modified existing serialization tests.
+
+        Added support for NaN, infinity and -infinity keywords in calc. Involved removing checks for 
+        inputs that would result in these values and introduction of new CSSKeywords for these three 
+        constants. Spec for this: https://drafts.csswg.org/css-values-4/#calc-error-constants. 
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+        (WebCore::CSSPrimitiveValue::formatNumberValue const):
+        * css/CSSValueKeywords.in:
+        * css/CSSValuePool.cpp:
+        (WebCore::CSSValuePool::createValue):
+        * css/calc/CSSCalcExpressionNodeParser.cpp:
+        (WebCore::getConstantTable):
+        * css/calc/CSSCalcOperationNode.cpp:
+        (WebCore::determineCategory):
+        (WebCore::CSSCalcOperationNode::createLog):
+        (WebCore::CSSCalcOperationNode::createStep):
+        (WebCore::CSSCalcOperationNode::createRound):
+        * css/calc/CSSCalcPrimitiveValueNode.cpp:
+        (WebCore::CSSCalcPrimitiveValueNode::invert):
+
 2021-10-01  Lauro Moura  <lmo...@igalia.com>
 
         [GLIB] Fix build on Ubuntu 20.04 after 242376@main

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (283433 => 283434)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2021-10-02 06:22:54 UTC (rev 283434)
@@ -260,7 +260,6 @@
     : CSSValue(PrimitiveClass)
 {
     setPrimitiveUnitType(type);
-    ASSERT(std::isfinite(num));
     m_value.num = num;
 }
 
@@ -951,6 +950,10 @@
 
 NEVER_INLINE String CSSPrimitiveValue::formatNumberValue(StringView suffix) const
 {
+    if (m_value.num == std::numeric_limits<double>::infinity())
+        return makeString("infinity", suffix);
+    if (m_value.num == -1 * std::numeric_limits<double>::infinity())
+        return makeString("-infinity", suffix);
     return makeString(m_value.num, suffix);
 }
 

Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (283433 => 283434)


--- trunk/Source/WebCore/css/CSSValueKeywords.in	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in	2021-10-02 06:22:54 UTC (rev 283434)
@@ -1366,6 +1366,9 @@
 rem
 to-zero
 nearest
+infinity
+-infinity
+NaN
 
 from-image
 

Modified: trunk/Source/WebCore/css/CSSValuePool.cpp (283433 => 283434)


--- trunk/Source/WebCore/css/CSSValuePool.cpp	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/CSSValuePool.cpp	2021-10-02 06:22:54 UTC (rev 283434)
@@ -112,8 +112,6 @@
 
 Ref<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSUnitType type)
 {
-    ASSERT(std::isfinite(value));
-
     if (value < 0 || value > StaticCSSValuePool::maximumCacheableIntegerValue)
         return CSSPrimitiveValue::create(value, type);
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp (283433 => 283434)


--- trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp	2021-10-02 06:22:54 UTC (rev 283434)
@@ -97,7 +97,12 @@
 
 static const CSSCalcSymbolTable getConstantTable()
 {
-    return { { CSSValuePi, CSSUnitType::CSS_NUMBER, piDouble }, { CSSValueE, CSSUnitType::CSS_NUMBER, std::exp(1.0) } };
+    return {
+        { CSSValuePi, CSSUnitType::CSS_NUMBER, piDouble }, { CSSValueE, CSSUnitType::CSS_NUMBER, std::exp(1.0) },
+        { CSSValueNegativeInfinity, CSSUnitType::CSS_NUMBER, -1 * std::numeric_limits<double>::infinity() },
+        { CSSValueInfinity, CSSUnitType::CSS_NUMBER, std::numeric_limits<double>::infinity() },
+        { CSSValueNaN, CSSUnitType::CSS_NUMBER, std::numeric_limits<double>::quiet_NaN() },
+    };
 }
 
 static ParseState checkDepthAndIndex(int depth, CSSParserTokenRange tokens)

Modified: trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp (283433 => 283434)


--- trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp	2021-10-02 06:22:54 UTC (rev 283434)
@@ -70,7 +70,7 @@
             return CalculationCategory::Other;
         return leftCategory == CalculationCategory::Number ? rightCategory : leftCategory;
     case CalcOperator::Divide:
-        if (rightCategory != CalculationCategory::Number || rightSide.isZero())
+        if (rightCategory != CalculationCategory::Number)
             return CalculationCategory::Other;
         return leftCategory;
     case CalcOperator::Sin:
@@ -158,7 +158,7 @@
             // At a / sub-_expression_, let left type be the result of finding the types of its left argument,
             // and right type be the result of finding the types of its right argument and then inverting it.
             // The sub-_expression_’s type is the result of multiplying the left type and right type.
-            if (invertCategory != CalculationCategory::Number || node.isZero())
+            if (invertCategory != CalculationCategory::Number)
                 return CalculationCategory::Other;
             break;
         }
@@ -438,18 +438,11 @@
     if (values.size() != 1 && values.size() != 2)
         return nullptr;
     for (auto& value : values) {
-        // TODO: Support infinity
-        if (value->category() != CalculationCategory::Number || !value->doubleValue(value->primitiveType())) {
+        if (value->category() != CalculationCategory::Number) {
             LOG_WITH_STREAM(Calc, stream << "Failed to create log node because unable to determine category from " << prettyPrintNodes(values));
             return nullptr;
         }
     }
-    
-    // TODO: Support infinity
-    if ((values.size() == 2 && values[1]->doubleValue(values[1]->primitiveType()) == 1)) {
-        LOG_WITH_STREAM(Calc, stream << "Failed to create log node because unable to determine category from " << prettyPrintNodes(values));
-        return nullptr;
-    }
 
     return adoptRef(new CSSCalcOperationNode(CalculationCategory::Number, CalcOperator::Log, WTFMove(values)));
 }
@@ -567,12 +560,6 @@
         LOG_WITH_STREAM(Calc, stream << "Failed to create stepped value node because unable to determine category from " << prettyPrintNodes(values));
         return nullptr;
     }
-    
-    if (!values[1]->doubleValue(values[1]->primitiveType())) {
-        LOG_WITH_STREAM(Calc, stream << "Failed to create stepped value node because unable to determine category from " << prettyPrintNodes(values));
-        return nullptr;
-    }
-
     return adoptRef(new CSSCalcOperationNode(values[0]->category(), op, WTFMove(values)));
 }
 
@@ -608,10 +595,6 @@
     CalcOperator roundType = values.size() == 2 ?  CalcOperator::Nearest : downcast<CSSCalcOperationNode>(values[0].get()).calcOperator();
     if (values.size() == 3)
         values.remove(0);
-    if (!values[1]->doubleValue(values[1]->primitiveType())) {
-        LOG_WITH_STREAM(Calc, stream << "Failed to create round node because unable to determine category from " << prettyPrintNodes(values));
-        return nullptr;
-    }
     return adoptRef(new CSSCalcOperationNode(values.rbegin()[0]->category(), roundType, WTFMove(values)));
 }
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp (283433 => 283434)


--- trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp	2021-10-02 06:22:54 UTC (rev 283434)
@@ -85,8 +85,10 @@
 void CSSCalcPrimitiveValueNode::invert()
 {
     ASSERT(isNumericValue());
-    if (!m_value->doubleValue())
+    if (!m_value->doubleValue()) {
         m_value = CSSPrimitiveValue::create(std::numeric_limits<double>::infinity(), m_value->primitiveType());
+        return;
+    }
 
     m_value = CSSPrimitiveValue::create(1.0 / m_value->doubleValue(), m_value->primitiveType());
 }

Modified: trunk/Source/WebCore/css/makevalues.pl (283433 => 283434)


--- trunk/Source/WebCore/css/makevalues.pl	2021-10-02 04:38:45 UTC (rev 283433)
+++ trunk/Source/WebCore/css/makevalues.pl	2021-10-02 06:22:54 UTC (rev 283434)
@@ -102,7 +102,11 @@
 for my $i (0 .. $#names) {
   my $id = $names[$i];
   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
-  print GPERF $lower_names[$i] . ", CSSValue" . $id . "\n";
+  if($lower_names[$i]=="-infinity") {
+    print GPERF $lower_names[$i] . ", CSSValueNegativeInfinity" . "\n";
+  } else {
+    print GPERF $lower_names[$i] . ", CSSValue" . $id . "\n";
+  }
 }
 
 print GPERF << "EOF";
@@ -179,7 +183,11 @@
 foreach my $name (@names) {
   my $id = $name;
   $id =~ s/(^[^-])|-(.)/uc($1||$2)/ge;
-  print HEADER "    CSSValue" . $id . " = " . $i . ",\n";
+  if($name=="-infinity") {
+    print HEADER "    CSSValueNegativeInfinity = " . $i . ",\n";
+  } else {
+    print HEADER "    CSSValue" . $id . " = " . $i . ",\n";
+  }
   $i = $i + 1;
   if (length($name) > $maxLen) {
     $maxLen = length($name);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to