Title: [295425] trunk
Revision
295425
Author
achristen...@apple.com
Date
2022-06-09 11:21:03 -0700 (Thu, 09 Jun 2022)

Log Message

convertingToLengthRequiresNonNullStyle needs to consider calc values
https://bugs.webkit.org/show_bug.cgi?id=241452

Reviewed by Antti Koivisto.

* LayoutTests/fast/css/matrix-translate-calc-units.html: Added.
* Source/WebCore/css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::convertingToLengthRequiresNonNullStyle const):
(WebCore::CSSPrimitiveValue::convertToLength const):
* Source/WebCore/css/TransformFunctions.cpp:
* Source/WebCore/css/calc/CSSCalcExpressionNode.h:
* Source/WebCore/css/calc/CSSCalcInvertNode.h:
* Source/WebCore/css/calc/CSSCalcNegateNode.h:
* Source/WebCore/css/calc/CSSCalcOperationNode.cpp:
(WebCore::CSSCalcOperationNode::convertingToLengthRequiresNonNullStyle const):
* Source/WebCore/css/calc/CSSCalcOperationNode.h:
* Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp:
(WebCore::CSSCalcPrimitiveValueNode::convertingToLengthRequiresNonNullStyle const):
* Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.h:
* Source/WebCore/css/calc/CSSCalcValue.cpp:
(WebCore::CSSCalcValue::convertingToLengthRequiresNonNullStyle const):
* Source/WebCore/css/calc/CSSCalcValue.h:

Canonical link: https://commits.webkit.org/251431@main

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/fast/css/matrix-translate-calc-units-expected.txt (0 => 295425)


--- trunk/LayoutTests/fast/css/matrix-translate-calc-units-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/matrix-translate-calc-units-expected.txt	2022-06-09 18:21:03 UTC (rev 295425)
@@ -0,0 +1,15 @@
+Verify invalid DOMMatrix strings throw, and more importantly don't crash
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new DOMMatrix('translate(min(0em))') threw exception SyntaxError: The string did not match the expected pattern..
+PASS new DOMMatrix('translateX(max(0ex))') threw exception SyntaxError: The string did not match the expected pattern..
+PASS new DOMMatrix('translateY(calc(0ch))') threw exception SyntaxError: The string did not match the expected pattern..
+PASS new DOMMatrix('translateZ(calc(11ic))') threw exception SyntaxError: The string did not match the expected pattern..
+PASS new DOMMatrix('translateZ(calc(123lh))') threw exception SyntaxError: The string did not match the expected pattern..
+PASS new DOMMatrix('translate(max(123px))') did not throw exception.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/matrix-translate-calc-units.html (0 => 295425)


--- trunk/LayoutTests/fast/css/matrix-translate-calc-units.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/matrix-translate-calc-units.html	2022-06-09 18:21:03 UTC (rev 295425)
@@ -0,0 +1,11 @@
+<script src=""
+<script>
+  description("Verify invalid DOMMatrix strings throw, and more importantly don't crash");
+  shouldThrow("new DOMMatrix('translate(min(0em))')");
+  shouldThrow("new DOMMatrix('translateX(max(0ex))')");
+  shouldThrow("new DOMMatrix('translateY(calc(0ch))')");
+  shouldThrow("new DOMMatrix('translateZ(calc(11ic))')");
+  shouldThrow("new DOMMatrix('translateZ(calc(123lh))')");
+  shouldNotThrow("new DOMMatrix('translate(max(123px))')");
+</script>
+<script src=""

Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (295424 => 295425)


--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -4262,8 +4262,11 @@
 
 inline bool CSSPrimitiveValue::convertingToLengthRequiresNonNullStyle(int lengthConversion) const
 {
-    ASSERT(isFontRelativeLength());
     // This matches the implementation in CSSPrimitiveValue::computeLengthDouble().
+    //
+    // FIXME: We should probably make CSSPrimitiveValue::computeLengthDouble and
+    // CSSPrimitiveValue::computeNonCalcLengthDouble (which has the style assertion)
+    // return std::optional<double> instead of having this check here.
     switch (primitiveUnitType()) {
     case CSSUnitType::CSS_EMS:
     case CSSUnitType::CSS_EXS:
@@ -4271,6 +4274,8 @@
     case CSSUnitType::CSS_IC:
     case CSSUnitType::CSS_LHS:
         return lengthConversion & (FixedIntegerConversion | FixedFloatConversion);
+    case CSSUnitType::CSS_CALC:
+        return m_value.calc->convertingToLengthRequiresNonNullStyle(lengthConversion);
     default:
         return false;
     }
@@ -4278,7 +4283,7 @@
 
 template<int supported> Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conversionData) const
 {
-    if (isFontRelativeLength() && convertingToLengthRequiresNonNullStyle(supported) && !conversionData.style())
+    if (convertingToLengthRequiresNonNullStyle(supported) && !conversionData.style())
         return Length(LengthType::Undefined);
     if ((supported & FixedIntegerConversion) && isLength())
         return computeLength<Length>(conversionData);

Modified: trunk/Source/WebCore/css/TransformFunctions.cpp (295424 => 295425)


--- trunk/Source/WebCore/css/TransformFunctions.cpp	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/TransformFunctions.cpp	2022-06-09 18:21:03 UTC (rev 295425)
@@ -102,6 +102,7 @@
     return primitiveValue ? primitiveValue->convertToLength<FixedFloatConversion | PercentConversion | CalculatedConversion>(conversionData) : Length(LengthType::Undefined);
 }
 
+// FIXME: This should return std::optional<TransformOperations>
 bool transformsForValue(const CSSValue& value, const CSSToLengthConversionData& conversionData, TransformOperations& outOperations)
 {
     ASSERT(!outOperations.size());

Modified: trunk/Source/WebCore/css/calc/CSSCalcExpressionNode.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcExpressionNode.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcExpressionNode.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -59,7 +59,9 @@
 
     virtual void collectDirectComputationalDependencies(HashSet<CSSPropertyID>&) const = 0;
     virtual void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>&) const = 0;
+    virtual bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const = 0;
 
+
     CalculationCategory category() const { return m_category; }
 
     virtual void dump(TextStream&) const = 0;

Modified: trunk/Source/WebCore/css/calc/CSSCalcInvertNode.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcInvertNode.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcInvertNode.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -58,6 +58,7 @@
 
     void collectDirectComputationalDependencies(HashSet<CSSPropertyID>& properties) const final { m_child->collectDirectComputationalDependencies(properties); }
     void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>& properties) const final { m_child->collectDirectRootComputationalDependencies(properties); }
+    bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const final { return m_child->convertingToLengthRequiresNonNullStyle(lengthConversion); }
 
     void dump(TextStream&) const final;
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcNegateNode.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcNegateNode.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcNegateNode.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -58,6 +58,7 @@
 
     void collectDirectComputationalDependencies(HashSet<CSSPropertyID>& properties) const final { m_child->collectDirectComputationalDependencies(properties); }
     void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>& properties) const final { m_child->collectDirectRootComputationalDependencies(properties); }
+    bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const final { return m_child->convertingToLengthRequiresNonNullStyle(lengthConversion); }
 
     void dump(TextStream&) const final;
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcOperationNode.cpp	2022-06-09 18:21:03 UTC (rev 295425)
@@ -35,6 +35,7 @@
 #include "CSSUnits.h"
 #include "CalcExpressionOperation.h"
 #include "Logging.h"
+#include <wtf/Algorithms.h>
 #include <wtf/text/TextStream.h>
 
 namespace WebCore {
@@ -1074,6 +1075,13 @@
         child->collectDirectRootComputationalDependencies(values);
 }
 
+bool CSSCalcOperationNode::convertingToLengthRequiresNonNullStyle(int lengthConversion) const
+{
+    return WTF::anyOf(m_children, [lengthConversion] (auto& child) {
+        return child->convertingToLengthRequiresNonNullStyle(lengthConversion);
+    });
+}
+
 void CSSCalcOperationNode::buildCSSText(const CSSCalcExpressionNode& node, StringBuilder& builder)
 {
     auto shouldOutputEnclosingCalc = [](const CSSCalcExpressionNode& rootNode) {

Modified: trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcOperationNode.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -117,6 +117,7 @@
 
     void collectDirectComputationalDependencies(HashSet<CSSPropertyID>&) const final;
     void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>&) const final;
+    bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const final;
 
     void dump(TextStream&) const final;
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.cpp	2022-06-09 18:21:03 UTC (rev 295425)
@@ -211,6 +211,11 @@
     m_value->collectDirectRootComputationalDependencies(values);
 }
 
+bool CSSCalcPrimitiveValueNode::convertingToLengthRequiresNonNullStyle(int lengthConversion) const
+{
+    return m_value->convertingToLengthRequiresNonNullStyle(lengthConversion);
+}
+
 bool CSSCalcPrimitiveValueNode::isZero() const
 {
     return !m_value->doubleValue();

Modified: trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcPrimitiveValueNode.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -74,6 +74,7 @@
     double computeLengthPx(const CSSToLengthConversionData&) const final;
     void collectDirectComputationalDependencies(HashSet<CSSPropertyID>&) const final;
     void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>&) const final;
+    bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const final;
 
     void dump(TextStream&) const final;
 

Modified: trunk/Source/WebCore/css/calc/CSSCalcValue.cpp (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcValue.cpp	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcValue.cpp	2022-06-09 18:21:03 UTC (rev 295425)
@@ -340,6 +340,11 @@
     return clampToPermittedRange(m_expression->computeLengthPx(conversionData));
 }
 
+bool CSSCalcValue::convertingToLengthRequiresNonNullStyle(int lengthConversion) const
+{
+    return m_expression->convertingToLengthRequiresNonNullStyle(lengthConversion);
+}
+
 bool CSSCalcValue::isCalcFunction(CSSValueID functionId)
 {
     switch (functionId) {

Modified: trunk/Source/WebCore/css/calc/CSSCalcValue.h (295424 => 295425)


--- trunk/Source/WebCore/css/calc/CSSCalcValue.h	2022-06-09 17:50:11 UTC (rev 295424)
+++ trunk/Source/WebCore/css/calc/CSSCalcValue.h	2022-06-09 18:21:03 UTC (rev 295425)
@@ -73,6 +73,8 @@
 
     void dump(TextStream&) const;
 
+    bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const;
+
 private:
     CSSCalcValue(Ref<CSSCalcExpressionNode>&&, bool shouldClampToNonNegative);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to