LibWeb: Ignore window-forwarded document.body.onfoo in detached DOM

Normally, assigning to e.g document.body.onload will forward to
window.onload. However, in a detached DOM tree, there is no associated
window, so we have nowhere to forward to, making this a no-op.

The bulk of this change is making Document::window() return a nullable
pointer, as documents created by DOMParser or DOMImplementation do not
have an associated window object, and so must be able to return null
from here.
This commit is contained in:
Andreas Kling 2024-03-10 08:41:18 +01:00
parent 7139d5945f
commit b98a2be96b
Notes: sideshowbarker 2024-07-19 01:59:31 +09:00
28 changed files with 92 additions and 61 deletions

View file

@ -941,7 +941,7 @@ static void update_the_source_set(DOM::Element& element)
if (child->has_attribute(HTML::AttributeNames::media)) {
auto media_query = parse_media_query(CSS::Parser::ParsingContext { element.document() },
child->get_attribute_value(HTML::AttributeNames::media));
if (!media_query || !media_query->evaluate(element.document().window())) {
if (!media_query || !element.document().window() || !media_query->evaluate(*element.document().window())) {
continue;
}
}