From d2217be803b16e28ff2a1573653fed87e79cc3a7 Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Tue, 28 Mar 2023 07:24:46 +0000 Subject: [PATCH] style: CSS comp funcs should handle NaN contagiously If NaN is given as any input to CSS comp funcs (min/max/clamp), it should return NaN. Does not cover simplification (see Bug 1820412). Adjusted WPT test expectations, 18 newly pass. :tada: Differential Revision: https://phabricator.services.mozilla.com/D171659 --- components/style/values/generics/calc.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/style/values/generics/calc.rs b/components/style/values/generics/calc.rs index 213595b9140..d530fda6c7e 100644 --- a/components/style/values/generics/calc.rs +++ b/components/style/values/generics/calc.rs @@ -449,8 +449,19 @@ impl CalcNode { }, Self::MinMax(ref nodes, op) => { let mut result = nodes[0].resolve_internal(leaf_to_output_fn)?; + + if result.is_nan() { + return Ok(result); + } + for node in nodes.iter().skip(1) { let candidate = node.resolve_internal(leaf_to_output_fn)?; + + if candidate.is_nan() { + result = candidate; + break; + } + let candidate_wins = match op { MinMaxOp::Min => candidate < result, MinMaxOp::Max => candidate > result, @@ -477,6 +488,11 @@ impl CalcNode { if result < min { result = min } + + if min.is_nan() || center.is_nan() || max.is_nan() { + result = ::nan(); + } + result }, Self::Round {