LibWeb: Avoid crash evaluating media query in document lacking window

In some cases a document may lack an associated window - to fix this for
now we just return false but perhaps there are some media queries we
should still attempt to resolve.
This commit is contained in:
Callum Law 2025-10-12 12:41:44 +13:00 committed by Andreas Kling
commit b1801c0bc9
Notes: github-actions[bot] 2025-10-17 16:27:27 +00:00
2 changed files with 12 additions and 1 deletions

View file

@ -99,7 +99,12 @@ String MediaFeature::to_string() const
MatchResult MediaFeature::evaluate(DOM::Document const* document) const
{
VERIFY(document);
VERIFY(document->window());
// FIXME: In some cases (e.g. when parsing HTML using DOMParser::parse_from_string()) a document may not be associated with a window -
// for now we just return false but perhaps there are some media queries we should still attempt to resolve.
if (!document->window())
return MatchResult::False;
auto maybe_queried_value = document->window()->query_media_feature(m_id);
if (!maybe_queried_value.has_value())
return MatchResult::False;