LibWeb: Handle non-numeric font-weight values in keyframes

Previously, using `font-weight` with a keyword or `calc()` value inside
a keyframe rule would cause a crash.
This commit is contained in:
Tim Ledbetter 2025-06-25 05:55:10 +01:00 committed by Jelle Raaijmakers
parent e69d9fb331
commit 48f56cad08
Notes: github-actions[bot] 2025-06-25 07:03:08 +00:00
3 changed files with 42 additions and 1 deletions

View file

@ -386,7 +386,7 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
// That's why it has to be set before everything else.
computed_values.set_font_list(computed_style.computed_font_list());
computed_values.set_font_size(computed_style.font_size());
computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight).as_number().number()));
computed_values.set_font_weight(computed_style.property(CSS::PropertyID::FontWeight).to_font_weight());
computed_values.set_font_kerning(computed_style.font_kerning());
computed_values.set_line_height(computed_style.line_height());

View file

@ -0,0 +1,7 @@
Harness status: OK
Found 2 tests
2 Fail
Fail Initially, the sibling-index() is 3 for #target
Fail Removing a preceding sibling of #target reduces the sibling-index()

View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<title>CSS Values and Units Test: sibling-index() changing font-weight during @keyframes animation</title>
<link rel="help" href="https://drafts.csswg.org/css-values-5/#tree-counting">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
@keyframes --anim {
from {
font-weight: calc(100 * sibling-index());
}
to {
font-weight: 600;
}
}
#target {
animation: --anim 1000s step-end;
}
</style>
<div>
<div id="rm"></div>
<div></div>
<div id="target"></div>
</div>
<script>
test(() => {
assert_equals(getComputedStyle(target).fontWeight, "300");
}, "Initially, the sibling-index() is 3 for #target");
test(() => {
rm.remove();
assert_equals(getComputedStyle(target).fontWeight, "200");
}, "Removing a preceding sibling of #target reduces the sibling-index()");
</script>