Changeset 217844 in webkit


Ignore:
Timestamp:
Jun 6, 2017, 11:27:53 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[css-conditional] The one-string version of CSS.supports should be wrapped in implied parentheses.
https://bugs.webkit.org/show_bug.cgi?id=172906

Patch by Emilio Cobos Álvarez <ecobos@igalia.com> on 2017-06-06
Reviewed by Darin Adler.

Source/WebCore:

From https://drafts.csswg.org/css-conditional/#the-css-interface:

When invoked with a single conditionText argument, it must return
true if conditionText, when either parsed and evaluated as a
supports_condition or parsed as a declaration, wrapped in implied
parentheses, and evaluated as a supports_condition, would return
true.

Note the "wrapped in implied parentheses" bit.

Gecko is fixing it in https://bugzil.la/1338486, and Blink in
https://crbug.com/729403.

Tests: css3/supports-dom-api.html

imported/w3c/web-platform-tests/cssom/CSS.html

  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseSupportsCondition):

  • css/parser/CSSParserImpl.cpp:

(WebCore::CSSParserImpl::consumeSupportsRule):

  • css/parser/CSSSupportsParser.cpp:

(WebCore::CSSSupportsParser::supportsCondition):

  • css/parser/CSSSupportsParser.h:

LayoutTests:

  • css3/supports-dom-api-expected.txt:
  • css3/supports-dom-api.html: Added test
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r217843 r217844  
     12017-06-06  Emilio Cobos Álvarez  <ecobos@igalia.com>
     2
     3        [css-conditional] The one-string version of CSS.supports should be wrapped in implied parentheses.
     4        https://bugs.webkit.org/show_bug.cgi?id=172906
     5
     6        Reviewed by Darin Adler.
     7
     8        * css3/supports-dom-api-expected.txt:
     9        * css3/supports-dom-api.html: Added test
     10
    1112017-06-06  Joseph Pecoraro  <pecoraro@apple.com>
    212
  • trunk/LayoutTests/css3/supports-dom-api-expected.txt

    r142739 r217844  
    44
    55
     6PASS CSS.supports("display: none") is true
    67PASS CSS.supports("(display: none)") is true
     8PASS CSS.supports("  display: none ") is true
    79PASS CSS.supports("(display: deadbeef)") is false
     10PASS CSS.supports("display: deadbeef") is false
     11PASS CSS.supports("(display: none) and ((display: block) or (display: inline))") is true
     12PASS CSS.supports("(not (display: deadbeef)) and (display: block)") is true
     13PASS CSS.supports("top: -webkit-calc(80% - 20px)") is true
     14PASS CSS.supports("background-color: rgb(0, 128, 0)") is true
     15PASS CSS.supports("background: url('/blah')") is true
     16PASS CSS.supports("background: invalid('/blah')") is false
     17PASS CSS.supports("display: none;") is false
     18PASS CSS.supports("display: none; garbage") is false
     19PASS CSS.supports("  display: none ; garbage ") is false
    820PASS CSS.supports("not (display: deadbeef)") is true
    921PASS CSS.supports("not (display: none)") is false
     
    2840PASS CSS.supports("(((((((display: none)))))))") is true
    2941PASS CSS.supports("(!important)") is false
     42PASS CSS.supports("!important") is false
    3043PASS CSS.supports("not not not not (display: none)") is false
    3144PASS CSS.supports("(top: -webkit-calc(80% - 20px))") is true
  • trunk/LayoutTests/css3/supports-dom-api.html

    r155275 r217844  
    88    description("Test window.CSS.supports()");
    99
     10    shouldBeTrue('CSS.supports("display: none")');
    1011    shouldBeTrue('CSS.supports("(display: none)")');
     12    shouldBeTrue('CSS.supports("  display: none ")');
    1113    shouldBeFalse('CSS.supports("(display: deadbeef)")');
     14
     15    shouldBeFalse('CSS.supports("display: deadbeef")');
     16    shouldBeTrue('CSS.supports("(display: none) and ((display: block) or (display: inline))")');
     17    shouldBeTrue('CSS.supports("(not (display: deadbeef)) and (display: block)")');
     18    shouldBeTrue('CSS.supports("top: -webkit-calc(80% - 20px)")');
     19    shouldBeTrue('CSS.supports("background-color: rgb(0, 128, 0)")');
     20    shouldBeTrue('CSS.supports("background: url(\'/blah\')")');
     21    shouldBeFalse('CSS.supports("background: invalid(\'/blah\')")');
     22    shouldBeFalse('CSS.supports("display: none;")');
     23    shouldBeFalse('CSS.supports("display: none; garbage")');
     24    shouldBeFalse('CSS.supports("  display: none ; garbage ")');
    1225
    1326    // Negation
     
    4457    shouldBeTrue('CSS.supports("(((((((display: none)))))))")');
    4558    shouldBeFalse('CSS.supports("(!important)")');
     59    shouldBeFalse('CSS.supports("!important")');
    4660    shouldBeFalse('CSS.supports("not not not not (display: none)")');
    4761
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cssom/CSS-expected.txt

    r217125 r217844  
    11
    22PASS CSS.escape
    3 FAIL CSS.supports, one argument form assert_equals: CSS.supports: Single-argument form allows for declarations without enclosing parentheses expected true but got false
     3PASS CSS.supports, one argument form
    44FAIL CSS.supports, two argument form assert_equals: CSS.supports: two argument form succeeds for custom property expected true but got false
    55
  • trunk/Source/WebCore/ChangeLog

    r217841 r217844  
     12017-06-06  Emilio Cobos Álvarez  <ecobos@igalia.com>
     2
     3        [css-conditional] The one-string version of CSS.supports should be wrapped in implied parentheses.
     4        https://bugs.webkit.org/show_bug.cgi?id=172906
     5
     6        Reviewed by Darin Adler.
     7
     8        From https://drafts.csswg.org/css-conditional/#the-css-interface:
     9
     10        > When invoked with a single conditionText argument, it must return
     11        > true if conditionText, when either parsed and evaluated as a
     12        > supports_condition or parsed as a declaration, wrapped in implied
     13        > parentheses, and evaluated as a supports_condition, would return
     14        > true.
     15
     16        Note the "wrapped in implied parentheses" bit.
     17
     18        Gecko is fixing it in https://bugzil.la/1338486, and Blink in
     19        https://crbug.com/729403.
     20
     21        Tests: css3/supports-dom-api.html
     22               imported/w3c/web-platform-tests/cssom/CSS.html
     23
     24        * css/parser/CSSParser.cpp:
     25        (WebCore::CSSParser::parseSupportsCondition):
     26        * css/parser/CSSParserImpl.cpp:
     27        (WebCore::CSSParserImpl::consumeSupportsRule):
     28        * css/parser/CSSSupportsParser.cpp:
     29        (WebCore::CSSSupportsParser::supportsCondition):
     30        * css/parser/CSSSupportsParser.h:
     31
    1322017-06-06  Joseph Pecoraro  <pecoraro@apple.com>
    233
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r216902 r217844  
    147147{
    148148    CSSParserImpl parser(m_context, condition);
    149     return CSSSupportsParser::supportsCondition(parser.tokenizer()->tokenRange(), parser) == CSSSupportsParser::Supported;
     149    return CSSSupportsParser::supportsCondition(parser.tokenizer()->tokenRange(), parser, CSSSupportsParser::ForWindowCSS) == CSSSupportsParser::Supported;
    150150}
    151151
  • trunk/Source/WebCore/css/parser/CSSParserImpl.cpp

    r216611 r217844  
    563563RefPtr<StyleRuleSupports> CSSParserImpl::consumeSupportsRule(CSSParserTokenRange prelude, CSSParserTokenRange block)
    564564{
    565     CSSSupportsParser::SupportsResult supported = CSSSupportsParser::supportsCondition(prelude, *this);
     565    CSSSupportsParser::SupportsResult supported = CSSSupportsParser::supportsCondition(prelude, *this, CSSSupportsParser::ForAtRule);
    566566    if (supported == CSSSupportsParser::Invalid)
    567567        return nullptr; // Parse error, invalid @supports condition
  • trunk/Source/WebCore/css/parser/CSSSupportsParser.cpp

    r209021 r217844  
    3535namespace WebCore {
    3636
    37 CSSSupportsParser::SupportsResult CSSSupportsParser::supportsCondition(CSSParserTokenRange range, CSSParserImpl& parser)
     37CSSSupportsParser::SupportsResult CSSSupportsParser::supportsCondition(CSSParserTokenRange range, CSSParserImpl& parser, SupportsParsingMode mode)
    3838{
    3939    // FIXME: The spec allows leading whitespace in @supports but not CSS.supports,
    4040    // but major browser vendors allow it in CSS.supports also.
    4141    range.consumeWhitespace();
    42     return CSSSupportsParser(parser).consumeCondition(range);
     42    CSSSupportsParser supportsParser(parser);
     43    auto result = supportsParser.consumeCondition(range);
     44    if (mode != ForWindowCSS || result != Invalid)
     45        return result;
     46    // window.CSS.supports requires parsing as-if the condition was wrapped in
     47    // parenthesis. The only productions that wouldn't have parsed above are the
     48    // declaration condition or the general enclosed productions.
     49    return supportsParser.consumeDeclarationConditionOrGeneralEnclosed(range);
    4350}
    4451
     
    106113}
    107114
     115CSSSupportsParser::SupportsResult CSSSupportsParser::consumeDeclarationConditionOrGeneralEnclosed(CSSParserTokenRange& range)
     116{
     117    if (range.peek().type() == FunctionToken) {
     118        range.consumeComponentValue();
     119        return Unsupported;
     120    }
     121
     122    return range.peek().type() == IdentToken && m_parser.supportsDeclaration(range) ? Supported : Unsupported;
     123}
     124
    108125CSSSupportsParser::SupportsResult CSSSupportsParser::consumeConditionInParenthesis(CSSParserTokenRange& range, CSSParserTokenType startTokenType)
    109126{
     
    116133    if (result != Invalid)
    117134        return result;
    118    
    119     if (innerRange.peek().type() == FunctionToken) {
    120         innerRange.consumeComponentValue();
    121         return Unsupported;
    122     }
    123 
    124     return innerRange.peek().type() == IdentToken && m_parser.supportsDeclaration(innerRange) ? Supported : Unsupported;
     135    return consumeDeclarationConditionOrGeneralEnclosed(innerRange);
    125136}
    126137
  • trunk/Source/WebCore/css/parser/CSSSupportsParser.h

    r209021 r217844  
    4545    };
    4646
    47     static SupportsResult supportsCondition(CSSParserTokenRange, CSSParserImpl&);
     47    enum SupportsParsingMode {
     48        ForAtRule,
     49        ForWindowCSS,
     50    };
     51
     52    static SupportsResult supportsCondition(CSSParserTokenRange, CSSParserImpl&, SupportsParsingMode);
    4853
    4954private:
     
    5358    SupportsResult consumeCondition(CSSParserTokenRange);
    5459    SupportsResult consumeNegation(CSSParserTokenRange);
     60    SupportsResult consumeDeclarationConditionOrGeneralEnclosed(CSSParserTokenRange&);
    5561
    5662    SupportsResult consumeConditionInParenthesis(CSSParserTokenRange&, CSSParserTokenType);
Note: See TracChangeset for help on using the changeset viewer.