Changeset 291911 in webkit


Ignore:
Timestamp:
Mar 25, 2022 6:45:25 PM (4 months ago)
Author:
Nikos Mouchtaris
Message:

Incorrect handling of NaN inside calc() for top-level calculation
https://bugs.webkit.org/show_bug.cgi?id=234176

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-values/calc-infinity-nan-computed-expected.txt: Added.
  • web-platform-tests/css/css-values/calc-infinity-nan-computed.html: Added.
  • web-platform-tests/css/css-values/round-function-expected.txt:
  • web-platform-tests/css/css-values/round-function.html:

Source/WebCore:

Add function to convert any top level NaN values to infinity values as per the spec.
This only affects the computed value of the calc expression, not its serialization.

Test: imported/w3c/web-platform-tests/css/css-values/calc-infinity-nan-computed.html

  • css/calc/CSSCalcOperationNode.cpp:

(WebCore::CSSCalcOperationNode::combineChildren):
(WebCore::convertToTopLevelValue):
(WebCore::CSSCalcOperationNode::evaluateOperator):

  • css/calc/CSSCalcOperationNode.h:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291888 r291911  
     12022-03-25  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Incorrect handling of NaN inside calc() for top-level calculation
     4        https://bugs.webkit.org/show_bug.cgi?id=234176
     5
     6        Reviewed by Simon Fraser.
     7
     8        * web-platform-tests/css/css-values/calc-infinity-nan-computed-expected.txt: Added.
     9        * web-platform-tests/css/css-values/calc-infinity-nan-computed.html: Added.
     10        * web-platform-tests/css/css-values/round-function-expected.txt:
     11        * web-platform-tests/css/css-values/round-function.html:
     12
    1132022-03-25  Youenn Fablet  <youenn@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-function-expected.txt

    r291841 r291911  
    3636PASS round(-13px, -10px) should be used-value-equivalent to -10px
    3737PASS round(-18px, -10px) should be used-value-equivalent to -20px
    38 PASS round(5, 0) should be used-value-equivalent to calc(NaN)
    39 PASS calc(-1 * round(5, 0)) should be used-value-equivalent to calc(NaN)
    40 PASS round(infinity, infinity) should be used-value-equivalent to calc(NaN)
    41 PASS calc(-1 * round(infinity, infinity)) should be used-value-equivalent to calc(NaN)
    42 PASS round(infinity, -infinity) should be used-value-equivalent to calc(NaN)
    43 PASS calc(-1 * round(infinity, -infinity)) should be used-value-equivalent to calc(NaN)
    44 PASS round(-infinity, infinity) should be used-value-equivalent to calc(NaN)
    45 PASS calc(-1 * round(-infinity, infinity)) should be used-value-equivalent to calc(NaN)
    46 PASS round(-infinity, -infinity) should be used-value-equivalent to calc(NaN)
    47 PASS calc(-1 * round(-infinity, -infinity)) should be used-value-equivalent to calc(NaN)
     38PASS round(5, 0) should be used-value-equivalent to calc(infinity)
     39PASS round(infinity, infinity) should be used-value-equivalent to calc(infinity)
     40PASS round(infinity, -infinity) should be used-value-equivalent to calc(infinity)
     41PASS round(-infinity, infinity) should be used-value-equivalent to calc(infinity)
     42PASS round(-infinity, -infinity) should be used-value-equivalent to calc(infinity)
    4843PASS round(infinity, 5) should be used-value-equivalent to calc(infinity)
    4944PASS round(infinity, -5) should be used-value-equivalent to calc(infinity)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/round-function.html

    r264522 r291911  
    6262
    6363// 0 step is NaN
    64 test_nan("round(5, 0)");
     64test_plus_infinity("round(5, 0)");
    6565// both infinite is NaN
    66 test_nan("round(infinity, infinity)");
    67 test_nan("round(infinity, -infinity)");
    68 test_nan("round(-infinity, infinity)");
    69 test_nan("round(-infinity, -infinity)");
     66test_plus_infinity("round(infinity, infinity)");
     67test_plus_infinity("round(infinity, -infinity)");
     68test_plus_infinity("round(-infinity, infinity)");
     69test_plus_infinity("round(-infinity, -infinity)");
    7070
    7171// infinite value with finite step is the same infinity
  • trunk/Source/WebCore/ChangeLog

    r291902 r291911  
     12022-03-25  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
     2
     3        Incorrect handling of NaN inside calc() for top-level calculation
     4        https://bugs.webkit.org/show_bug.cgi?id=234176
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add function to convert any top level NaN values to infinity values as per the spec.
     9        This only affects the computed value of the calc expression, not its serialization.
     10
     11        Test: imported/w3c/web-platform-tests/css/css-values/calc-infinity-nan-computed.html
     12
     13        * css/calc/CSSCalcOperationNode.cpp:
     14        (WebCore::CSSCalcOperationNode::combineChildren):
     15        (WebCore::convertToTopLevelValue):
     16        (WebCore::CSSCalcOperationNode::evaluateOperator):
     17        * css/calc/CSSCalcOperationNode.h:
     18
    1192022-03-25  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp

    r291841 r291911  
    624624    if (isIdentity() || !m_children.size())
    625625        return;
    626 
     626    m_isRoot = IsRoot::No;
     627   
    627628    if (m_children.size() < 2) {
    628629        if (m_children.size() == 1 && isTrigNode()) {
  • trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h

    r291516 r291911  
    3434    WTF_MAKE_FAST_ALLOCATED;
    3535public:
     36    enum class IsRoot : bool { No, Yes };
     37   
    3638    static RefPtr<CSSCalcOperationNode> create(CalcOperator, RefPtr<CSSCalcExpressionNode>&& leftSide, RefPtr<CSSCalcExpressionNode>&& rightSide);
    3739    static RefPtr<CSSCalcOperationNode> createSum(Vector<Ref<CSSCalcExpressionNode>>&& values);
     
    126128        return nullptr;
    127129    }
    128 
     130   
     131    static double convertToTopLevelValue(double value)
     132    {
     133        if (isnan(value))
     134            value = std::numeric_limits<double>::infinity();
     135        return value;
     136    }
     137   
    129138    double evaluate(const Vector<double>& children) const
    130139    {
    131         return evaluateOperator(m_operator, children);
     140        auto result = evaluateOperator(m_operator, children);
     141        return m_isRoot == IsRoot::No ? result : convertToTopLevelValue(result);
    132142    }
    133143
     
    145155    Vector<Ref<CSSCalcExpressionNode>> m_children;
    146156    bool m_allowsNegativePercentageReference = false;
     157    IsRoot m_isRoot = IsRoot::Yes;
    147158};
    148159
Note: See TracChangeset for help on using the changeset viewer.