Skip to content

Truly independent web browser

LibWeb: Look up the agent and event loop of the current thread

Andreas Kling3d7c88b8d26c
diff --git a/Libraries/LibWeb/Bindings/Rust/src/indexed_db/cpp.rs b/Libraries/LibWeb/Bindings/Rust/src/indexed_db/cpp.rs
index 3ab8cace0b3..15ce7dd5a5b 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/indexed_db/cpp.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/indexed_db/cpp.rs
@@ -27,7 +27,7 @@ unsafe extern "C" {
fn web_indexed_db_create_dom_string_list(realm: *mut c_void, strings: *const usize, count: usize) -> *mut c_void;
fn web_indexed_db_queue_a_database_task(cell: *mut c_void, steps: unsafe extern "C" fn(*mut c_void, *mut c_void));
fn web_indexed_db_run_in_parallel(cell: *mut c_void, steps: unsafe extern "C" fn(*mut c_void, *mut c_void));
- fn web_indexed_db_main_thread_event_loop() -> *mut c_void;
+ fn web_indexed_db_current_event_loop() -> *mut c_void;
fn web_indexed_db_enqueue_check_pending_connection_wait(database: *mut c_void);
fn web_indexed_db_devtools_client_is_active(realm: *mut c_void) -> bool;
fn web_indexed_db_create_transaction_changes() -> *mut c_void;
@@ -130,9 +130,9 @@ pub(crate) fn run_in_parallel(_: &Vm, steps: Function) {
}
/// https://html.spec.whatwg.org/multipage/webappapis.html#main-thread-event-loop
-pub(crate) fn main_thread_event_loop() -> CppCell {
+pub(crate) fn current_event_loop() -> CppCell {
// SAFETY: LibWeb returns the live event loop.
- unsafe { CppCell::from_raw(web_indexed_db_main_thread_event_loop()) }
+ unsafe { CppCell::from_raw(web_indexed_db_current_event_loop()) }
}
/// Checks the database's pending connection wait after the collection that runs a finalizer, if the database is still
diff --git a/Libraries/LibWeb/Bindings/Rust/src/indexed_db/idb_database.rs b/Libraries/LibWeb/Bindings/Rust/src/indexed_db/idb_database.rs
index e0626353b20..c7561f156e2 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/indexed_db/idb_database.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/indexed_db/idb_database.rs
@@ -18,7 +18,7 @@ use crate::bindings::conversions::{CppInterface, DOMStringOrDOMStringSequence};
use crate::bindings::event_target::{CppEventTarget, GetTheParent};
use crate::bindings::interface::{Ref, Wrappable, allocate};
use crate::bindings::{CallContext, Exception, WebIdlResult};
-use crate::indexed_db::cpp::{enqueue_post_gc_task, main_thread_event_loop};
+use crate::indexed_db::cpp::{current_event_loop, enqueue_post_gc_task};
use crate::indexed_db::idb_object_store::{
IDBObjectStore, constraint_error, invalid_state_error, not_found_error, transaction_inactive_error,
};
@@ -429,7 +429,7 @@ impl IDBDatabase {
let transaction = IDBTransaction::create(vm, *this, mode, options.durability, &scope_stores.values());
// 8. Set transaction’s cleanup event loop to the current event loop.
- transaction.set_cleanup_event_loop(vm, Some(main_thread_event_loop()));
+ transaction.set_cleanup_event_loop(vm, Some(current_event_loop()));
Self::block_on_conflicting_transactions(*this, vm, transaction);
diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp
index 6ea18182c73..0d9229aa6c6 100644
--- a/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -742,7 +742,7 @@ WebIDL::CallbackType* EventTarget::get_current_value_of_event_handler(Utf16FlySt
auto source_text = source_builder.to_string();
- auto& vm = Bindings::main_thread_vm();
+ auto& vm = JS::VM::the();
auto compiled_function = JS::CompiledDynamicFunction::compile(vm, source_text, parameters_string, body, JS::FunctionKind::Normal);
diff --git a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
index 31f40fc60a3..300800c4617 100644
--- a/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/BodyStreamPullSource.cpp
@@ -218,7 +218,7 @@ void BodyStreamPullSource::on_pull_wake()
// AD-HOC: While the HTML event loop is paused, the pull runs now rather than in a fetch task, which would not run
// until the loop resumes.
- if (HTML::main_thread_event_loop().execution_paused()) {
+ if (HTML::current_event_loop().execution_paused()) {
run_pull_task();
push_while_paused();
return;
@@ -236,7 +236,7 @@ void BodyStreamPullSource::on_pull_wake()
// AD-HOC: The tasks of a navigation body adopted from another process are queued without a document, since the
// previous document's tasks stop running once the new document replaces it.
- HTML::queue_a_task(HTML::Task::Source::Networking, HTML::main_thread_event_loop(), nullptr, steps);
+ HTML::queue_a_task(HTML::Task::Source::Networking, HTML::current_event_loop(), nullptr, steps);
}
// AD-HOC: A sync XHR send() pauses the HTML event loop while it waits for exactly these bytes, and a stream set up
@@ -245,7 +245,7 @@ void BodyStreamPullSource::on_pull_wake()
// would deliver them (see the sync XHR body path in fetch_response_handover()).
void BodyStreamPullSource::push_while_paused()
{
- if (m_detached || m_pending_pull_promise || m_push_ticket.has_value() || !HTML::main_thread_event_loop().execution_paused())
+ if (m_detached || m_pending_pull_promise || m_push_ticket.has_value() || !HTML::current_event_loop().execution_paused())
return;
if (!m_fetch_controller || m_fetch_controller->control_block().body_intent() != Engine::BodyIntent::SyncAccumulate)
return;
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
index 7f99526451c..fa8fb1737b8 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
@@ -222,7 +222,7 @@ void FetchController::stop_fetch()
// cancelling any queued fetch tasks and then ignoring any callbacks.
auto ongoing_fetch_tasks = move(m_ongoing_fetch_tasks);
- HTML::main_thread_event_loop().task_queue().remove_tasks_matching([&](auto const& task) {
+ HTML::current_event_loop().task_queue().remove_tasks_matching([&](auto const& task) {
return ongoing_fetch_tasks.remove_all_matching([&](u64, HTML::TaskID task_id) {
return task.id() == task_id;
});
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
index 212899fc3eb..177af52b7e7 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp
@@ -123,7 +123,7 @@ void Body::did_read_resource_header(Core::ImmutableBytes bytes, SniffOutcome out
auto callback = exchange(body->m_sniff_bytes_callback, nullptr);
callback->function()(*body->sniff_bytes_if_available());
});
- HTML::queue_a_task(HTML::Task::Source::Networking, HTML::main_thread_event_loop(), nullptr, steps);
+ HTML::queue_a_task(HTML::Task::Source::Networking, HTML::current_event_loop(), nullptr, steps);
}
// https://fetch.spec.whatwg.org/#concept-body-clone
diff --git a/Libraries/LibWeb/HTML/BroadcastChannel.cpp b/Libraries/LibWeb/HTML/BroadcastChannel.cpp
index 0b18b7634ca..7821a73a6e8 100644
--- a/Libraries/LibWeb/HTML/BroadcastChannel.cpp
+++ b/Libraries/LibWeb/HTML/BroadcastChannel.cpp
@@ -90,7 +90,7 @@ void deliver_broadcast_channel_message_locally(BroadcastChannelMessage message)
auto channel_name = Utf16String::from_utf16(message.channel_name.view());
URL::RustIntegration::lend_origin_to_ffi(message.storage_key.origin, [&](URL::FFI::FfiOrigin const& storage_key_origin) {
URL::RustIntegration::lend_origin_to_ffi(message.source_origin, [&](URL::FFI::FfiOrigin const& source_origin) {
- web_rust_broadcast_channel_deliver_message_locally(JS::HostABI::vm_to_abi(Bindings::main_thread_vm()), &storage_key_origin, move(channel_name).into_raw(), &source_origin, message.serialized_message.data.span(), shared_memory.data(), shared_memory_sizes.data(), shared_memory.size());
+ web_rust_broadcast_channel_deliver_message_locally(JS::HostABI::vm_to_abi(JS::VM::the()), &storage_key_origin, move(channel_name).into_raw(), &source_origin, message.serialized_message.data.span(), shared_memory.data(), shared_memory_sizes.data(), shared_memory.size());
});
});
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index d7bac0033ea..5464d8d0574 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -142,6 +142,11 @@ EventLoop& main_thread_event_loop()
return *static_cast<HTML::Agent*>(Bindings::main_thread_vm().agent())->event_loop;
}
+EventLoop& current_event_loop()
+{
+ return *surrounding_agent().event_loop;
+}
+
// https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop
void EventLoop::spin_until(GC::Ref<GC::Function<bool()>> goal_condition)
{
@@ -1749,7 +1754,7 @@ void EventLoop::release_held_frames_for_testing()
void run_when_event_loop_reaches_step_1(GC::Ref<GC::Function<void()>> steps)
{
- auto& event_loop = main_thread_event_loop();
+ auto& event_loop = current_event_loop();
event_loop.run_upon_reaching_step_1(steps);
}
@@ -1758,7 +1763,7 @@ TaskID queue_a_task(HTML::Task::Source source, GC::Ptr<EventLoop> event_loop, GC
{
// 1. If event loop was not given, set event loop to the implied event loop.
if (!event_loop)
- event_loop = main_thread_event_loop();
+ event_loop = current_event_loop();
// FIXME: 2. If document was not given, set document to the implied document.
@@ -1798,7 +1803,7 @@ TaskID queue_global_task(HTML::Task::Source source, JS::Object& global_object, G
void queue_a_microtask(GC::Ptr<DOM::Document const> document, GC::Ref<GC::Function<void()>> steps)
{
// 1. If event loop was not given, set event loop to the implied event loop.
- auto& event_loop = HTML::main_thread_event_loop();
+ auto& event_loop = HTML::current_event_loop();
// FIXME: 2. If document was not given, set document to the implied document.
@@ -1816,7 +1821,7 @@ void queue_a_microtask(GC::Ptr<DOM::Document const> document, GC::Ref<GC::Functi
void perform_a_microtask_checkpoint()
{
- main_thread_event_loop().perform_a_microtask_checkpoint();
+ current_event_loop().perform_a_microtask_checkpoint();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index 0c012f7f99a..602bde2b37a 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -354,7 +354,13 @@ private:
Function<void()> m_on_destroyed;
};
+// The event loop of the window agent, from that agent's thread only. Code that a worker can reach has to use
+// current_event_loop().
WEB_API EventLoop& main_thread_event_loop();
+
+// The event loop of the agent on the current thread.
+WEB_API EventLoop& current_event_loop();
+
WEB_API void run_when_event_loop_reaches_step_1(GC::Ref<GC::Function<void()>> steps);
WEB_API TaskID queue_a_task(HTML::Task::Source, GC::Ptr<EventLoop>, GC::Ptr<DOM::Document>, GC::Ref<GC::Function<void()>> steps, Task::Priority = Task::Priority::Normal, GC::Ptr<GC::Function<void()>> discard_steps = {});
WEB_API TaskID queue_global_task(HTML::Task::Source, JS::Object&, GC::Ref<GC::Function<void()>> steps, Task::Priority = Task::Priority::Normal, GC::Ptr<GC::Function<void()>> discard_steps = {});
diff --git a/Libraries/LibWeb/HTML/EventLoop/Task.cpp b/Libraries/LibWeb/HTML/EventLoop/Task.cpp
index 6cca32c7c8c..ce55c064c4c 100644
--- a/Libraries/LibWeb/HTML/EventLoop/Task.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/Task.cpp
@@ -102,7 +102,7 @@ NonnullRefPtr<ParallelQueue> ParallelQueue::create()
TaskID ParallelQueue::enqueue(GC::Ref<GC::Function<void()>> algorithm)
{
- auto& event_loop = HTML::main_thread_event_loop();
+ auto& event_loop = HTML::current_event_loop();
auto task = HTML::Task::create(m_task_source.source, nullptr, algorithm);
event_loop.task_queue().add(task);
return task->id();
diff --git a/Libraries/LibWeb/HTML/Scripting/Agent.cpp b/Libraries/LibWeb/HTML/Scripting/Agent.cpp
index 48a9e516b22..240e0137cf2 100644
--- a/Libraries/LibWeb/HTML/Scripting/Agent.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Agent.cpp
@@ -42,6 +42,11 @@ void Agent::detach_script_abort_handle()
m_script_abort_handle->detach();
}
+Agent& surrounding_agent()
+{
+ return *static_cast<Agent*>(JS::VM::the().agent());
+}
+
// https://html.spec.whatwg.org/multipage/webappapis.html#relevant-agent
Agent& relevant_agent(JS::Object const& object)
{
diff --git a/Libraries/LibWeb/HTML/Scripting/Agent.h b/Libraries/LibWeb/HTML/Scripting/Agent.h
index ca491e31acb..515d2099970 100644
--- a/Libraries/LibWeb/HTML/Scripting/Agent.h
+++ b/Libraries/LibWeb/HTML/Scripting/Agent.h
@@ -12,6 +12,7 @@
#include <LibJS/Runtime/Agent.h>
#include <LibWeb/Fetch/Infrastructure/FetchControllerRegistry.h>
#include <LibWeb/Forward.h>
+#include <LibWeb/HTML/EventLoop/Task.h>
#include <LibWeb/HTML/Scripting/ScriptAbortHandle.h>
namespace JS {
@@ -37,8 +38,13 @@ struct WEB_API Agent : public JS::Agent {
Fetch::Infrastructure::FetchControllerRegistry fetch_controller_registry;
+ // https://w3c.github.io/web-locks/#lock-task-queue
+ RefPtr<ParallelQueue> lock_task_queue;
+
virtual void spin_event_loop_until(GC::Root<GC::Function<bool()>> goal_condition) override;
+ virtual bool is_similar_origin_window_agent() const { return false; }
+
// Only the agent's thread may call this, the first time at least. The handle is for other threads.
NonnullRefPtr<ScriptAbortHandle> script_abort_handle();
void detach_script_abort_handle();
@@ -58,6 +64,9 @@ private:
RefPtr<ScriptAbortHandle> m_script_abort_handle;
};
+// The agent of the current thread, which has one if it runs any web code at all.
+WEB_API Agent& surrounding_agent();
+
Agent& relevant_agent(JS::Object const&);
Agent& relevant_agent(DOM::Node const&);
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index 1461cace6fb..8859b5fce6e 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -228,7 +228,7 @@ void clean_up_after_running_script(EnvironmentSettingsObject const& settings)
// 3. If the JavaScript execution context stack is now empty, perform a microtask checkpoint. (If this runs scripts, these algorithms will be invoked reentrantly.)
if (!vm.has_running_execution_context())
- main_thread_event_loop().perform_a_microtask_checkpoint();
+ current_event_loop().perform_a_microtask_checkpoint();
}
static JS::ExecutionContext* top_most_script_having_execution_context(JS::VM& vm)
@@ -252,8 +252,8 @@ void prepare_to_run_callback(EnvironmentSettingsObject& settings)
// 1. Push settings onto the backup incumbent settings object stack.
// NOTE: The spec doesn't say which event loop's stack to put this on. However, all the examples of the incumbent settings object use iframes and cross browsing context communication to demonstrate the concept.
- // This means that it must rely on some global state that can be accessed by all browsing contexts, which is the main thread event loop.
- HTML::main_thread_event_loop().push_onto_backup_incumbent_realm_stack(settings);
+ // This means that it must rely on some global state that can be accessed by all browsing contexts, which is the event loop of their agent.
+ HTML::current_event_loop().push_onto_backup_incumbent_realm_stack(settings);
// 2. Let context be the topmost script-having execution context.
auto* context = top_most_script_having_execution_context(vm);
@@ -322,7 +322,7 @@ void clean_up_after_running_callback(EnvironmentSettingsObject const& settings)
}
// 3. Assert: the topmost entry of the backup incumbent realm stack is settings.
- auto& event_loop = HTML::main_thread_event_loop();
+ auto& event_loop = HTML::current_event_loop();
VERIFY(&event_loop.top_of_backup_incumbent_realm_stack() == &settings);
// 4. Remove settings from the backup incumbent realm stack.
@@ -411,18 +411,18 @@ JS::Realm& incumbent_realm()
GC::Ptr<EnvironmentSettingsObject> environment_settings_object_at(EnvironmentSettingsObjectAddress address)
{
- return main_thread_event_loop().environment_settings_object_at(address);
+ return current_event_loop().environment_settings_object_at(address);
}
GC::Ptr<EnvironmentSettingsObject> environment_settings_object_with_id(EnvironmentId const& id)
{
- return main_thread_event_loop().environment_settings_object_with_id(id);
+ return current_event_loop().environment_settings_object_with_id(id);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#incumbent-settings-object
EnvironmentSettingsObject& incumbent_settings_object()
{
- auto& event_loop = HTML::main_thread_event_loop();
+ auto& event_loop = HTML::current_event_loop();
auto& vm = event_loop.vm();
// 1. Let context be the topmost script-having execution context.
@@ -472,14 +472,14 @@ EnvironmentSettingsObject& principal_realm_settings_object(JS::Realm& realm)
EnvironmentSettingsObject& current_settings_object()
{
// Then, the current settings object is the environment settings object of the current realm.
- return principal_realm_settings_object(*Bindings::main_thread_vm().current_realm());
+ return principal_realm_settings_object(*JS::VM::the().current_realm());
}
// https://html.spec.whatwg.org/multipage/webappapis.html#current-global-object
JS::Object& current_global_object()
{
// Similarly, the current global object is the global object of the current realm.
- return Bindings::main_thread_vm().current_realm()->global_object();
+ return JS::VM::the().current_realm()->global_object();
}
Window& current_window()
@@ -652,7 +652,7 @@ WindowOrWorkerGlobalScopeMixin& relevant_window_or_worker_global_scope(Window co
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-entry-realm
JS::Realm& entry_realm()
{
- auto& event_loop = HTML::main_thread_event_loop();
+ auto& event_loop = HTML::current_event_loop();
auto& vm = event_loop.vm();
// With this in hand, we define the entry execution context to be the most recently pushed item in the JavaScript execution context stack that is a realm execution context.
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
index c5bebe1c672..29cf47851e9 100644
--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp
@@ -197,7 +197,7 @@ Utf16String module_type_from_module_request(JS::ModuleRequest const& module_requ
// https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, Utf16View specifier)
{
- auto& vm = Bindings::main_thread_vm();
+ auto& vm = JS::VM::the();
// 1. Let settingsObject and baseURL be null.
GC::Ptr<EnvironmentSettingsObject> settings_object;
diff --git a/Libraries/LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h b/Libraries/LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h
index 7e135d112cd..2a44088e3a5 100644
--- a/Libraries/LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h
+++ b/Libraries/LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h
@@ -24,6 +24,8 @@ struct SimilarOriginWindowAgent : public Agent {
static WEB_API NonnullOwnPtr<SimilarOriginWindowAgent> create(GC::Heap&);
+ virtual bool is_similar_origin_window_agent() const override { return true; }
+
// https://dom.spec.whatwg.org/#mutation-observer-compound-microtask-queued-flag
// Each similar-origin window agent has a mutation observer microtask queued (a boolean), which is initially false. [HTML]
bool mutation_observer_microtask_queued { false };
diff --git a/Libraries/LibWeb/IndexedDB/IDBFactory.cpp b/Libraries/LibWeb/IndexedDB/IDBFactory.cpp
index 483efc036dc..636332c891e 100644
--- a/Libraries/LibWeb/IndexedDB/IDBFactory.cpp
+++ b/Libraries/LibWeb/IndexedDB/IDBFactory.cpp
@@ -26,7 +26,7 @@ GC::Ref<IDBFactory> IDBFactory::create(JS::Realm& realm)
bool cleanup_indexed_database_transactions(HTML::EventLoop& event_loop)
{
- return web_rust_indexed_db_cleanup_indexed_database_transactions(JS::HostABI::vm_to_abi(Bindings::main_thread_vm()), &event_loop);
+ return web_rust_indexed_db_cleanup_indexed_database_transactions(JS::HostABI::vm_to_abi(JS::VM::the()), &event_loop);
}
void close_all_database_connections(JS::Realm& realm)
diff --git a/Libraries/LibWeb/IndexedDB/Inspection.cpp b/Libraries/LibWeb/IndexedDB/Inspection.cpp
index f1c6ed6a250..8136ea5fc47 100644
--- a/Libraries/LibWeb/IndexedDB/Inspection.cpp
+++ b/Libraries/LibWeb/IndexedDB/Inspection.cpp
@@ -53,7 +53,7 @@ struct IndexedDatabaseDocument {
static JSVM* vm()
{
- return JS::HostABI::vm_to_abi(Bindings::main_thread_vm());
+ return JS::HostABI::vm_to_abi(JS::VM::the());
}
static String serialize_key_path(KeyPathAbi const& key_path)
diff --git a/Libraries/LibWeb/IndexedDB/RustIntegration.cpp b/Libraries/LibWeb/IndexedDB/RustIntegration.cpp
index 14ad6b195dc..99e182f0806 100644
--- a/Libraries/LibWeb/IndexedDB/RustIntegration.cpp
+++ b/Libraries/LibWeb/IndexedDB/RustIntegration.cpp
@@ -39,7 +39,7 @@ JSObject* web_indexed_db_wrap_dom_exception(void* realm, void* exception);
JSObject* web_indexed_db_create_dom_string_list(void* realm, FlatPtr const* strings, size_t count);
void web_indexed_db_queue_a_database_task(void* cell, void (*steps)(JSVM*, void*));
void web_indexed_db_run_in_parallel(void* cell, void (*steps)(JSVM*, void*));
-void* web_indexed_db_main_thread_event_loop();
+void* web_indexed_db_current_event_loop();
void web_indexed_db_enqueue_check_pending_connection_wait(void* database);
bool web_indexed_db_devtools_client_is_active(void* realm);
IndexedDB::TransactionChanges* web_indexed_db_create_transaction_changes();
@@ -90,7 +90,7 @@ void web_indexed_db_queue_a_database_task(void* cell, void (*steps)(JSVM*, void*
GC::Ref<GC::Cell> function = *static_cast<GC::Cell*>(cell);
// NB: The task's captures, which the collector scans, keep the function alive until the steps run.
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(GC::Heap::the(), [function, steps] {
- steps(JS::HostABI::vm_to_abi(Bindings::main_thread_vm()), function.ptr());
+ steps(JS::HostABI::vm_to_abi(JS::VM::the()), function.ptr());
}));
}
@@ -99,13 +99,13 @@ void web_indexed_db_run_in_parallel(void* cell, void (*steps)(JSVM*, void*))
GC::Ref<GC::Cell> function = *static_cast<GC::Cell*>(cell);
// NB: The function's captures, which the collector scans, keep the cell alive until the steps run.
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [function, steps] {
- steps(JS::HostABI::vm_to_abi(Bindings::main_thread_vm()), function.ptr());
+ steps(JS::HostABI::vm_to_abi(JS::VM::the()), function.ptr());
}));
}
-void* web_indexed_db_main_thread_event_loop()
+void* web_indexed_db_current_event_loop()
{
- return &HTML::main_thread_event_loop();
+ return &HTML::current_event_loop();
}
void web_indexed_db_enqueue_check_pending_connection_wait(void* database)
@@ -113,7 +113,7 @@ void web_indexed_db_enqueue_check_pending_connection_wait(void* database)
GC::Heap::the().enqueue_post_gc_task([database = GC::Weak<GC::Cell>(*static_cast<GC::Cell*>(database))] {
if (!database)
return;
- web_rust_indexed_db_check_pending_connection_wait(JS::HostABI::vm_to_abi(Bindings::main_thread_vm()), database.ptr().ptr());
+ web_rust_indexed_db_check_pending_connection_wait(JS::HostABI::vm_to_abi(JS::VM::the()), database.ptr().ptr());
});
}
diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp
index 935c2cd4fea..084d344b4df 100644
--- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp
+++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp
@@ -83,7 +83,7 @@ void MediaSource::queue_a_media_source_task(GC::Ref<GC::Function<void()>> task)
if (media_element_assigned_to() != nullptr)
document = media_element_assigned_to()->document();
- HTML::queue_a_task(HTML::Task::Source::Unspecified, HTML::main_thread_event_loop(), document, task);
+ HTML::queue_a_task(HTML::Task::Source::Unspecified, HTML::current_event_loop(), document, task);
}
bool MediaSource::ready_state_is_closed() const
diff --git a/Libraries/LibWeb/ServiceWorker/Job.cpp b/Libraries/LibWeb/ServiceWorker/Job.cpp
index a7a4983031a..f1cd231f8d6 100644
--- a/Libraries/LibWeb/ServiceWorker/Job.cpp
+++ b/Libraries/LibWeb/ServiceWorker/Job.cpp
@@ -444,7 +444,7 @@ static void update(JS::VM& vm, GC::Ref<Job> job)
auto fetch_controller = fetch_job_script(*job, *request, move(fetch_algorithms_input), consume_body);
// FIXME: This feels.. uncomfortable but it should work to block the current task until the fetch has progressed past our processResponse hook or aborted
- auto& event_loop = job->client ? job->client->responsible_event_loop() : HTML::main_thread_event_loop();
+ auto& event_loop = job->client ? job->client->responsible_event_loop() : HTML::current_event_loop();
event_loop.spin_until(GC::create_function(GC::Heap::the(), [fetch_controller, &process_response_completion_result]() -> bool {
if (process_response_completion_result.has_value())
return true;
diff --git a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index 227f598ef82..d602ffbe18b 100644
--- a/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -1109,7 +1109,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(NullableDocumentOrXMLHttpRequestB
// deferred by nsAutoSyncOperation — so its timers and author microtasks hold as well.
// AD-HOC: We don't update the rendering when pausing: That runs author callbacks (e.g., rAF callbacks),
// which must not run inside a blocked send() — itself possibly invoked from within a microtask.
- auto pause_handle = HTML::main_thread_event_loop().pause(HTML::EventLoop::UpdateTheRendering::No);
+ auto pause_handle = HTML::current_event_loop().pause(HTML::EventLoop::UpdateTheRendering::No);
Platform::EventLoopPlugin::the().spin_until(GC::create_function(GC::Heap::the(), [processed_response, did_time_out]() {
return processed_response->value() || did_time_out->value();
}));