mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Coerce NaNs to 0 when escaping top-level calculations
This commit is contained in:
parent
545d151948
commit
6a3c3ee291
Notes:
github-actions[bot]
2025-03-25 19:54:37 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/6a3c3ee2911 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4088 Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 12 additions and 3 deletions
|
@ -2716,9 +2716,16 @@ Optional<Time> CalculatedStyleValue::resolve_time(CalculationResolutionContext c
|
|||
Optional<double> CalculatedStyleValue::resolve_number(CalculationResolutionContext const& context) const
|
||||
{
|
||||
auto result = m_calculation->resolve(context);
|
||||
if (result.type().has_value() && result.type()->matches_number(m_context.percentages_resolve_as))
|
||||
return result.value();
|
||||
return {};
|
||||
if (!result.type().has_value() || !result.type()->matches_number(m_context.percentages_resolve_as))
|
||||
return {};
|
||||
|
||||
// https://drafts.csswg.org/css-values/#calc-ieee
|
||||
// NaN does not escape a top-level calculation; it’s censored into a zero value.
|
||||
auto value = result.value();
|
||||
if (isnan(value))
|
||||
return 0.;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Optional<i64> CalculatedStyleValue::resolve_integer(CalculationResolutionContext const& context) const
|
||||
|
|
|
@ -12,6 +12,7 @@ scale(1, 2) => matrix(1, 0, 0, 2, 0, 0)
|
|||
scale(100%, 200%) => matrix(1, 0, 0, 2, 0, 0)
|
||||
scale(calc(1 / 2)) => matrix(0.5, 0, 0, 0.5, 0, 0)
|
||||
scale(calc(50% + 25%)) => matrix(0.75, 0, 0, 0.75, 0, 0)
|
||||
scale(calc(NaN)) => matrix(0, 0, 0, 0, 0, 0)
|
||||
scaleX(2) => matrix(2, 0, 0, 1, 0, 0)
|
||||
scaleX(200%) => matrix(2, 0, 0, 1, 0, 0)
|
||||
scaleY(2.5) => matrix(1, 0, 0, 2.5, 0, 0)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
"scale(100%, 200%)",
|
||||
"scale(calc(1 / 2))",
|
||||
"scale(calc(50% + 25%))",
|
||||
"scale(calc(NaN))",
|
||||
"scaleX(2)",
|
||||
"scaleX(200%)",
|
||||
"scaleY(2.5)",
|
||||
|
|
Loading…
Add table
Reference in a new issue