Changeset 279358 in webkit


Ignore:
Timestamp:
Jun 28, 2021 6:34:20 PM (13 months ago)
Author:
Darin Adler
Message:

CSS parser "consume declaration" algorithm does not handle whitespace correctly
https://bugs.webkit.org/show_bug.cgi?id=227368

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-properties-values-api/at-property-animation-expected.txt:
  • web-platform-tests/css/css-properties-values-api/at-property-expected.txt:
  • web-platform-tests/css/css-properties-values-api/at-property-shadow-expected.txt:
  • web-platform-tests/css/css-properties-values-api/determine-registration-expected.txt:
  • web-platform-tests/css/css-properties-values-api/registered-property-cssom-expected.txt:
  • web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-expected.txt:

Regenerated to reflect the whitespace trimming: one new pass, no new failures. Some of
these tests will also need updates to match the newer CSS specification. Not doing those
here right now.

  • web-platform-tests/css/css-properties-values-api/at-property.html:

Pulled down a newer version of this test from the WPT repository with expectations in line
with newer CSS specification.

  • web-platform-tests/css/css-syntax/declarations-trim-whitespace-expected.txt:
  • web-platform-tests/css/css-variables/variable-cssText-expected.txt:

Expect most tests to pass instead of fail. There are still some failures. Given my reading
of the CSS specification I suspect it is the tests that are incorrect.

  • web-platform-tests/css/css-variables/variable-definition-expected.txt:
  • web-platform-tests/css/css-variables/variable-definition.html:

Pulled down a newer version of this test from the WPT repository with expectations in line
with newer CSS specification. Some tests are still failing because of expectations about
trailing whitespace. Given my reading of the CSS specification I suspect it is the tests
that are incorrect.

  • web-platform-tests/css/css-variables/variable-reference-expected.txt:
  • web-platform-tests/css/css-variables/variable-reference.html:
  • web-platform-tests/css/css-variables/variable-substitution-variable-declaration-expected.txt:
  • web-platform-tests/css/css-variables/variable-substitution-variable-declaration.html:

Pulled down a newer version of these tests from the WPT repository with expectations in
line with newer CSS specification.

  • web-platform-tests/css/cssom/variable-names-expected.txt: Expect tests to pass, not fail.

Source/WebCore:

Test: imported/w3c/web-platform-tests/css/css-syntax/declarations-trim-whitespace.html

To avoid creating regressions in CSS variable behavior, had to make
changes there to handle whitespace correctly at the same time as the
change to the "consume declaration" algorithm.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::customPropertyValue): Restructured
to not have a case for each variant custom value type. This lets us
support the new Empty value type without extra code here.

  • css/CSSCustomPropertyValue.cpp:

(WebCore::CSSCustomPropertyValue::createEmpty): Added. Used for a new
Empty value type for properties that have empty string as their value,
which is a new capability added to the CSS specification.
(WebCore::CSSCustomPropertyValue::equals const): Removed unneeded pointer
comparison optimization. Added support for Empty value.
(WebCore::CSSCustomPropertyValue::customCSSText const): Updated to use
null string for m_stringValue instead of a separate m_serialized flag.
Added support for Empty value.
(WebCore::CSSCustomPropertyValue::tokens const): Added support for
Empty value. Also call directly to customCSSText instead of calling
through cssText.

  • css/CSSCustomPropertyValue.h: Updated for the above, adding Empty value.

Removed m_serialized. Greatly simplified the copy constructor since Ref
now has a copy constructor.

  • css/CSSVariableReferenceValue.cpp:

(WebCore::resolveVariableFallback): Consume whitespace after the comma,
matching what is now called for in the CSS specification.

  • css/calc/CSSCalcExpressionNodeParser.cpp:

(WebCore::CSSCalcExpressionNodeParser::parseCalcFunction): Use
consumeCommaIncludingWhitespace to simplify the code. No behavior change,
just refactoring.

  • css/parser/CSSParserImpl.cpp:

(WebCore::CSSParserImpl::consumeDeclaration): Updated algorithm to match
the CSS specification, trimming whitespace correctly.
(WebCore::CSSParserImpl::consumeCustomPropertyValue): Added support for
a custom property value with no declaration value, as now called for in
the CSS specification, using CSSCustomPropertyValue::createEmpty.

  • css/parser/CSSVariableParser.cpp:

(WebCore::isValidVariableReference): Allow empty fallback, as now called
for in the CSS specification.
(WebCore::isValidConstantReference): Ditto.

LayoutTests:

  • css-custom-properties-api/inline.html: Update expectations to expect leading

whitespace to be trimmed.

  • fast/css/variables/test-suite/011.html: Updated to expect a variable reference

with no fallback tokens to be valid. Change in the CSS specification since this
test was written.

  • fast/css/variables/test-suite/013.html: Ditto.
  • fast/css/variables/test-suite/041.html: Ditto.
  • fast/css/variables/test-suite/043.html: Ditto.
  • fast/css/variables/test-suite/061.html: Updated to expect a value with no tokens

to be valid. Change in the CSS specification since this test was written.

  • fast/css/variables/test-suite/100.html: Updated to expect a variable reference

with no fallback tokens to be valid. Change in the CSS specification since this
test was written.

  • fast/css/variables/test-suite/105.html: Ditto.
  • fast/css/variables/test-suite/136.html: Ditto.
  • fast/css/variables/test-suite/170.html: Updated to expect a value with no tokens

to be valid. Change in the CSS specification since this test was written.

  • fast/css/variables/test-suite/171.html: Ditto.
  • platform/mac/TestExpectations: Removed a line for a test that no longer exists

(not changed in this patch).

Location:
trunk
Files:
38 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r279356 r279358  
     12021-06-28  Darin Adler  <darin@apple.com>
     2
     3        CSS parser "consume declaration" algorithm does not handle whitespace correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=227368
     5
     6        Reviewed by Sam Weinig.
     7
     8        * css-custom-properties-api/inline.html: Update expectations to expect leading
     9        whitespace to be trimmed.
     10
     11        * fast/css/variables/test-suite/011.html: Updated to expect a variable reference
     12        with no fallback tokens to be valid. Change in the CSS specification since this
     13        test was written.
     14        * fast/css/variables/test-suite/013.html: Ditto.
     15        * fast/css/variables/test-suite/041.html: Ditto.
     16        * fast/css/variables/test-suite/043.html: Ditto.
     17
     18        * fast/css/variables/test-suite/061.html: Updated to expect a value with no tokens
     19        to be valid. Change in the CSS specification since this test was written.
     20
     21        * fast/css/variables/test-suite/100.html: Updated to expect a variable reference
     22        with no fallback tokens to be valid. Change in the CSS specification since this
     23        test was written.
     24        * fast/css/variables/test-suite/105.html: Ditto.
     25        * fast/css/variables/test-suite/136.html: Ditto.
     26
     27        * fast/css/variables/test-suite/170.html: Updated to expect a value with no tokens
     28        to be valid. Change in the CSS specification since this test was written.
     29        * fast/css/variables/test-suite/171.html: Ditto.
     30
     31        * platform/mac/TestExpectations: Removed a line for a test that no longer exists
     32        (not changed in this patch).
     33
    1342021-06-28  Cameron McCormack  <heycam@apple.com>
    235
  • trunk/LayoutTests/css-custom-properties-api/inline.html

    r269360 r279358  
    2121test(function() {
    2222  // Nothing registered yet, whatever you specify works
    23   assert_equals(computedStyle.getPropertyValue('--a'), ' 10em');
    24   assert_equals(computedStyle.getPropertyValue('--b'), ' 10em');
     23  assert_equals(computedStyle.getPropertyValue('--a'), '10em');
     24  assert_equals(computedStyle.getPropertyValue('--b'), '10em');
    2525
    2626  inlineStyle.setProperty('--a', 'hello');
     
    5858  assert_equals(inlineStyle.getPropertyValue('--b'), '');
    5959  assert_equals(computedStyle.getPropertyValue('--a'), '160px');
    60   assert_equals(computedStyle.getPropertyValue('--b'), ' 10em');
     60  assert_equals(computedStyle.getPropertyValue('--b'), '10em');
    6161}, "Values can be removed from inline styles");
    6262
  • trunk/LayoutTests/fast/css/variables/test-suite/011.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test a failing non-custom property declaration in an @supports rule where the property value contains a syntactically invalid variable reference due to having no fallback tokens.</title>
     5--><html><head><title>CSS Test: Test a non-custom property declaration in an @supports rule where the property value contains a variable reference with no fallback tokens.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#using-variables" rel="help">
     
    99<style>
    1010body { color: red; }
    11 @supports (color: var(--a)) and (not (color: var(--a,))) {
     11@supports (color: var(--a,)) {
    1212  p { color: green; }
    1313}
  • trunk/LayoutTests/fast/css/variables/test-suite/013.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test a failing non-custom property declaration in an @supports rule where the property value contains a syntactically invalid variable reference due to having no fallback tokens, just a comment.</title>
     5--><html><head><title>CSS Test: Test a non-custom property declaration in an @supports rule where the property value contains a variable reference with no fallback tokens, just a comment.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#using-variables" rel="help">
     
    99<style>
    1010body { color: red; }
    11 @supports (color: var(--a)) and (not (color: var(--a,/**/))) {
     11@supports (color: var(--a,/**/)) {
    1212  p { color: green; }
    1313}
  • trunk/LayoutTests/fast/css/variables/test-suite/041.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test a failing custom property declaration in an @supports rule whose value contains a variable reference with no fallback tokens.</title>
     5--><html><head><title>CSS Test: Test a custom property declaration in an @supports rule whose value contains a variable reference with no fallback tokens.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    99<style>
    1010body { color: red; }
    11 @supports (--a: a) and (not (--a: var(--b,))) {
     11@supports (--a: var(--b,)) {
    1212  p { color: green; }
    1313}
  • trunk/LayoutTests/fast/css/variables/test-suite/043.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test a failing custom property declaration in an @supports rule whose value contains a variable reference with no fallback tokens, just a comment.</title>
     5--><html><head><title>CSS Test: Test a custom property declaration in an @supports rule whose value contains a variable reference with no fallback tokens, just a comment.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    99<style>
    1010body { color: red; }
    11 @supports (--a: a) and (not (--a: var(--b,/**/))) {
     11@supports (--a: var(--b,/**/)) {
    1212  p { color: green; }
    1313}
  • trunk/LayoutTests/fast/css/variables/test-suite/061.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test a failing custom property declaration in an @supports rule whose value contains no tokens.</title>
     5--><html><head><title>CSS Test: Test a custom property declaration in an @supports rule whose value contains no tokens.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    99<style>
    1010body { color: red; }
    11 @supports (--a: a) and (not (--a:)) {
     11@supports (--a:) {
    1212  p { color: green; }
    1313}
  • trunk/LayoutTests/fast/css/variables/test-suite/100.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test declaring a non-custom property with invalid syntax due to having a variable reference whose fallback contains nothing but a comment.</title>
     5--><html><head><title>CSS Test: Test declaring a non-custom property with a variable reference whose fallback contains nothing but a comment.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#using-variables" rel="help">
     
    99<style>
    1010body {
    11   --a: crimson;
     11  --a: green;
    1212  color: red;
    1313}
    1414p {
    15   color: green;
    1615  color: var(--a,/**/);
    1716}
  • trunk/LayoutTests/fast/css/variables/test-suite/105.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test declaring a non-custom property with invalid syntax due to having a variable reference whose fallback contains no tokens.</title>
     5--><html><head><title>CSS Test: Test declaring a non-custom property with a variable reference whose fallback contains no tokens.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#using-variables" rel="help">
     
    99<style>
    1010body {
    11   --a: crimson;
     11  --a: green;
    1212  color: red;
    1313}
    1414p {
    15   color: green;
    1615  color: var(--a,);
    1716}
  • trunk/LayoutTests/fast/css/variables/test-suite/136.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test declaring a variable with invalid syntax due to a variable reference having no tokens in its fallback.</title>
     5--><html><head><title>CSS Test: Test declaring a variable with a variable reference having no tokens in its fallback.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    1010p {
    1111  color: red;
    12   --a: green;
    13   --b: crimson;
     12  --a: red;
     13  --b: green;
    1414  --a: var(--b,);
    1515  color: var(--a);
  • trunk/LayoutTests/fast/css/variables/test-suite/170.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test declaring a variable with invalid syntax due to having no tokens.</title>
     5--><html><head><title>CSS Test: Test declaring a variable with no tokens.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    1212}
    1313p {
    14   color: orange;
    15   --a: green;
    1614  --a:;
    17   color: var(--a);
     15  color: var(--a) green;
    1816}
    1917</style>
  • trunk/LayoutTests/fast/css/variables/test-suite/171.html

    r191128 r279358  
    33     Any copyright is dedicated to the Public Domain.
    44     http://creativecommons.org/publicdomain/zero/1.0/
    5 --><html><head><title>CSS Test: Test declaring a variable with invalid syntax due to a variable reference having only a comment in its fallback.</title>
     5--><html><head><title>CSS Test: Test declaring a variable with a variable reference having only a comment in its fallback.</title>
    66<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
    77<link href="http://www.w3.org/TR/css-variables-1/#syntax" rel="help">
     
    1010p {
    1111  color: red;
    12   --a: green;
    13   --b: crimson;
     12  --a: crimson;
     13  --b: green;
    1414  --a: var(--b,/**/);
    1515  color: var(--a);
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r279344 r279358  
     12021-06-28  Darin Adler  <darin@apple.com>
     2
     3        CSS parser "consume declaration" algorithm does not handle whitespace correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=227368
     5
     6        Reviewed by Sam Weinig.
     7
     8        * web-platform-tests/css/css-properties-values-api/at-property-animation-expected.txt:
     9        * web-platform-tests/css/css-properties-values-api/at-property-expected.txt:
     10        * web-platform-tests/css/css-properties-values-api/at-property-shadow-expected.txt:
     11        * web-platform-tests/css/css-properties-values-api/determine-registration-expected.txt:
     12        * web-platform-tests/css/css-properties-values-api/registered-property-cssom-expected.txt:
     13        * web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-expected.txt:
     14        Regenerated to reflect the whitespace trimming: one new pass, no new failures. Some of
     15        these tests will also need updates to match the newer CSS specification. Not doing those
     16        here right now.
     17
     18        * web-platform-tests/css/css-properties-values-api/at-property.html:
     19        Pulled down a newer version of this test from the WPT repository with expectations in line
     20        with newer CSS specification.
     21
     22        * web-platform-tests/css/css-syntax/declarations-trim-whitespace-expected.txt:
     23        * web-platform-tests/css/css-variables/variable-cssText-expected.txt:
     24        Expect most tests to pass instead of fail. There are still some failures. Given my reading
     25        of the CSS specification I suspect it is the tests that are incorrect.
     26
     27        * web-platform-tests/css/css-variables/variable-definition-expected.txt:
     28        * web-platform-tests/css/css-variables/variable-definition.html:
     29        Pulled down a newer version of this test from the WPT repository with expectations in line
     30        with newer CSS specification. Some tests are still failing because of expectations about
     31        trailing whitespace. Given my reading of the CSS specification I suspect it is the tests
     32        that are incorrect.
     33
     34        * web-platform-tests/css/css-variables/variable-reference-expected.txt:
     35        * web-platform-tests/css/css-variables/variable-reference.html:
     36        * web-platform-tests/css/css-variables/variable-substitution-variable-declaration-expected.txt:
     37        * web-platform-tests/css/css-variables/variable-substitution-variable-declaration.html:
     38        Pulled down a newer version of these tests from the WPT repository with expectations in
     39        line with newer CSS specification.
     40
     41        * web-platform-tests/css/cssom/variable-names-expected.txt: Expect tests to pass, not fail.
     42
    1432021-06-28  Chris Dumez  <cdumez@apple.com>
    244
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-animation-expected.txt

    r264522 r279358  
    55FAIL Ongoing animation matches new keyframes against the current registration assert_equals: expected "0px" but got ""
    66FAIL Ongoing animation picks up redeclared intial value assert_equals: expected "200px" but got ""
    7 FAIL Ongoing animation picks up redeclared inherits flag assert_equals: expected "200px" but got " 100px"
    8 FAIL Ongoing animation picks up redeclared meaning of 'unset' assert_equals: expected "200px" but got " 100px"
     7FAIL Ongoing animation picks up redeclared inherits flag assert_equals: expected "200px" but got "100px"
     8FAIL Ongoing animation picks up redeclared meaning of 'unset' assert_equals: expected "200px" but got "100px"
    99FAIL Transitioning from initial value assert_equals: expected "rgb(255, 0, 0)" but got ""
    10 FAIL Transitioning from specified value assert_equals: expected "rgb(0, 0, 255)" but got " blue"
     10FAIL Transitioning from specified value assert_equals: expected "rgb(0, 0, 255)" but got "blue"
    1111FAIL Transition triggered by initial value change assert_equals: expected "100px" but got ""
    1212FAIL No transition when changing types assert_equals: expected "100px" but got ""
    13 FAIL No transition when removing @property rule assert_equals: expected "100px" but got " 100px"
     13FAIL No transition when removing @property rule assert_equals: expected " 100px" but got "100px"
    1414
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-expected.txt

    r267650 r279358  
    5757PASS Rule not applied [<color>, notacolor, false]
    5858PASS Rule not applied [<length>, 10em, false]
    59 FAIL Non-inherited properties do not inherit assert_equals: expected "40px" but got " 40px"
    60 FAIL Inherited properties inherit assert_equals: expected "40px" but got " 40px"
     59FAIL Non-inherited properties do not inherit assert_equals: expected "0px" but got "40px"
     60PASS Inherited properties inherit
    6161FAIL Initial values substituted as computed value assert_equals: expected "rgb(0, 128, 0)" but got ""
    6262PASS Non-universal registration are invalid without an initial value
    63 FAIL Initial value may be omitted for universal registration assert_equals: expected "" but got " calc(1px + 1px)"
     63FAIL Initial value may be omitted for universal registration assert_equals: expected "" but got "calc(1px + 1px)"
    6464
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-shadow-expected.txt

    r264522 r279358  
    11
    2 FAIL @property rules in shadow trees should have no effect assert_equals: expected "2px" but got " calc(1px + 1px)"
     2FAIL @property rules in shadow trees should have no effect assert_equals: expected "2px" but got "calc(1px + 1px)"
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property.html

    r264522 r279358  
    201201  try {
    202202    target.style = `${name}: calc(1px + 1px);`;
    203     assert_equals(getComputedStyle(target).getPropertyValue(name), ' calc(1px + 1px)');
     203    assert_equals(getComputedStyle(target).getPropertyValue(name), 'calc(1px + 1px)');
    204204  } finally {
    205205    target.style = '';
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/determine-registration-expected.txt

    r264522 r279358  
    66FAIL CSS.registerProperty determines the registration when uncontested The given initial value does not parse for the given syntax.
    77FAIL @property registrations are cleared when rule removed assert_equals: expected "10px" but got ""
    8 FAIL Computed value becomes token sequence when @property is removed assert_equals: expected "2px" but got " calc(1px + 1px)"
    9 FAIL Inherited status is reflected in computed styles when @property is removed assert_equals: expected "0px" but got " 10px"
     8FAIL Computed value becomes token sequence when @property is removed assert_equals: expected " calc(1px + 1px)" but got "calc(1px + 1px)"
     9FAIL Inherited status is reflected in computed styles when @property is removed assert_equals: expected " 10px" but got "10px"
    1010FAIL Invalid @property rule (missing syntax) does not overwrite previous valid rule assert_equals: expected "1px" but got ""
    1111FAIL Invalid @property rule (missing inherits descriptor) does not overwrite previous valid rule assert_equals: expected "1px" but got ""
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/registered-property-cssom-expected.txt

    r267650 r279358  
    11
    2 PASS CSSOM setters function as expected for unregistered properties
     2FAIL CSSOM setters function as expected for unregistered properties assert_equals: expected " 10px" but got "10px"
    33FAIL CSS.registerProperty The given initial value does not parse for the given syntax.
    4 FAIL Formerly valid values are still readable from inline styles but are computed as the unset value assert_equals: expected "rgb(0, 0, 255)" but got "hello"
    5 FAIL Values not matching the registered type can still be set assert_equals: expected "hi" but got "5"
    6 FAIL Values can be removed from inline styles assert_equals: expected "rgb(255, 0, 0)" but got " red"
     4FAIL Formerly valid values are still readable from inline styles but are computed as the unset value assert_equals: expected "5" but got ""
     5FAIL Values not matching the registered type can still be set assert_equals: expected "hi" but got ""
     6FAIL Values can be removed from inline styles assert_equals: expected "rgb(255, 0, 0)" but got "red"
    77FAIL Stylesheets can be modified by CSSOM assert_equals: expected "0px" but got "10px"
    88FAIL Valid values can be set on inline styles assert_equals: expected "rgb(255, 192, 203)" but got "pink"
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-expected.txt

    r267650 r279358  
    11
    2 PASS var() references work with registered properties
     2FAIL var() references work with registered properties assert_equals: expected " 20px" but got "20px"
    33FAIL References to registered var()-properties work in registered lists assert_equals: expected "1px, 10px, 2px" but got "0px"
    44FAIL References to mixed registered and unregistered var()-properties work in registered lists assert_equals: expected "1px, 20px, 10px, 2px" but got "0px"
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/declarations-trim-whitespace-expected.txt

    r267650 r279358  
    11
    22PASS --foo-1:bar;
    3 FAIL --foo-2: bar; assert_equals: expected "bar" but got " bar"
    4 FAIL --foo-3:bar ; assert_equals: expected "bar" but got "bar "
    5 FAIL --foo-4: bar ; assert_equals: expected "bar" but got " bar "
    6 FAIL --foo-5: bar !important; assert_equals: expected "bar" but got " bar "
    7 FAIL --foo-6: bar !important ; assert_equals: expected "bar" but got " bar "
     3PASS --foo-2: bar;
     4PASS --foo-3:bar ;
     5PASS --foo-4: bar ;
     6PASS --foo-5: bar !important;
     7PASS --foo-6: bar !important ;
    88PASS --foo-7:bar!important;
    99PASS --foo-8:bar!important ;
    10 FAIL --foo-9:bar (then ws until end of rule) assert_equals: expected "bar" but got "bar "
     10PASS --foo-9:bar (then ws until end of rule)
    1111foo
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-cssText-expected.txt

    r271706 r279358  
    11
    2 FAIL target1 assert_equals: expected "--var: var1;" but got "--var:  var1;"
     2PASS target1
    33PASS target2
    44PASS target3
    5 PASS target4
    6 PASS target5
     5FAIL target4 assert_equals: expected "margin: var(--prop)  !important;" but got "margin: var(--prop) !important;"
     6FAIL target5 assert_equals: expected "background: var(--prop)  !important;" but got "background: var(--prop) !important;"
    77FAIL target6 assert_equals: expected "background: green;" but got "background-color: green;"
    88PASS target7
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-definition-expected.txt

    r271706 r279358  
    44PASS single char variable
    55PASS single char '-' variable
    6 FAIL no char variable assert_equals: Expected Value should match actual value expected "value" but got ""
     6PASS no char variable
    77PASS white space value (single space)
    8 FAIL white space value (double space) assert_equals: Expected Value should match actual value expected "  " but got " "
     8PASS white space value (double space)
    99PASS overwrite
    1010PASS can't overwrite with no value
     
    1616PASS  leading white space (single space)
    1717PASS  middle white space (single space)
    18 PASS  trailing white space (single space)
    19 FAIL  leading white space (double space) 2 assert_equals: Expected Value should match actual value expected "  value" but got " value"
     18FAIL  trailing white space (single space) assert_equals: Expected Value should match actual value expected "value " but got "value"
     19PASS  leading white space (double space) 2
    2020FAIL  middle white space (double space) 2 assert_equals: Expected Value should match actual value expected "value1  value2" but got "value1 value2"
    21 FAIL  trailing white space (double space) 2 assert_equals: Expected Value should match actual value expected "value  " but got "value "
    22 PASS !important
     21FAIL  trailing white space (double space) 2 assert_equals: Expected Value should match actual value expected "value  " but got "value"
     22FAIL !important assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    2323PASS !important 2
    24 PASS !important (with space)
     24FAIL !important (with space) assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    2525PASS no variable (Computed Style)
    2626PASS variable (Computed Style)
    2727PASS single char variable (Computed Style)
    2828PASS single char '-' variable (Computed Style)
    29 FAIL no char variable (Computed Style) assert_equals: Expected Value should match actual value expected "value" but got ""
     29PASS no char variable (Computed Style)
    3030PASS white space value (single space) (Computed Style)
    31 FAIL white space value (double space) (Computed Style) assert_equals: Expected Value should match actual value expected "  " but got " "
     31PASS white space value (double space) (Computed Style)
    3232PASS overwrite (Computed Style)
    3333PASS can't overwrite with no value (Computed Style)
     
    3939PASS  leading white space (single space) (Computed Style)
    4040PASS  middle white space (single space) (Computed Style)
    41 PASS  trailing white space (single space) (Computed Style)
    42 FAIL  leading white space (double space) 2 (Computed Style) assert_equals: Expected Value should match actual value expected "  value" but got " value"
     41FAIL  trailing white space (single space) (Computed Style) assert_equals: Expected Value should match actual value expected "value " but got "value"
     42PASS  leading white space (double space) 2 (Computed Style)
    4343FAIL  middle white space (double space) 2 (Computed Style) assert_equals: Expected Value should match actual value expected "value1  value2" but got "value1 value2"
    44 FAIL  trailing white space (double space) 2 (Computed Style) assert_equals: Expected Value should match actual value expected "value  " but got "value "
    45 PASS !important (Computed Style)
     44FAIL  trailing white space (double space) 2 (Computed Style) assert_equals: Expected Value should match actual value expected "value  " but got "value"
     45FAIL !important (Computed Style) assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    4646PASS !important 2 (Computed Style)
    47 PASS !important (with space) (Computed Style)
     47FAIL !important (with space) (Computed Style) assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    4848PASS no variable (Cascading)
    4949PASS variable (Cascading)
    5050PASS single char variable (Cascading)
    5151PASS single char '-' variable (Cascading)
    52 FAIL no char variable (Cascading) assert_equals: Expected Value should match actual value expected "value" but got ""
     52PASS no char variable (Cascading)
    5353PASS white space value (single space) (Cascading)
    54 FAIL white space value (double space) (Cascading) assert_equals: Expected Value should match actual value expected "  " but got " "
     54PASS white space value (double space) (Cascading)
    5555PASS overwrite (Cascading)
    5656PASS can't overwrite with no value (Cascading)
     
    6262PASS  leading white space (single space) (Cascading)
    6363PASS  middle white space (single space) (Cascading)
    64 PASS  trailing white space (single space) (Cascading)
    65 FAIL  leading white space (double space) 2 (Cascading) assert_equals: Expected Value should match actual value expected "  value" but got " value"
     64FAIL  trailing white space (single space) (Cascading) assert_equals: Expected Value should match actual value expected "value " but got "value"
     65PASS  leading white space (double space) 2 (Cascading)
    6666FAIL  middle white space (double space) 2 (Cascading) assert_equals: Expected Value should match actual value expected "value1  value2" but got "value1 value2"
    67 FAIL  trailing white space (double space) 2 (Cascading) assert_equals: Expected Value should match actual value expected "value  " but got "value "
    68 PASS !important (Cascading)
     67FAIL  trailing white space (double space) 2 (Cascading) assert_equals: Expected Value should match actual value expected "value  " but got "value"
     68FAIL !important (Cascading) assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    6969PASS !important 2 (Cascading)
    70 PASS !important (with space) (Cascading)
     70FAIL !important (with space) (Cascading) assert_equals: Expected Value should match actual value expected "value1 " but got "value1"
    7171PASS basic CSSOM.setProperty
    7272FAIL CSSOM.setProperty with space 1 assert_equals: Expected Value should match actual value expected "" but got "green"
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-definition.html

    r271706 r279358  
    2323        { varName:"--v",       expectedValue:"value",   style:"--v:value",                  testName:"single char variable"},
    2424        { varName:"---",       expectedValue:"value",   style:"---:value",                  testName:"single char '-' variable"},
    25         { varName:"--",        expectedValue:"value",   style:"--:value",                   testName:"no char variable"},
    26         { varName:"--var",     expectedValue:" ",       style:"--var: ",                    testName:"white space value (single space)"},
    27         { varName:"--var",     expectedValue:"  ",      style:"--var:  ",                   testName:"white space value (double space)"},
     25        { varName:"--",        expectedValue:"",        style:"--:value",                   testName:"no char variable"},
     26        { varName:"--var",     expectedValue:"",       style:"--var: ",                    testName:"white space value (single space)"},
     27        { varName:"--var",     expectedValue:"",      style:"--var:  ",                   testName:"white space value (double space)"},
    2828        { varName:"--var",     expectedValue:"value2",  style:"--var:value1; --var:value2", testName:"overwrite"},
    29         { varName:"--var",     expectedValue:"value",   style:"--var:value;--var:;",        testName:"can't overwrite with no value"},
    30         { varName:"--var",     expectedValue:" ",       style:"--var:value;--var: ;",       testName:"can overwrite with space value"},
     29        { varName:"--var",     expectedValue:"",   style:"--var:value;--var:;",        testName:"can't overwrite with no value"},
     30        { varName:"--var",     expectedValue:"",       style:"--var:value;--var: ;",       testName:"can overwrite with space value"},
    3131        { varName:"--var",     expectedValue:"value1",  style:"--var:value1; --Var:value2", testName:"case sensetivity"},
    3232        { varName:"--Var",     expectedValue:"value2",  style:"--var:value1; --Var:value2", testName:"case sensetivity2"},
    3333        { varName:"---var",    expectedValue:"value",  style:"---var:value;",               testName:"parsing three dashes at start of variable"},
    3434        { varName:"-var4" ,    expectedValue:"",        style:"-var4:value3",               testName:"parsing multiple dashes with one dash at start of variable"},
    35         { varName:"--var",     expectedValue:" value",  style:"--var: value",               testName:" leading white space (single space)"},
     35        { varName:"--var",     expectedValue:"value",  style:"--var: value",               testName:" leading white space (single space)"},
    3636        { varName:"--var",     expectedValue:"value1 value2", style:"--var:value1 value2",  testName:" middle white space (single space)"},
    3737        { varName:"--var",     expectedValue:"value ",  style:"--var:value ",               testName:" trailing white space (single space)"},
    38         { varName:"--var",     expectedValue:"  value", style:"--var:  value",              testName:" leading white space (double space) 2"},
     38        { varName:"--var",     expectedValue:"value", style:"--var:  value",              testName:" leading white space (double space) 2"},
    3939        { varName:"--var",     expectedValue:"value1  value2", style:"--var:value1  value2",testName:" middle white space (double space) 2"},
    4040        { varName:"--var",     expectedValue:"value  ", style:"--var:value  ",              testName:" trailing white space (double space) 2"},
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-reference-expected.txt

    r271706 r279358  
    88PASS width: var(--prop1, var(--prop2, var(--prop3, auto)));
    99PASS width: var(--prop1) var(--prop2)
     10PASS width: var(--prop,);
    1011PASS width: var();
    1112PASS width: var(prop);
    1213PASS width: var(-prop);
    13 PASS width: var(--prop,);
    1414PASS width: var(--prop 20px);
    1515PASS width: var(--prop, var(prop));
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-reference.html

    r271706 r279358  
    3535        { cssText: "width: var(--prop1, var(--prop2, var(--prop3, auto)));", expectedPropertyValue: "var(--prop1, var(--prop2, var(--prop3, auto)))" },
    3636        { cssText: "width: var(--prop1) var(--prop2)",      expectedPropertyValue: "var(--prop1) var(--prop2)" },
     37        { cssText: "width: var(--prop,);",                  expectedPropertyValue: "var(--prop,)" },
    3738
    3839        { cssText: "width: var();",                         expectedPropertyValue: "" },
    3940        { cssText: "width: var(prop);",                     expectedPropertyValue: "" },
    4041        { cssText: "width: var(-prop);",                    expectedPropertyValue: "" },
    41         { cssText: "width: var(--prop,);",                  expectedPropertyValue: "" },
    4242        { cssText: "width: var(--prop 20px);",              expectedPropertyValue: "" },
    4343        { cssText: "width: var(--prop, var(prop));",        expectedPropertyValue: "" },
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-substitution-variable-declaration-expected.txt

    r271706 r279358  
    3030PASS target10 --varA
    3131PASS target10 --varB
    32 FAIL target10 --varC assert_equals: expected "" but got " another good one"
     32FAIL target10 --varC assert_equals: expected "" but got "another good one"
    3333
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-variables/variable-substitution-variable-declaration.html

    r271706 r279358  
    102102
    103103        var testcases = [
    104             { element: "target1",       propertyName: "--var2",         expectedPropertyValue: "   23px 13px 17px 10px" },
     104            { element: "target1",       propertyName: "--var2",         expectedPropertyValue: "23px 13px 17px 10px" },
    105105            { element: "target1",       propertyName: "margin-top",     expectedPropertyValue: "23px" },
    106106            { element: "target1",       propertyName: "margin-right",   expectedPropertyValue: "13px" },
     
    110110            { element: "target2parent", propertyName: "--var1",         expectedPropertyValue: "" },
    111111            { element: "target2parent", propertyName: "--var2",         expectedPropertyValue: "" },
    112             { element: "target2",       propertyName: "--var1",         expectedPropertyValue: " good" },
     112            { element: "target2",       propertyName: "--var1",         expectedPropertyValue: "good" },
    113113            { element: "target2",       propertyName: "--var2",         expectedPropertyValue: "" },
    114114
    115             { element: "target3",       propertyName: "--var1",         expectedPropertyValue: "  5px" },
    116             { element: "target3",       propertyName: "--var2",         expectedPropertyValue: "   5px" },
     115            { element: "target3",       propertyName: "--var1",         expectedPropertyValue: "5px" },
     116            { element: "target3",       propertyName: "--var2",         expectedPropertyValue: "5px" },
    117117
    118118            { element: "target4",       propertyName: "--varA",         expectedPropertyValue: "" },
    119119            { element: "target4",       propertyName: "--varB",         expectedPropertyValue: "" },
    120             { element: "target4",       propertyName: "--varC",         expectedPropertyValue: " 13px" },
     120            { element: "target4",       propertyName: "--varC",         expectedPropertyValue: "13px" },
    121121
    122122            { element: "target5",       propertyName: "--varA",         expectedPropertyValue: "" },
     
    133133
    134134            { element: "target8",       propertyName: "--varA",         expectedPropertyValue: "" },
    135             { element: "target8",       propertyName: "--varB",         expectedPropertyValue: "  7px" },
     135            { element: "target8",       propertyName: "--varB",         expectedPropertyValue: "7px" },
    136136
    137             { element: "target9",       propertyName: "--varA",         expectedPropertyValue: " good" },
     137            { element: "target9",       propertyName: "--varA",         expectedPropertyValue: "good" },
    138138            { element: "target9",       propertyName: "--varB",         expectedPropertyValue: "" },
    139139            { element: "target9",       propertyName: "--varC",         expectedPropertyValue: "" },
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom/variable-names-expected.txt

    r232005 r279358  
    11
    2 FAIL custom property '--a' assert_equals: property value returned correctly from specified style getPropertyValue (after serialization/re-parsing) expected "value" but got " value"
     2PASS custom property '--a'
    33FAIL custom property '--a;b' assert_equals: appears on specified style (after serialization/re-parsing) expected 1 but got 0
    4 FAIL custom property '---' assert_equals: property value returned correctly from specified style getPropertyValue (after serialization/re-parsing) expected "value" but got " value"
     4PASS custom property '---'
    55FAIL custom property '--\' assert_equals: appears on specified style (after serialization/re-parsing) expected 1 but got 0
    6 FAIL custom property '--ab' assert_equals: property value returned correctly from specified style getPropertyValue (after serialization/re-parsing) expected "value" but got " value"
    7 FAIL custom property '--0' assert_equals: property value returned correctly from specified style getPropertyValue (after serialization/re-parsing) expected "value" but got " value"
     6PASS custom property '--ab'
     7PASS custom property '--0'
    88
  • trunk/LayoutTests/platform/mac/TestExpectations

    r279356 r279358  
    15251525webaudio/oscillator-sine.html [ Skip ]
    15261526
    1527 webkit.org/b/199013 [ Debug ] imported/w3c/web-platform-tests/websockets/Create-Secure-verify-url-set-non-default-port.any.html [ Pass Failure ]
    1528 
    15291527webkit.org/b/190882 animations/change-one-anim.html [ Pass Failure ]
    15301528
  • trunk/Source/WebCore/ChangeLog

    r279355 r279358  
     12021-06-28  Darin Adler  <darin@apple.com>
     2
     3        CSS parser "consume declaration" algorithm does not handle whitespace correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=227368
     5
     6        Reviewed by Sam Weinig.
     7
     8        Test: imported/w3c/web-platform-tests/css/css-syntax/declarations-trim-whitespace.html
     9
     10        To avoid creating regressions in CSS variable behavior, had to make
     11        changes there to handle whitespace correctly at the same time as the
     12        change to the "consume declaration" algorithm.
     13
     14        * css/CSSComputedStyleDeclaration.cpp:
     15        (WebCore::ComputedStyleExtractor::customPropertyValue): Restructured
     16        to not have a case for each variant custom value type. This lets us
     17        support the new Empty value type without extra code here.
     18
     19        * css/CSSCustomPropertyValue.cpp:
     20        (WebCore::CSSCustomPropertyValue::createEmpty): Added. Used for a new
     21        Empty value type for properties that have empty string as their value,
     22        which is a new capability added to the CSS specification.
     23        (WebCore::CSSCustomPropertyValue::equals const): Removed unneeded pointer
     24        comparison optimization. Added support for Empty value.
     25        (WebCore::CSSCustomPropertyValue::customCSSText const): Updated to use
     26        null string for m_stringValue instead of a separate m_serialized flag.
     27        Added support for Empty value.
     28        (WebCore::CSSCustomPropertyValue::tokens const): Added support for
     29        Empty value. Also call directly to customCSSText instead of calling
     30        through cssText.
     31
     32        * css/CSSCustomPropertyValue.h: Updated for the above, adding Empty value.
     33        Removed m_serialized. Greatly simplified the copy constructor since Ref
     34        now has a copy constructor.
     35
     36        * css/CSSVariableReferenceValue.cpp:
     37        (WebCore::resolveVariableFallback): Consume whitespace after the comma,
     38        matching what is now called for in the CSS specification.
     39
     40        * css/calc/CSSCalcExpressionNodeParser.cpp:
     41        (WebCore::CSSCalcExpressionNodeParser::parseCalcFunction): Use
     42        consumeCommaIncludingWhitespace to simplify the code. No behavior change,
     43        just refactoring.
     44
     45        * css/parser/CSSParserImpl.cpp:
     46        (WebCore::CSSParserImpl::consumeDeclaration): Updated algorithm to match
     47        the CSS specification, trimming whitespace correctly.
     48        (WebCore::CSSParserImpl::consumeCustomPropertyValue): Added support for
     49        a custom property value with no declaration value, as now called for in
     50        the CSS specification, using CSSCustomPropertyValue::createEmpty.
     51
     52        * css/parser/CSSVariableParser.cpp:
     53        (WebCore::isValidVariableReference): Allow empty fallback, as now called
     54        for in the CSS specification.
     55        (WebCore::isValidConstantReference): Ditto.
     56
    1572021-06-28  Dana Estra  <destra@apple.com>
    258
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r279218 r279358  
    24642464        return nullptr;
    24652465
    2466     auto* registered = styledElement->document().getCSSRegisteredCustomPropertySet().get(propertyName);
    24672466    auto* value = style->getCustomProperty(propertyName);
    2468 
    2469     if (registered && !value)
    2470         return registered->initialValueCopy();
    2471 
    2472     if (!value)
    2473         return nullptr;
    2474 
    2475     return WTF::switchOn(value->value(), [&](const Ref<CSSVariableReferenceValue>&) {
    2476         ASSERT_NOT_REACHED();
    2477         return RefPtr<CSSValue>();
    2478     }, [&](const CSSValueID&) {
    2479         return CSSCustomPropertyValue::create(*value);
    2480     }, [&](const Ref<CSSVariableData>&) {
    2481         return CSSCustomPropertyValue::create(*value);
    2482     }, [&](const Length& value) {
     2467    if (!value) {
     2468        auto registered = styledElement->document().getCSSRegisteredCustomPropertySet().get(propertyName);
     2469        return registered ? registered->initialValueCopy() : nullptr;
     2470    }
     2471
     2472    return WTF::switchOn(value->value(), [&](const Length& value) -> Ref<CSSValue> {
    24832473        return zoomAdjustedPixelValueForLength(value, *style);
    2484     }, [&](const Ref<StyleImage>&) {
     2474    }, [&](auto&) -> Ref<CSSValue> {
    24852475        return CSSCustomPropertyValue::create(*value);
    24862476    });
  • trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp

    r266717 r279358  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#include "config.h"
    2727#include "CSSCustomPropertyValue.h"
     28
    2829#include "CSSTokenizer.h"
    2930
    3031namespace WebCore {
    3132
     33Ref<CSSCustomPropertyValue> CSSCustomPropertyValue::createEmpty(const AtomString& name)
     34{
     35    return adoptRef(*new CSSCustomPropertyValue(name, Monostate { }));
     36}
     37
    3238bool CSSCustomPropertyValue::equals(const CSSCustomPropertyValue& other) const
    3339{
    34     if (this == &other)
    35         return true;
    3640    if (m_name != other.m_name || m_value.index() != other.m_value.index())
    3741        return false;
    38     return WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>& value) {
     42    return WTF::switchOn(m_value, [&](const Monostate&) {
     43        return true;
     44    }, [&](const Ref<CSSVariableReferenceValue>& value) {
    3945        return value.get() == WTF::get<Ref<CSSVariableReferenceValue>>(other.m_value).get();
    4046    }, [&](const CSSValueID& value) {
     
    5157String CSSCustomPropertyValue::customCSSText() const
    5258{
    53     if (!m_serialized) {
    54         m_serialized = true;
    55 
    56         WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>& value) {
     59    if (m_stringValue.isNull()) {
     60        WTF::switchOn(m_value, [&](const Monostate&) {
     61            m_stringValue = emptyString();
     62        }, [&](const Ref<CSSVariableReferenceValue>& value) {
    5763            m_stringValue = value->cssText();
    5864        }, [&](const CSSValueID& value) {
     
    7278{
    7379    Vector<CSSParserToken> result;
    74 
    75     WTF::switchOn(m_value, [&](const Ref<CSSVariableReferenceValue>&) {
     80    WTF::switchOn(m_value, [&](const Monostate&) {
     81        // Do nothing.
     82    }, [&](const Ref<CSSVariableReferenceValue>&) {
    7683        ASSERT_NOT_REACHED();
    7784    }, [&](const CSSValueID&) {
    78         // Do nothing
     85        // Do nothing.
    7986    }, [&](const Ref<CSSVariableData>& value) {
    8087        result.appendVector(value->tokens());
    81     }, [&](const Length&) {
    82         CSSTokenizer tokenizer(cssText());
    83 
    84         auto tokenizerRange = tokenizer.tokenRange();
    85         while (!tokenizerRange.atEnd())
    86             result.append(tokenizerRange.consume());
    87     }, [&](const Ref<StyleImage>&) {
    88         CSSTokenizer tokenizer(cssText());
    89 
     88    }, [&](auto&) {
     89        CSSTokenizer tokenizer(customCSSText());
    9090        auto tokenizerRange = tokenizer.tokenRange();
    9191        while (!tokenizerRange.atEnd())
    9292            result.append(tokenizerRange.consume());
    9393    });
    94 
    9594    return result;
    9695}
  • trunk/Source/WebCore/css/CSSCustomPropertyValue.h

    r259988 r279358  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636
    3737class CSSParserToken;
    38 class RenderStyle;
    3938
    4039class CSSCustomPropertyValue final : public CSSValue {
    4140public:
    42     using VariantValue = Variant<Ref<CSSVariableReferenceValue>, CSSValueID, Ref<CSSVariableData>, Length, Ref<StyleImage>>;
     41    using VariantValue = Variant<Monostate, Ref<CSSVariableReferenceValue>, CSSValueID, Ref<CSSVariableData>, Length, Ref<StyleImage>>;
     42
     43    static Ref<CSSCustomPropertyValue> createEmpty(const AtomString& name);
    4344
    4445    static Ref<CSSCustomPropertyValue> createUnresolved(const AtomString& name, Ref<CSSVariableReferenceValue>&& value)
     
    7980        return adoptRef(*new CSSCustomPropertyValue(other));
    8081    }
    81    
     82
    8283    String customCSSText() const;
    8384
     
    9091
    9192    Vector<CSSParserToken> tokens() const;
    92     bool equals(const CSSCustomPropertyValue& other) const;
     93    bool equals(const CSSCustomPropertyValue&) const;
    9394
    9495private:
     
    9798        , m_name(name)
    9899        , m_value(WTFMove(value))
    99         , m_serialized(false)
    100100    {
    101101    }
     
    104104        : CSSValue(CustomPropertyClass)
    105105        , m_name(other.m_name)
    106         , m_value(CSSValueUnset)
     106        , m_value(other.m_value)
    107107        , m_stringValue(other.m_stringValue)
    108         , m_serialized(other.m_serialized)
    109108    {
    110         // No copy constructor for Ref<>, so we have to do this ourselves
    111         auto visitor = WTF::makeVisitor([&](const Ref<CSSVariableReferenceValue>& value) {
    112             m_value = value.copyRef();
    113         }, [&](const CSSValueID& value) {
    114             m_value = value;
    115         }, [&](const Ref<CSSVariableData>& value) {
    116             m_value = value.copyRef();
    117         }, [&](const Length& value) {
    118             m_value = value;
    119         }, [&](const Ref<StyleImage>& value) {
    120             m_value = value.copyRef();
    121         });
    122         WTF::visit(visitor, other.m_value);
    123109    }
    124    
     110
    125111    const AtomString m_name;
    126     VariantValue m_value;
    127    
     112    const VariantValue m_value;
    128113    mutable String m_stringValue;
    129     mutable bool m_serialized { false }; // FIXME: Should use null m_stringValue instead of a separate boolean.
    130114};
    131115
  • trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp

    r266989 r279358  
    6969        return false;
    7070    ASSERT(range.peek().type() == CommaToken);
    71     range.consume();
     71    range.consumeIncludingWhitespace();
    7272    return resolveTokenRange(range, result, builderState);
    7373}
  • trunk/Source/WebCore/css/calc/CSSCalcExpressionNodeParser.cpp

    r278891 r279358  
    3636#include "CSSParserToken.h"
    3737#include "CSSParserTokenRange.h"
     38#include "CSSPropertyParserHelpers.h"
    3839#include "Logging.h"
    3940#include <wtf/text/TextStream.h>
     
    138139    while (!tokens.atEnd()) {
    139140        tokens.consumeWhitespace();
    140         if (requireComma) {
    141             if (tokens.consume().type() != CommaToken)
    142                 return false;
    143             tokens.consumeWhitespace();
    144         }
     141        if (requireComma && !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(tokens))
     142            return false;
    145143
    146144        RefPtr<CSSCalcExpressionNode> node;
  • trunk/Source/WebCore/css/parser/CSSParserImpl.cpp

    r278933 r279358  
    801801}
    802802
     803static void removeTrailingWhitespace(const CSSParserTokenRange& range, const CSSParserToken*& position)
     804{
     805    while (position != range.begin() && position[-1].type() == WhitespaceToken)
     806        --position;
     807}
     808
     809// https://drafts.csswg.org/css-syntax/#consume-declaration
    803810void CSSParserImpl::consumeDeclaration(CSSParserTokenRange range, StyleRuleType ruleType)
    804811{
     
    806813
    807814    ASSERT(range.peek().type() == IdentToken);
    808     const CSSParserToken& token = range.consumeIncludingWhitespace();
    809     CSSPropertyID propertyID = token.parseAsCSSPropertyID();
     815    auto& token = range.consumeIncludingWhitespace();
     816    auto propertyID = token.parseAsCSSPropertyID();
    810817    if (range.consume().type() != ColonToken)
    811818        return; // Parse error
     819    range.consumeWhitespace();
     820
     821    auto declarationValueEnd = range.end();
     822    bool important = false;
     823    if (!range.atEnd()) {
     824        auto end = range.end();
     825        removeTrailingWhitespace(range, end);
     826        declarationValueEnd = end;
     827        if (end[-1].type() == IdentToken && equalIgnoringASCIICase(end[-1].value(), "important")) {
     828            --end;
     829            removeTrailingWhitespace(range, end);
     830            if (end[-1].type() == DelimiterToken && end[-1].delimiter() == '!') {
     831                important = true;
     832                --end;
     833                removeTrailingWhitespace(range, end);
     834                declarationValueEnd = end;
     835            }
     836        }
     837    }
     838
     839    size_t propertiesCount = m_parsedProperties.size();
    812840
    813841    if (m_context.isPropertyRuntimeDisabled(propertyID) || isInternalCSSProperty(propertyID))
    814842        propertyID = CSSPropertyInvalid;
    815843
    816     bool important = false;
    817     const CSSParserToken* declarationValueEnd = range.end();
    818     const CSSParserToken* last = range.end() - 1;
    819     while (last->type() == WhitespaceToken)
    820         --last;
    821     if (last->type() == IdentToken && equalIgnoringASCIICase(last->value(), "important")) {
    822         --last;
    823         while (last->type() == WhitespaceToken)
    824             --last;
    825         if (last->type() == DelimiterToken && last->delimiter() == '!') {
    826             important = true;
    827             declarationValueEnd = last;
    828         }
    829     }
    830 
    831     size_t propertiesCount = m_parsedProperties.size();
    832844    if (propertyID == CSSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) {
    833845        AtomString variableName = token.value().toAtomString();
     
    850862void CSSParserImpl::consumeCustomPropertyValue(CSSParserTokenRange range, const AtomString& variableName, bool important)
    851863{
    852     if (RefPtr<CSSCustomPropertyValue> value = CSSVariableParser::parseDeclarationValue(variableName, range, m_context))
     864    if (range.atEnd())
     865        m_parsedProperties.append(CSSProperty(CSSPropertyCustom, CSSCustomPropertyValue::createEmpty(variableName), important));
     866    else if (auto value = CSSVariableParser::parseDeclarationValue(variableName, range, m_context))
    853867        m_parsedProperties.append(CSSProperty(CSSPropertyCustom, WTFMove(value), important));
    854868}
  • trunk/Source/WebCore/css/parser/CSSVariableParser.cpp

    r246490 r279358  
    3434#include "CSSParserContext.h"
    3535#include "CSSParserTokenRange.h"
     36#include "CSSPropertyParserHelpers.h"
    3637
    3738namespace WebCore {
     
    5657}
    5758
    58 bool isValidVariableReference(CSSParserTokenRange, bool& hasAtApplyRule, const CSSParserContext&);
    59 bool isValidConstantReference(CSSParserTokenRange, bool& hasAtApplyRule, const CSSParserContext&);
     59static bool isValidVariableReference(CSSParserTokenRange, bool& hasAtApplyRule, const CSSParserContext&);
     60static bool isValidConstantReference(CSSParserTokenRange, bool& hasAtApplyRule, const CSSParserContext&);
    6061
    6162static bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool& hasAtApplyRule, const CSSParserContext& parserContext, bool isTopLevelBlock = true)
     
    127128        return true;
    128129
    129     if (range.consume().type() != CommaToken)
     130    if (!CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range))
    130131        return false;
    131132    if (range.atEnd())
    132         return false;
     133        return true;
    133134
    134135    bool hasReferences = false;
     
    144145        return true;
    145146
    146     if (range.consume().type() != CommaToken)
     147    if (!CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range))
    147148        return false;
    148149    if (range.atEnd())
    149         return false;
     150        return true;
    150151
    151152    bool hasReferences = false;
Note: See TracChangeset for help on using the changeset viewer.