LibWeb: Check for missing node or invalid query in obtain_theme_color

This commit is contained in:
Gingeh 2025-01-10 13:19:34 +11:00 committed by Tim Ledbetter
parent 6fd03425b2
commit 9f2ce259ad
Notes: github-actions[bot] 2025-01-12 19:48:07 +00:00
3 changed files with 11 additions and 2 deletions

View file

@ -1501,7 +1501,7 @@ void Document::obtain_theme_color()
auto media = element.attribute(HTML::AttributeNames::media);
if (media.has_value()) {
auto query = parse_media_query(context, media.value());
if (window() && !query->evaluate(*window()))
if (query.is_null() || !window() || !query->evaluate(*window()))
return TraversalDecision::Continue;
}
@ -1514,7 +1514,7 @@ void Document::obtain_theme_color()
// 4. If color is not failure, then return color.
if (!css_value.is_null() && css_value->is_color()) {
Optional<Layout::NodeWithStyle const&> root_node;
if (html_element())
if (html_element() && html_element()->layout_node())
root_node = *html_element()->layout_node();
theme_color = css_value->to_color(root_node);

View file

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

View file

@ -0,0 +1,8 @@
<!DOCTYPE html>
<meta name="theme-color" content="red">
<script src="include.js"></script>
<script>
test(() => {
println("PASS (didn't crash)");
});
</script>