CSS3 calc: add isZero implementations to catch divide by zero
authormikelawther@chromium.org <mikelawther@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2012 20:22:03 +0000 (20:22 +0000)
committermikelawther@chromium.org <mikelawther@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2012 20:22:03 +0000 (20:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78603

Reviewed by Ojan Vafai.

Source/WebCore:

* css/CSSCalculationValue.cpp:
(WebCore::CSSCalcPrimitiveValue::isZero):
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcBinaryOperation::isZero):
(CSSCalcBinaryOperation):
* css/CSSCalculationValue.h:
(CSSCalcExpressionNode):

LayoutTests:

* css3/calc/calc-errors-expected.txt:

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

LayoutTests/ChangeLog
LayoutTests/css3/calc/calc-errors-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSCalculationValue.h

index 8dbb370..c8521a5 100644 (file)
@@ -1,3 +1,12 @@
+2012-02-14  Mike Lawther  <mikelawther@chromium.org>
+
+        CSS3 calc: add isZero implementations to catch divide by zero
+        https://bugs.webkit.org/show_bug.cgi?id=78603
+
+        Reviewed by Ojan Vafai.
+
+        * css3/calc/calc-errors-expected.txt:
+
 2012-02-14  Tony Chang  <tony@chromium.org>
 
         [chromium] Unreviewed, marking a perf test as slow in debug and two
index 1e5e218..ec814f4 100644 (file)
@@ -3,7 +3,7 @@ All boxes below should be 100px * 100px and green.
 unclosed calc => PASS
 unclosed calc with garbage => PASS
 garbage => PASS
-zero division => FAIL: expected width of 100, but was 0
+zero division => PASS
 non length => PASS
 number + length => PASS
 length + number => PASS
index 0fba182..6362c43 100644 (file)
@@ -1,3 +1,18 @@
+2012-02-14  Mike Lawther  <mikelawther@chromium.org>
+
+        CSS3 calc: add isZero implementations to catch divide by zero
+        https://bugs.webkit.org/show_bug.cgi?id=78603
+
+        Reviewed by Ojan Vafai.
+
+        * css/CSSCalculationValue.cpp:
+        (WebCore::CSSCalcPrimitiveValue::isZero):
+        (CSSCalcPrimitiveValue):
+        (WebCore::CSSCalcBinaryOperation::isZero):
+        (CSSCalcBinaryOperation):
+        * css/CSSCalculationValue.h:
+        (CSSCalcExpressionNode):
+
 2012-02-12  Timothy Hatcher  <timothy@apple.com>
 
         Don't include CachedResources that haven't downloaded when populating the Web Inspector on load.
index eeb761a..8dd0c8e 100755 (executable)
@@ -99,6 +99,11 @@ public:
         return adoptRef(new CSSCalcPrimitiveValue(value, isInteger));
     }
     
+    virtual bool isZero() const
+    {
+        return !m_value->getDoubleValue();
+    }
+
     virtual String cssText() const
     {
         return m_value->cssText();
@@ -193,6 +198,11 @@ public:
         return adoptRef(new CSSCalcBinaryOperation(leftSide, rightSide, op, newCategory));
     }
     
+    virtual bool isZero() const
+    {
+        return !doubleValue();
+    }
+
     virtual double doubleValue() const 
     {
         return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue());
index 93820a3..2dbf429 100755 (executable)
@@ -59,12 +59,12 @@ class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
 public:
     
     virtual ~CSSCalcExpressionNode() = 0;  
+    virtual bool isZero() const = 0;
     virtual double doubleValue() const = 0;  
     virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
     
     CalculationCategory category() const { return m_category; }    
     bool isInteger() const { return m_isInteger; }
-    bool isZero() const { return false; }
     
 protected:
     CSSCalcExpressionNode(CalculationCategory category, bool isInteger)