ASSERTION FAILED: leftCategory != CalcOther && rightCategory != CalcOther
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 17:08:43 +0000 (17:08 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 17:08:43 +0000 (17:08 +0000)
in WebCore::CSSCalcBinaryOperation::createSimplified
https://bugs.webkit.org/show_bug.cgi?id=132870

Source/WebCore:
According to the standard, calc() should be able to handle angle, time
and frequency values as well: http://www.w3.org/TR/css3-values/#calc

Patch by Martin Hodovan <mhodovan.u-szeged@partner.samsung.com> on 2014-05-13
Reviewed by Darin Adler.

Test: fast/css/calc-with-angle-time-frequency.html

* css/CSSCalculationValue.cpp:
(WebCore::unitCategory):
(WebCore::CSSCalcPrimitiveValue::createCalcExpression):
(WebCore::CSSCalcPrimitiveValue::computeLengthPx):
(WebCore::CSSCalcPrimitiveValue::addSubtractResult):
(WebCore::CSSCalcPrimitiveValue::determineCategory):
(WebCore::CSSCalcBinaryOperation::primitiveType)
* css/CSSCalculationValue.h: extending CalculationCategory
* css/CSSParser.cpp:
(WebCore::CSSParser::validCalculationUnit):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::primitiveType):

LayoutTests:
Added test contains calc() expressions with angle, time and frequency values,
covering all the newly introduced unit types, each of which used to fail.

Patch by Martin Hodovan <mhodovan.u-szeged@partner.samsung.com> on 2014-05-13
Reviewed by Darin Adler.

* fast/css/calc-with-angle-time-frequency-expected.txt: Added.
* fast/css/calc-with-angle-time-frequency.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168685 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/calc-with-angle-time-frequency-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/calc-with-angle-time-frequency.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSCalculationValue.h
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSPrimitiveValue.cpp

index 8211ee8..156a38e 100644 (file)
@@ -1,3 +1,17 @@
+2014-05-13  Martin Hodovan  <mhodovan.u-szeged@partner.samsung.com>
+
+        ASSERTION FAILED: leftCategory != CalcOther && rightCategory != CalcOther
+        in WebCore::CSSCalcBinaryOperation::createSimplified
+        https://bugs.webkit.org/show_bug.cgi?id=132870
+
+        Added test contains calc() expressions with angle, time and frequency values,
+        covering all the newly introduced unit types, each of which used to fail. 
+
+        Reviewed by Darin Adler.
+
+        * fast/css/calc-with-angle-time-frequency-expected.txt: Added.
+        * fast/css/calc-with-angle-time-frequency.html: Added.
+
 2014-05-13  Krzysztof Wolanski  <k.wolanski@samsung.com>
 
         [EFL] Rebaseline after r168575
diff --git a/LayoutTests/fast/css/calc-with-angle-time-frequency-expected.txt b/LayoutTests/fast/css/calc-with-angle-time-frequency-expected.txt
new file mode 100644 (file)
index 0000000..654ddf7
--- /dev/null
@@ -0,0 +1 @@
+This test passes if it does not crash.
diff --git a/LayoutTests/fast/css/calc-with-angle-time-frequency.html b/LayoutTests/fast/css/calc-with-angle-time-frequency.html
new file mode 100644 (file)
index 0000000..b67e8a7
--- /dev/null
@@ -0,0 +1,25 @@
+<html>
+    <head>
+        <script>
+            if (window.testRunner)
+                testRunner.dumpAsText();
+        </script>
+        <style>
+            * {
+                width: calc(300deg/2);
+                width: calc(300rad/2);
+                width: calc(300grad/2);
+                width: calc(300turn/2);
+
+                width: calc(300ms/2);
+                width: calc(300s/2);
+
+                width: calc(300hz/2);
+                width: calc(300khz/2);
+            }
+        </style>
+    </head>
+    <body>
+        This test passes if it does not crash.
+    </body>
+</html>
index a58896b..6f1c4a5 100644 (file)
@@ -1,3 +1,29 @@
+2014-05-13  Martin Hodovan  <mhodovan.u-szeged@partner.samsung.com>
+
+        ASSERTION FAILED: leftCategory != CalcOther && rightCategory != CalcOther
+        in WebCore::CSSCalcBinaryOperation::createSimplified
+        https://bugs.webkit.org/show_bug.cgi?id=132870
+
+        According to the standard, calc() should be able to handle angle, time
+        and frequency values as well: http://www.w3.org/TR/css3-values/#calc
+
+        Reviewed by Darin Adler.
+
+        Test: fast/css/calc-with-angle-time-frequency.html
+
+        * css/CSSCalculationValue.cpp:
+        (WebCore::unitCategory):
+        (WebCore::CSSCalcPrimitiveValue::createCalcExpression):
+        (WebCore::CSSCalcPrimitiveValue::computeLengthPx):
+        (WebCore::CSSCalcPrimitiveValue::addSubtractResult):
+        (WebCore::CSSCalcPrimitiveValue::determineCategory):
+        (WebCore::CSSCalcBinaryOperation::primitiveType)
+        * css/CSSCalculationValue.h: extending CalculationCategory
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::validCalculationUnit):
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::primitiveType):
+
 2014-05-13  Darin Adler  <darin@apple.com>
 
         Try to fix the !ENABLE(ICONDATABASE) build
index 4ad8e34..ee9c631 100644 (file)
@@ -56,8 +56,6 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitTypes type)
     case CSSPrimitiveValue::CSS_NUMBER:
     case CSSPrimitiveValue::CSS_PARSER_INTEGER:
         return CalcNumber;
-    case CSSPrimitiveValue::CSS_PERCENTAGE:
-        return CalcPercent;
     case CSSPrimitiveValue::CSS_EMS:
     case CSSPrimitiveValue::CSS_EXS:
     case CSSPrimitiveValue::CSS_PX:
@@ -69,6 +67,19 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitTypes type)
     case CSSPrimitiveValue::CSS_REMS:
     case CSSPrimitiveValue::CSS_CHS:
         return CalcLength;
+    case CSSPrimitiveValue::CSS_PERCENTAGE:
+        return CalcPercent;
+    case CSSPrimitiveValue::CSS_DEG:
+    case CSSPrimitiveValue::CSS_RAD:
+    case CSSPrimitiveValue::CSS_GRAD:
+    case CSSPrimitiveValue::CSS_TURN:
+        return CalcAngle;
+    case CSSPrimitiveValue::CSS_MS:
+    case CSSPrimitiveValue::CSS_S:
+        return CalcTime;
+    case CSSPrimitiveValue::CSS_HZ:
+    case CSSPrimitiveValue::CSS_KHZ:
+        return CalcFrequency;
     default:
         return CalcOther;
     }
@@ -218,6 +229,9 @@ private:
         // Only types that could be part of a Length expression can be converted
         // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length.
         case CalcPercentNumber:
+        case CalcAngle:
+        case CalcTime:
+        case CalcFrequency:
         case CalcOther:
             ASSERT_NOT_REACHED();
         }
@@ -242,6 +256,9 @@ private:
             return m_value->getDoubleValue();
         case CalcPercentLength:
         case CalcPercentNumber:
+        case CalcAngle:
+        case CalcTime:
+        case CalcFrequency:
         case CalcOther:
             ASSERT_NOT_REACHED();
             break;
@@ -274,7 +291,7 @@ private:
     RefPtr<CSSPrimitiveValue> m_value;
 };
 
-static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = {
+static const CalculationCategory addSubtractResult[CalcAngle][CalcAngle] = {
 //    CalcNumber         CalcLength         CalcPercent        CalcPercentNumber  CalcPercentLength
     { CalcNumber,        CalcOther,         CalcPercentNumber, CalcPercentNumber, CalcOther }, //         CalcNumber
     { CalcOther,         CalcLength,        CalcPercentLength, CalcOther,         CalcPercentLength }, // CalcLength
@@ -294,7 +311,11 @@ static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi
     switch (op) {
     case CalcAdd:
     case CalcSubtract:
-        return addSubtractResult[leftCategory][rightCategory];
+        if (leftCategory < CalcAngle || rightCategory < CalcAngle)
+            return addSubtractResult[leftCategory][rightCategory];
+        if (leftCategory == rightCategory)
+            return leftCategory;
+        return CalcOther;
     case CalcMultiply:
         if (leftCategory != CalcNumber && rightCategory != CalcNumber)
             return CalcOther;
@@ -470,6 +491,12 @@ private:
         }
         case CalcPercentLength:
         case CalcPercentNumber:
+        case CalcAngle:
+            return CSSPrimitiveValue::CSS_DEG;
+        case CalcTime:
+            return CSSPrimitiveValue::CSS_MS;
+        case CalcFrequency:
+            return CSSPrimitiveValue::CSS_HZ;
         case CalcOther:
             return CSSPrimitiveValue::CSS_UNKNOWN;
         }
index afb601d..df68676 100644 (file)
@@ -46,6 +46,9 @@ enum CalculationCategory {
     CalcPercent,
     CalcPercentNumber,
     CalcPercentLength,
+    CalcAngle,
+    CalcTime,
+    CalcFrequency,
     CalcOther
 };
 
index ae236a5..241f967 100644 (file)
@@ -1558,6 +1558,13 @@ bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags, Rel
 
     bool b = false;
     switch (m_parsedCalculation->category()) {
+    case CalcNumber:
+        b = (unitflags & FNumber);
+        if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
+            b = true;
+        if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
+            b = false;
+        break;
     case CalcLength:
         b = (unitflags & FLength);
         break;
@@ -1566,19 +1573,21 @@ bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags, Rel
         if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
             b = false;
         break;
-    case CalcNumber:
-        b = (unitflags & FNumber);
-        if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
-            b = true;
-        if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
-            b = false;
-        break;
     case CalcPercentLength:
         b = (unitflags & FPercent) && (unitflags & FLength);
         break;
     case CalcPercentNumber:
         b = (unitflags & FPercent) && (unitflags & FNumber);
         break;
+    case CalcAngle:
+        b = (unitflags & FAngle);
+        break;
+    case CalcTime:
+        b = (unitflags & FTime);
+        break;
+    case CalcFrequency:
+        b = (unitflags & FFrequency);
+        break;
     case CalcOther:
         break;
     }
index c4e4cb9..1dad8db 100644 (file)
@@ -193,14 +193,20 @@ unsigned short CSSPrimitiveValue::primitiveType() const
     switch (m_value.calc->category()) {
     case CalcNumber:
         return CSSPrimitiveValue::CSS_NUMBER;
-    case CalcPercent:
-        return CSSPrimitiveValue::CSS_PERCENTAGE;
     case CalcLength:
         return CSSPrimitiveValue::CSS_PX;
+    case CalcPercent:
+        return CSSPrimitiveValue::CSS_PERCENTAGE;
     case CalcPercentNumber:
         return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER;
     case CalcPercentLength:
         return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH;
+    case CalcAngle:
+        return CSSPrimitiveValue::CSS_DEG;
+    case CalcTime:
+        return CSSPrimitiveValue::CSS_MS;
+    case CalcFrequency:
+        return CSSPrimitiveValue::CSS_HZ;
     case CalcOther:
         return CSSPrimitiveValue::CSS_UNKNOWN;
     }