mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
LibWeb/HTML: Hook up a WorkerAgent for web workers
This commit is contained in:
parent
5290ebfe19
commit
041ff0c7ff
Notes:
github-actions[bot]
2025-04-25 14:45:27 +00:00
Author: https://github.com/shannonbooth
Commit: 041ff0c7ff
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4453
10 changed files with 78 additions and 12 deletions
|
@ -40,6 +40,7 @@
|
||||||
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
|
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
|
||||||
#include <LibWeb/HTML/Scripting/SyntheticRealmSettings.h>
|
#include <LibWeb/HTML/Scripting/SyntheticRealmSettings.h>
|
||||||
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
||||||
|
#include <LibWeb/HTML/Scripting/WorkerAgent.h>
|
||||||
#include <LibWeb/HTML/ShadowRealmGlobalScope.h>
|
#include <LibWeb/HTML/ShadowRealmGlobalScope.h>
|
||||||
#include <LibWeb/HTML/Window.h>
|
#include <LibWeb/HTML/Window.h>
|
||||||
#include <LibWeb/HTML/WindowProxy.h>
|
#include <LibWeb/HTML/WindowProxy.h>
|
||||||
|
@ -72,15 +73,28 @@ HTML::Script* active_script()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_main_thread_vm(HTML::EventLoop::Type type)
|
static NonnullOwnPtr<JS::Agent> create_agent(GC::Heap& heap, AgentType type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case AgentType::SimilarOriginWindow:
|
||||||
|
return HTML::SimilarOriginWindowAgent::create(heap);
|
||||||
|
case AgentType::DedicatedWorker:
|
||||||
|
case AgentType::SharedWorker:
|
||||||
|
return HTML::WorkerAgent::create(heap, JS::Agent::CanBlock::Yes);
|
||||||
|
case AgentType::ServiceWorker:
|
||||||
|
return HTML::WorkerAgent::create(heap, JS::Agent::CanBlock::No);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize_main_thread_vm(AgentType type)
|
||||||
{
|
{
|
||||||
VERIFY(!s_main_thread_vm);
|
VERIFY(!s_main_thread_vm);
|
||||||
|
|
||||||
s_main_thread_vm = JS::VM::create();
|
s_main_thread_vm = JS::VM::create();
|
||||||
s_main_thread_vm->set_agent(HTML::SimilarOriginWindowAgent::create());
|
s_main_thread_vm->set_agent(create_agent(s_main_thread_vm->heap(), type));
|
||||||
|
|
||||||
auto& agent = as<HTML::Agent>(*s_main_thread_vm->agent());
|
|
||||||
agent.event_loop = s_main_thread_vm->heap().allocate<HTML::EventLoop>(type);
|
|
||||||
|
|
||||||
s_main_thread_vm->on_unimplemented_property_access = [](auto const& object, auto const& property_key) {
|
s_main_thread_vm->on_unimplemented_property_access = [](auto const& object, auto const& property_key) {
|
||||||
dbgln("FIXME: Unimplemented IDL interface: '{}.{}'", object.class_name(), property_key.to_string());
|
dbgln("FIXME: Unimplemented IDL interface: '{}.{}'", object.class_name(), property_key.to_string());
|
||||||
|
|
|
@ -32,7 +32,15 @@ struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData
|
||||||
|
|
||||||
HTML::Script* active_script();
|
HTML::Script* active_script();
|
||||||
|
|
||||||
void initialize_main_thread_vm(HTML::EventLoop::Type);
|
enum class AgentType : u8 {
|
||||||
|
SimilarOriginWindow,
|
||||||
|
DedicatedWorker,
|
||||||
|
SharedWorker,
|
||||||
|
ServiceWorker,
|
||||||
|
Worklet,
|
||||||
|
};
|
||||||
|
|
||||||
|
void initialize_main_thread_vm(AgentType);
|
||||||
JS::VM& main_thread_vm();
|
JS::VM& main_thread_vm();
|
||||||
|
|
||||||
void queue_mutation_observer_microtask(DOM::Document const&);
|
void queue_mutation_observer_microtask(DOM::Document const&);
|
||||||
|
|
|
@ -508,6 +508,7 @@ set(SOURCES
|
||||||
HTML/Scripting/SyntheticRealmSettings.cpp
|
HTML/Scripting/SyntheticRealmSettings.cpp
|
||||||
HTML/Scripting/TemporaryExecutionContext.cpp
|
HTML/Scripting/TemporaryExecutionContext.cpp
|
||||||
HTML/Scripting/WindowEnvironmentSettingsObject.cpp
|
HTML/Scripting/WindowEnvironmentSettingsObject.cpp
|
||||||
|
HTML/Scripting/WorkerAgent.cpp
|
||||||
HTML/Scripting/WorkerEnvironmentSettingsObject.cpp
|
HTML/Scripting/WorkerEnvironmentSettingsObject.cpp
|
||||||
HTML/Scripting/SerializedEnvironmentSettingsObject.cpp
|
HTML/Scripting/SerializedEnvironmentSettingsObject.cpp
|
||||||
HTML/SelectedFile.cpp
|
HTML/SelectedFile.cpp
|
||||||
|
|
|
@ -11,10 +11,12 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
NonnullOwnPtr<SimilarOriginWindowAgent> SimilarOriginWindowAgent::create()
|
NonnullOwnPtr<SimilarOriginWindowAgent> SimilarOriginWindowAgent::create(GC::Heap& heap)
|
||||||
{
|
{
|
||||||
// See 'creating an agent' step in: https://html.spec.whatwg.org/multipage/webappapis.html#obtain-similar-origin-window-agent
|
// See 'creating an agent' step in: https://html.spec.whatwg.org/multipage/webappapis.html#obtain-similar-origin-window-agent
|
||||||
return adopt_own(*new SimilarOriginWindowAgent(CanBlock::No));
|
auto agent = adopt_own(*new SimilarOriginWindowAgent(CanBlock::No));
|
||||||
|
agent->event_loop = heap.allocate<HTML::EventLoop>(HTML::EventLoop::Type::Window);
|
||||||
|
return agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#relevant-agent
|
// https://html.spec.whatwg.org/multipage/webappapis.html#relevant-agent
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#similar-origin-window-agent
|
// https://html.spec.whatwg.org/multipage/webappapis.html#similar-origin-window-agent
|
||||||
struct SimilarOriginWindowAgent : public Agent {
|
struct SimilarOriginWindowAgent : public Agent {
|
||||||
static NonnullOwnPtr<SimilarOriginWindowAgent> create();
|
static NonnullOwnPtr<SimilarOriginWindowAgent> create(GC::Heap&);
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#mutation-observer-compound-microtask-queued-flag
|
// 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]
|
// Each similar-origin window agent has a mutation observer microtask queued (a boolean), which is initially false. [HTML]
|
||||||
|
|
19
Libraries/LibWeb/HTML/Scripting/WorkerAgent.cpp
Normal file
19
Libraries/LibWeb/HTML/Scripting/WorkerAgent.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||||
|
#include <LibWeb/HTML/Scripting/WorkerAgent.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
NonnullOwnPtr<WorkerAgent> WorkerAgent::create(GC::Heap& heap, CanBlock can_block)
|
||||||
|
{
|
||||||
|
auto agent = adopt_own(*new WorkerAgent(can_block));
|
||||||
|
agent->event_loop = heap.allocate<HTML::EventLoop>(HTML::EventLoop::Type::Worker);
|
||||||
|
return agent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
22
Libraries/LibWeb/HTML/Scripting/WorkerAgent.h
Normal file
22
Libraries/LibWeb/HTML/Scripting/WorkerAgent.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/HTML/Scripting/Agent.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/webappapis.html#dedicated-worker-agent
|
||||||
|
// https://html.spec.whatwg.org/multipage/webappapis.html#shared-worker-agent
|
||||||
|
struct WorkerAgent : public Agent {
|
||||||
|
static NonnullOwnPtr<WorkerAgent> create(GC::Heap&, CanBlock);
|
||||||
|
|
||||||
|
private:
|
||||||
|
using Agent::Agent;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ struct Globals {
|
||||||
Globals::Globals()
|
Globals::Globals()
|
||||||
{
|
{
|
||||||
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
|
Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
|
||||||
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window);
|
Web::Bindings::initialize_main_thread_vm(Web::Bindings::AgentType::SimilarOriginWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(is_layout_test_mode, &font_provider));
|
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(is_layout_test_mode, &font_provider));
|
||||||
|
|
||||||
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window);
|
Web::Bindings::initialize_main_thread_vm(Web::Bindings::AgentType::SimilarOriginWindow);
|
||||||
|
|
||||||
if (collect_garbage_on_every_allocation)
|
if (collect_garbage_on_every_allocation)
|
||||||
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);
|
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);
|
||||||
|
|
|
@ -68,7 +68,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(false));
|
Web::Platform::FontPlugin::install(*new WebView::FontPlugin(false));
|
||||||
|
|
||||||
Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Worker);
|
Web::Bindings::initialize_main_thread_vm(Web::Bindings::AgentType::DedicatedWorker);
|
||||||
|
|
||||||
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
|
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue