Trim whitespace around CSS custom declarations.
There was a spec change a few years back, requiring us to
strip spaces and comments from the beginning and end of CSS
custom property declarations.
We take a slight performance hit:
Initial style (µs) Before After Perf 95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce 10041 9994 +0.5% [ +0.1%, +0.9%]
Encyclopedia 106735 106744 -0.0% [ -0.6%, +0.4%]
Extension 132830 133009 -0.1% [ -0.6%, +0.2%]
News 42534 42653 -0.3% [ -1.0%, +0.1%]
Search 2636 2662 -1.0% [ -1.4%, -0.6%]
Social1 23298 23312 -0.1% [ -0.3%, +0.2%]
Social2 1039 1042 -0.3% [ -1.0%, +0.4%]
Sports 42680 42985 -0.7% [ -1.0%, -0.5%]
Video 41971 42134 -0.4% [ -0.6%, -0.1%]
Geometric mean -0.3% [ -0.5%, -0.1%]
Parse (µs) Before After Perf 95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce 1360 1372 -0.9% [ -1.2%, -0.4%]
Encyclopedia 7349 7384 -0.5% [ -0.7%, -0.2%]
Extension 1349 1352 -0.2% [ -1.2%, +0.2%]
News 7929 7982 -0.7% [ -1.0%, -0.3%]
Search 4965 4997 -0.6% [ -0.9%, -0.4%]
Social1 14752 14837 -0.6% [ -0.8%, -0.3%]
Social2 617 620 -0.4% [ -1.4%, +0.7%]
Sports 56182 56318 -0.2% [ -0.6%, +0.0%]
Video 34720 35091 -1.1% [ -1.3%, -0.8%]
Geometric mean -0.6% [ -0.9%, -0.4%]
Recalc style (µs) Before After Perf 95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce 11417 11378 +0.3% [ -0.2%, +0.8%]
Encyclopedia 83808 84066 -0.3% [ -1.4%, +0.1%]
Extension 120362 120394 -0.0% [ -0.7%, +0.3%]
News 31566 31549 +0.1% [ -1.2%, +0.5%]
Search 242 242 -0.0% [ -1.5%, +0.7%]
Social1 17242 17203 +0.2% [ -0.1%, +0.4%]
Social2 602 593 +1.4% [ +0.7%, +2.1%]
Sports 22817 22874 -0.3% [ -0.5%, +0.0%]
Video 25931 25969 -0.1% [ -0.4%, +0.1%]
Geometric mean +0.1% [ -0.5%, +0.5%]
We save a little bit of RAM, obviously, but not much.
Fixed: 1211112
Fixed: 1220144
Change-Id: Ib7656de36d6a94d85ba25ecf60e9879b21c36468
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3341633
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Steinar H Gunderson <sesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1116326}
diff --git a/css/css-layout-api/style-map-multi.https.html b/css/css-layout-api/style-map-multi.https.html
index 9c49d0f..fe6017b 100644
--- a/css/css-layout-api/style-map-multi.https.html
+++ b/css/css-layout-api/style-map-multi.https.html
@@ -11,7 +11,7 @@
width: 100px;
/* Properties under test. */
- --foo: bar;
+ --foo:bar;
margin-left: 2px;
}
@@ -37,7 +37,7 @@
async layout(children, edges, constraints, styleMap) {
const expected = [
{property: '--bar', value: '[CSSUnparsedValue=]'},
- {property: '--foo', value: '[CSSUnparsedValue= bar]'},
+ {property: '--foo', value: '[CSSUnparsedValue=bar]'},
{property: 'empty-cells', value: '[CSSKeywordValue=show]'},
{property: 'margin-left', value: '[CSSUnitValue=2px]'},
];
diff --git a/css/css-layout-api/style-map.https.html b/css/css-layout-api/style-map.https.html
index 0300b8d..52032d9 100644
--- a/css/css-layout-api/style-map.https.html
+++ b/css/css-layout-api/style-map.https.html
@@ -11,7 +11,7 @@
width: 100px;
/* Properties under test. */
- --foo: bar;
+ --foo:bar;
margin-left: 2px;
}
@@ -59,7 +59,7 @@
const tests = [
{property: '--bar', expected: '[CSSUnparsedValue=]'},
- {property: '--foo', expected: '[CSSUnparsedValue= bar]'},
+ {property: '--foo', expected: '[CSSUnparsedValue=bar]'},
{property: 'empty-cells', expected: '[CSSKeywordValue=show]'},
{property: 'margin-left', expected: '[CSSUnitValue=2px]'},
];
diff --git a/css/css-paint-api/style-background-image.https.html b/css/css-paint-api/style-background-image.https.html
index 6a58da3..c36e502 100644
--- a/css/css-paint-api/style-background-image.https.html
+++ b/css/css-paint-api/style-background-image.https.html
@@ -7,7 +7,7 @@
width: 100px;
height: 100px;
margin-left: 2px;
- --foo: bar;
+ --foo:bar;
}
#canvas-geometry {
@@ -44,7 +44,7 @@
ctx.fillStyle = 'green';
if (serializedStrings[0] != "--bar: [CSSUnparsedValue=]")
ctx.fillStyle = 'red';
- if (serializedStrings[1] != "--foo: [CSSUnparsedValue= bar]")
+ if (serializedStrings[1] != "--foo: [CSSUnparsedValue=bar]")
ctx.fillStyle = 'blue';
if (serializedStrings[2] != "empty-cells: [CSSKeywordValue=show]")
ctx.fillStyle = 'yellow';
diff --git a/css/css-paint-api/style-before-pseudo.https.html b/css/css-paint-api/style-before-pseudo.https.html
index 7fde66e..cc569a4 100644
--- a/css/css-paint-api/style-before-pseudo.https.html
+++ b/css/css-paint-api/style-before-pseudo.https.html
@@ -16,7 +16,7 @@
background-image: paint(geometry);
margin-left: 2px;
- --foo: bar;
+ --foo:bar;
}
</style>
<script src="/common/reftest-wait.js"></script>
@@ -48,7 +48,7 @@
ctx.fillStyle = 'green';
if (serializedStrings[0] != "--bar: [CSSUnparsedValue=]")
ctx.fillStyle = 'red';
- if (serializedStrings[1] != "--foo: [CSSUnparsedValue= bar]")
+ if (serializedStrings[1] != "--foo: [CSSUnparsedValue=bar]")
ctx.fillStyle = 'blue';
if (serializedStrings[2] != "margin-left: [CSSUnitValue=2px]")
ctx.fillStyle = 'yellow';
diff --git a/css/css-syntax/serialize-consecutive-tokens.html b/css/css-syntax/serialize-consecutive-tokens.html
index 21eebca..f6e220d 100644
--- a/css/css-syntax/serialize-consecutive-tokens.html
+++ b/css/css-syntax/serialize-consecutive-tokens.html
@@ -104,4 +104,18 @@
testTokenPairs("/", "*");
+// Test that interior comments are preserved, but exterior ones are not.
+function testComments(text, t1, expected) {
+ const b = document.body;
+ test(()=>{
+ b.style.setProperty("--t1", t1);
+ b.style.setProperty("--result", text);
+ const result = getComputedStyle(b).getPropertyValue("--result");
+ assert_equals(result, expected);
+ }, `Comments are handled correctly when computing ${text} using t1:${t1}.`);
+}
+testComments("a/* comment */b", "", "a/* comment */b");
+testComments("a/* comment */var(--t1)", "b", "a/**/b");
+testComments("var(--t1)b", "a/* comment */", "a/**/b");
+
</script>
diff --git a/css/css-variables/variable-cssText.html b/css/css-variables/variable-cssText.html
index 27183ea..15a3ad8 100644
--- a/css/css-variables/variable-cssText.html
+++ b/css/css-variables/variable-cssText.html
@@ -23,7 +23,7 @@
<div id="target8" style="color: green; color: var(--prop);"></div>
<div id="target9" style="margin: var(--prop); margin-top: 10px"></div>
<div id="target10"style="expando: var(--prop);"></div>
-<div id="target11"style="color: /* comment that must be preserved */ var(--prop) var(--prop);"></div>
+<div id="target11"style="color: /* comment that must not be preserved */ var(--prop) /* kept comment */ var(--prop); /* another stripped comment */ /* indeed */ "></div>
<script type="text/javascript">
"use strict";
@@ -39,7 +39,7 @@
{ element: "target8", expectedCssText: "color: var(--prop);" },
{ element: "target9", expectedCssText: "margin-right: ; margin-bottom: ; margin-left: ; margin-top: 10px;" },
{ element: "target10", expectedCssText: "" },
- { element: "target11", expectedCssText: "color: /* comment that must be preserved */ var(--prop) var(--prop);" }
+ { element: "target11", expectedCssText: "color: var(--prop) /* kept comment */ var(--prop);" }
];
testcases.forEach(function (testcase) {