LibWeb: Return a representation of an 'Agent' in 'relevant agent'

This makes it more convenient to use the 'relvant agent' concept,
instead of the awkward dynamic casts we needed to do for every call
site.

mutation_observers is also changed to hold a GC::Root instead of raw
GC::Ptr. Somehow this was not causing problems before, but trips up CI
after these changes.
This commit is contained in:
Shannon Booth 2025-01-04 23:12:55 +13:00 committed by Tim Flynn
parent 5bed8f4055
commit 64eeda6450
Notes: github-actions[bot] 2025-01-11 15:40:39 +00:00
15 changed files with 140 additions and 98 deletions

View file

@ -14,6 +14,7 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Scripting/Agent.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/TraversableNavigable.h>
@ -67,7 +68,7 @@ void EventLoop::schedule()
EventLoop& main_thread_event_loop()
{
return *static_cast<Bindings::WebEngineCustomData*>(Bindings::main_thread_vm().custom_data())->event_loop;
return *static_cast<Bindings::WebEngineCustomData*>(Bindings::main_thread_vm().custom_data())->agent.event_loop;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop
@ -460,8 +461,7 @@ TaskID queue_a_task(HTML::Task::Source source, GC::Ptr<EventLoop> event_loop, GC
TaskID queue_global_task(HTML::Task::Source source, JS::Object& global_object, GC::Ref<GC::Function<void()>> steps)
{
// 1. Let event loop be global's relevant agent's event loop.
auto& global_custom_data = verify_cast<Bindings::WebEngineCustomData>(*global_object.vm().custom_data());
auto& event_loop = global_custom_data.event_loop;
auto& event_loop = relevant_agent(global_object).event_loop;
// 2. Let document be global's associated Document, if global is a Window object; otherwise null.
DOM::Document* document { nullptr };