Skip to content

Commit

Permalink
LibWeb: Don't crash when resolving grid properties of inline elements
Browse files Browse the repository at this point in the history
Previously, attempting to get the computed value for a
grid-template-rows or grid-template-columns property would cause a
crash for inline elements.
  • Loading branch information
tcl3 authored and awesomekling committed Sep 20, 2024
1 parent f65df3f commit 087fcb8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
21 changes: 21 additions & 0 deletions Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable-box.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const elementsToTest = [
"br",
"span",
];
for (const elementName of elementsToTest) {
const element = document.createElement(elementName);
document.body.appendChild(element);
const style = getComputedStyle(element);
let values = [];
for (const propertyName of style) {
values.push(style[propertyName]);
}
element.remove();
}
println("PASS (didn't crash)");
});
</script>
15 changes: 0 additions & 15 deletions Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable.html

This file was deleted.

4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,14 @@ RefPtr<CSSStyleValue const> ResolvedCSSStyleDeclaration::style_value_for_propert
// For grid-template-columns and grid-template-rows the resolved value is the used value.
// https://www.w3.org/TR/css-grid-2/#resolved-track-list-standalone
if (property_id == PropertyID::GridTemplateColumns) {
if (layout_node.paintable()) {
if (layout_node.paintable() && layout_node.paintable()->is_paintable_box()) {
auto const& paintable_box = verify_cast<Painting::PaintableBox const>(*layout_node.paintable());
if (auto used_values_for_grid_template_columns = paintable_box.used_values_for_grid_template_columns()) {
return used_values_for_grid_template_columns;
}
}
} else if (property_id == PropertyID::GridTemplateRows) {
if (layout_node.paintable()) {
if (layout_node.paintable() && layout_node.paintable()->is_paintable_box()) {
auto const& paintable_box = verify_cast<Painting::PaintableBox const>(*layout_node.paintable());
if (auto used_values_for_grid_template_rows = paintable_box.used_values_for_grid_template_rows()) {
return used_values_for_grid_template_rows;
Expand Down

0 comments on commit 087fcb8

Please sign in to comment.