LibWeb: Avoid dereferencing a null pointer to document

This commit is contained in:
Pratyush Nair 2025-09-05 10:22:47 +05:30 committed by Sam Atkins
commit 01be928a16
Notes: github-actions[bot] 2025-09-10 15:58:41 +00:00
3 changed files with 24 additions and 1 deletions

View file

@ -754,7 +754,12 @@ GC::Ptr<CSSPropertyRule> Parser::convert_to_property_rule(AtRule const& rule)
return {}; return {};
} }
auto parsing_params = CSS::Parser::ParsingParams { *document() }; CSS::Parser::ParsingParams parsing_params;
if (document())
parsing_params = CSS::Parser::ParsingParams { *document() };
else
parsing_params = CSS::Parser::ParsingParams { realm() };
auto syntax_component_values = parse_component_values_list(parsing_params, syntax_maybe.value()); auto syntax_component_values = parse_component_values_list(parsing_params, syntax_maybe.value());
auto maybe_syntax = parse_as_syntax(syntax_component_values); auto maybe_syntax = parse_as_syntax(syntax_component_values);

View file

@ -0,0 +1 @@
PASS (Didn't crash)

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const sheet = new CSSStyleSheet();
const css = `
@property --test {
syntax: '<color>';
inherits: false;
initial-value: black;
}
`;
sheet.replaceSync(css);
document.adoptedStyleSheets = [sheet];
println("PASS (Didn't crash)");
});
</script>