Skip to content

Truly independent web browser

LibWeb: Wrap non-integer Typed OM numbers for <integer> in CSSMathSum

Andreas Klingc14554969850
diff --git a/Libraries/LibWeb/CSS/CSSUnitValue.cpp b/Libraries/LibWeb/CSS/CSSUnitValue.cpp
index aeff7eec692..dbb6e6539c7 100644
--- a/Libraries/LibWeb/CSS/CSSUnitValue.cpp
+++ b/Libraries/LibWeb/CSS/CSSUnitValue.cpp
@@ -397,6 +397,10 @@ WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSUnitValue::create_an_int
if (property_accepts_type(property.id(), ValueType::Integer)) {
auto integer = round_to_nearest_integer(number.value());
+ // NB: A number that is not an integer does not match <integer>, so it's wrapped in a CSSMathSum, like
+ // a value outside of the accepted range. It then gets rounded when computed.
+ if (static_cast<double>(integer) != number.value())
+ return wrap_in_math_sum(number);
if (property_accepts_integer(property.id(), integer))
return IntegerStyleValue::create(integer);
return wrap_in_math_sum(number);
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/column-count.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/column-count.txt
index e8e94c1f13b..01953952c2c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/column-count.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/column-count.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 32 tests
-30 Pass
-2 Fail
+31 Pass
+1 Fail
Pass Can set 'column-count' to CSS-wide keywords: initial
Pass Can set 'column-count' to CSS-wide keywords: inherit
Pass Can set 'column-count' to CSS-wide keywords: unset
@@ -12,7 +12,7 @@ Pass Can set 'column-count' to var() references: var(--A)
Pass Can set 'column-count' to the 'auto' keyword: auto
Pass Can set 'column-count' to a number: 0
Pass Can set 'column-count' to a number: -3.14
-Fail Can set 'column-count' to a number: 3.14
+Pass Can set 'column-count' to a number: 3.14
Fail Can set 'column-count' to a number: calc(2 + 3)
Pass Setting 'column-count' to a length: 0px throws TypeError
Pass Setting 'column-count' to a length: -3.14em throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/order.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/order.txt
index 9416817398d..55d50ef4a5a 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/order.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/order.txt
@@ -2,16 +2,16 @@ Harness status: OK
Found 31 tests
-28 Pass
-3 Fail
+30 Pass
+1 Fail
Pass Can set 'order' to CSS-wide keywords: initial
Pass Can set 'order' to CSS-wide keywords: inherit
Pass Can set 'order' to CSS-wide keywords: unset
Pass Can set 'order' to CSS-wide keywords: revert
Pass Can set 'order' to var() references: var(--A)
Pass Can set 'order' to a number: 0
-Fail Can set 'order' to a number: -3.14
-Fail Can set 'order' to a number: 3.14
+Pass Can set 'order' to a number: -3.14
+Pass Can set 'order' to a number: 3.14
Fail Can set 'order' to a number: calc(2 + 3)
Pass Setting 'order' to a length: 0px throws TypeError
Pass Setting 'order' to a length: -3.14em throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/orphans.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/orphans.txt
index 131c25c513a..643b80a299e 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/orphans.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/orphans.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 31 tests
-29 Pass
-2 Fail
+30 Pass
+1 Fail
Pass Can set 'orphans' to CSS-wide keywords: initial
Pass Can set 'orphans' to CSS-wide keywords: inherit
Pass Can set 'orphans' to CSS-wide keywords: unset
@@ -11,7 +11,7 @@ Pass Can set 'orphans' to CSS-wide keywords: revert
Pass Can set 'orphans' to var() references: var(--A)
Pass Can set 'orphans' to a number: 0
Pass Can set 'orphans' to a number: -3.14
-Fail Can set 'orphans' to a number: 3.14
+Pass Can set 'orphans' to a number: 3.14
Fail Can set 'orphans' to a number: calc(2 + 3)
Pass Setting 'orphans' to a length: 0px throws TypeError
Pass Setting 'orphans' to a length: -3.14em throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/widows.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/widows.txt
index 11aa4f62635..48d9d09629c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/widows.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/widows.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 31 tests
-29 Pass
-2 Fail
+30 Pass
+1 Fail
Pass Can set 'widows' to CSS-wide keywords: initial
Pass Can set 'widows' to CSS-wide keywords: inherit
Pass Can set 'widows' to CSS-wide keywords: unset
@@ -11,7 +11,7 @@ Pass Can set 'widows' to CSS-wide keywords: revert
Pass Can set 'widows' to var() references: var(--A)
Pass Can set 'widows' to a number: 0
Pass Can set 'widows' to a number: -3.14
-Fail Can set 'widows' to a number: 3.14
+Pass Can set 'widows' to a number: 3.14
Fail Can set 'widows' to a number: calc(2 + 3)
Pass Setting 'widows' to a length: 0px throws TypeError
Pass Setting 'widows' to a length: -3.14em throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/z-index.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/z-index.txt
index 8158e6bbf35..79cb86a18eb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/z-index.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/z-index.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 32 tests
-29 Pass
-3 Fail
+31 Pass
+1 Fail
Pass Can set 'z-index' to CSS-wide keywords: initial
Pass Can set 'z-index' to CSS-wide keywords: inherit
Pass Can set 'z-index' to CSS-wide keywords: unset
@@ -11,8 +11,8 @@ Pass Can set 'z-index' to CSS-wide keywords: revert
Pass Can set 'z-index' to var() references: var(--A)
Pass Can set 'z-index' to the 'auto' keyword: auto
Pass Can set 'z-index' to a number: 0
-Fail Can set 'z-index' to a number: -3.14
-Fail Can set 'z-index' to a number: 3.14
+Pass Can set 'z-index' to a number: -3.14
+Pass Can set 'z-index' to a number: 3.14
Fail Can set 'z-index' to a number: calc(2 + 3)
Pass Setting 'z-index' to a length: 0px throws TypeError
Pass Setting 'z-index' to a length: -3.14em throws TypeError