Crash when setting '-webkit-line-clamp' CSS property to a calculated value
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Nov 2014 01:18:32 +0000 (01:18 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Nov 2014 01:18:32 +0000 (01:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138777

Reviewed by Benjamin Poulain.

Source/WebCore:

CSS Calculated values were not handled when converting a CSSPrimitiveValue
to a LineClampValue. As a result, we would hit an ASSERT_NOT_REACHED()
assertion. To address this issue, this patch updates the code to use
primitiveType() / getValue<>() instead of m_primitiveUnitType /
m_value.num, as those getter function properly handle CSS Calculated
values.

Test: fast/css/webkit-line-clamp-calculated-value.html

* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::operator LineClampValue):

LayoutTests:

Add a layout test to check that assigning calculated values to the
'-webkit-line-clamp' CSS property does not crash and behaves as
expected.

* fast/css/webkit-line-clamp-calculated-value-expected.txt: Added.
* fast/css/webkit-line-clamp-calculated-value.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css/webkit-line-clamp-calculated-value-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/webkit-line-clamp-calculated-value.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSPrimitiveValueMappings.h

index d719ac8..b734057 100644 (file)
@@ -1,3 +1,17 @@
+2014-11-16  Chris Dumez  <cdumez@apple.com>
+
+        Crash when setting '-webkit-line-clamp' CSS property to a calculated value
+        https://bugs.webkit.org/show_bug.cgi?id=138777
+
+        Reviewed by Benjamin Poulain.
+
+        Add a layout test to check that assigning calculated values to the
+        '-webkit-line-clamp' CSS property does not crash and behaves as
+        expected.
+
+        * fast/css/webkit-line-clamp-calculated-value-expected.txt: Added.
+        * fast/css/webkit-line-clamp-calculated-value.html: Added.
+
 2014-11-16  Joanmarie Diggs  <jdiggs@igalia.com>
 
         AX: [ATK] Expose the blockquote element using ATK_ROLE_BLOCK_QUOTE
diff --git a/LayoutTests/fast/css/webkit-line-clamp-calculated-value-expected.txt b/LayoutTests/fast/css/webkit-line-clamp-calculated-value-expected.txt
new file mode 100644 (file)
index 0000000..c25c340
--- /dev/null
@@ -0,0 +1,16 @@
+Tests assigning a calculated value to -webkit-line-clamp CSS property.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testDiv.style['-webkit-line-clamp'] is ""
+testDiv.style['-webkit-line-clamp'] = 'calc(10% * 2)'
+PASS testDiv.style['-webkit-line-clamp'] is "calc(20%)"
+PASS window.getComputedStyle(testDiv).getPropertyValue('-webkit-line-clamp') is "20%"
+testDiv.style['-webkit-line-clamp'] = 'calc(2 * 3)'
+PASS testDiv.style['-webkit-line-clamp'] is "calc(6)"
+PASS window.getComputedStyle(testDiv).getPropertyValue('-webkit-line-clamp') is "6"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/webkit-line-clamp-calculated-value.html b/LayoutTests/fast/css/webkit-line-clamp-calculated-value.html
new file mode 100644 (file)
index 0000000..67bf17a
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<div id="testDiv"></div>
+<script>
+description("Tests assigning a calculated value to -webkit-line-clamp CSS property.");
+
+var testDiv = document.getElementById("testDiv");
+
+shouldBeEmptyString("testDiv.style['-webkit-line-clamp']");
+evalAndLog("testDiv.style['-webkit-line-clamp'] = 'calc(10% * 2)'");
+shouldBeEqualToString("testDiv.style['-webkit-line-clamp']", "calc(20%)");
+shouldBeEqualToString("window.getComputedStyle(testDiv).getPropertyValue('-webkit-line-clamp')", "20%");
+evalAndLog("testDiv.style['-webkit-line-clamp'] = 'calc(2 * 3)'");
+shouldBeEqualToString("testDiv.style['-webkit-line-clamp']", "calc(6)");
+shouldBeEqualToString("window.getComputedStyle(testDiv).getPropertyValue('-webkit-line-clamp')", "6");
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
index 76515c9..60dd0b3 100644 (file)
@@ -1,3 +1,22 @@
+2014-11-16  Chris Dumez  <cdumez@apple.com>
+
+        Crash when setting '-webkit-line-clamp' CSS property to a calculated value
+        https://bugs.webkit.org/show_bug.cgi?id=138777
+
+        Reviewed by Benjamin Poulain.
+
+        CSS Calculated values were not handled when converting a CSSPrimitiveValue
+        to a LineClampValue. As a result, we would hit an ASSERT_NOT_REACHED()
+        assertion. To address this issue, this patch updates the code to use
+        primitiveType() / getValue<>() instead of m_primitiveUnitType /
+        m_value.num, as those getter function properly handle CSS Calculated
+        values.
+
+        Test: fast/css/webkit-line-clamp-calculated-value.html
+
+        * css/CSSPrimitiveValueMappings.h:
+        (WebCore::CSSPrimitiveValue::operator LineClampValue):
+
 2014-11-16  Tim Horton  <timothy_horton@apple.com>
 
         Use TextIndicator instead of the built in Lookup highlight
index 01035ac..8165e3b 100644 (file)
@@ -133,11 +133,11 @@ template<> inline CSSPrimitiveValue::CSSPrimitiveValue(LineClampValue i)
 
 template<> inline CSSPrimitiveValue::operator LineClampValue() const
 {
-    if (m_primitiveUnitType == CSS_NUMBER)
-        return LineClampValue(clampTo<int>(m_value.num), LineClampLineCount);
+    if (primitiveType() == CSS_NUMBER)
+        return LineClampValue(getValue<int>(), LineClampLineCount);
 
-    if (m_primitiveUnitType == CSS_PERCENTAGE)
-        return LineClampValue(clampTo<int>(m_value.num), LineClampPercentage);
+    if (primitiveType() == CSS_PERCENTAGE)
+        return LineClampValue(getValue<int>(), LineClampPercentage);
 
     ASSERT_NOT_REACHED();
     return LineClampValue();