LibWeb: Don't assume calc() simplification worked on invalid tree

Fixes #4469
This commit is contained in:
Andreas Kling 2025-04-25 15:00:02 +02:00 committed by Jelle Raaijmakers
commit d8ea16d94e
Notes: github-actions[bot] 2025-04-25 14:56:08 +00:00
3 changed files with 123 additions and 2 deletions

View file

@ -2926,8 +2926,9 @@ NonnullRefPtr<CalculationNode const> simplify_a_calculation_tree(CalculationNode
// running roots operation using its children, expressed in the results canonical unit.
if (root->is_math_function_node()) {
if (auto maybe_simplified = root->run_operation_if_possible(context, resolution_context); maybe_simplified.has_value()) {
// NOTE: If this returns nullptr, that's a logic error in the code, so it's fine to assert that it's nonnull.
return make_calculation_node(maybe_simplified.release_value(), context).release_nonnull();
if (auto node = make_calculation_node(maybe_simplified.release_value(), context))
return node.release_nonnull();
return root;
}
}