1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:58:12 +00:00

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
28 changed files with 92 additions and 61 deletions

View file

@ -638,7 +638,7 @@ WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> Document::open(StringView url,
return WebIDL::InvalidAccessError::create(realm(), "Cannot perform open on a document that isn't fully active."_fly_string);
// 2. Return the result of running the window open steps with url, name, and features.
return window().open_impl(url, name, features);
return window()->open_impl(url, name, features);
}
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#closing-the-input-stream
@ -2273,7 +2273,7 @@ JS::GCPtr<HTML::Location> Document::location()
if (!is_fully_active())
return nullptr;
return window().location();
return window()->location();
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
@ -2330,7 +2330,7 @@ void Document::run_the_resize_steps()
return;
m_last_viewport_size = viewport_size;
window().dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize));
window()->dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize));
schedule_layout_update();
}
@ -2401,9 +2401,13 @@ void Document::evaluate_media_queries_and_report_changes()
void Document::evaluate_media_rules()
{
auto window = this->window();
if (!window)
return;
bool any_media_queries_changed_match_state = false;
for (auto& style_sheet : style_sheets().sheets()) {
if (style_sheet->evaluate_media_queries(window()))
if (style_sheet->evaluate_media_queries(*window))
any_media_queries_changed_match_state = true;
}
@ -3305,6 +3309,10 @@ void Document::unregister_resize_observer(Badge<ResizeObserver::ResizeObserver>,
// https://www.w3.org/TR/intersection-observer/#queue-an-intersection-observer-task
void Document::queue_intersection_observer_task()
{
auto window = this->window();
if (!window)
return;
// 1. If documents IntersectionObserverTaskQueued flag is set to true, return.
if (m_intersection_observer_task_queued)
return;
@ -3313,7 +3321,7 @@ void Document::queue_intersection_observer_task()
m_intersection_observer_task_queued = true;
// 3. Queue a task on the IntersectionObserver task source associated with the document's event loop to notify intersection observers.
HTML::queue_global_task(HTML::Task::Source::IntersectionObserver, window(), [this]() {
HTML::queue_global_task(HTML::Task::Source::IntersectionObserver, *window, [this]() {
auto& realm = this->realm();
// https://www.w3.org/TR/intersection-observer/#notify-intersection-observers
@ -4039,7 +4047,7 @@ void Document::ensure_animation_timer()
return;
}
update_animations_and_send_events(window().performance()->now());
update_animations_and_send_events(window()->performance()->now());
for (auto& timeline : m_associated_animation_timelines) {
for (auto& animation : timeline->associated_animations())