mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder and decoder to serialize JS values. It also used a u32 buffer under the hood, which made using its structures a bit awkward. We had previously worked around its data structures in transferable streams, which nested transfers of MessagePort instances. We basically had to add hooks into the MessagePort to route to the correct transfer receiving steps, and we could not invoke the correct AOs directly as the spec dictates. We now use IPC mechanics to encode and decode data. This works because, although we are encoding JS values, we are only ultimately encoding primitive and basic AK types. The resulting data structures actually enforce that we implement transferable streams exactly as the spec is worded (I had planned to do that in a separate commit, but the fallout of this patch actually required that change).
This commit is contained in:
parent
7fad8c333d
commit
64abc6101d
Notes:
github-actions[bot]
2025-07-18 14:10:44 +00:00
Author: https://github.com/trflynn89
Commit: 64abc6101d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5492
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/shannonbooth
44 changed files with 765 additions and 970 deletions
|
@ -36,7 +36,7 @@ WorkerHost::WorkerHost(URL::URL url, Web::Bindings::WorkerType type, String name
|
|||
WorkerHost::~WorkerHost() = default;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#run-a-worker
|
||||
void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataHolder message_port_data, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings_snapshot, Web::Bindings::RequestCredentials credentials, bool is_shared)
|
||||
void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder message_port_data, Web::HTML::SerializedEnvironmentSettingsObject const& outside_settings_snapshot, Web::Bindings::RequestCredentials credentials, bool is_shared)
|
||||
{
|
||||
// 3. Let unsafeWorkerCreationTime be the unsafe shared current time.
|
||||
auto unsafe_worker_creation_time = Web::HighResolutionTime::unsafe_shared_current_time();
|
||||
|
@ -157,6 +157,7 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataHolder mess
|
|||
|
||||
auto on_complete_function = [inside_settings, worker_global_scope, message_port_data = move(message_port_data), url = m_url, is_shared](GC::Ptr<Web::HTML::Script> script) mutable {
|
||||
auto& realm = inside_settings->realm();
|
||||
|
||||
// 1. If script is null or if script's error to rethrow is non-null, then:
|
||||
if (!script || !script->error_to_rethrow().is_null()) {
|
||||
// FIXME: 1. Queue a global task on the DOM manipulation task source given worker's relevant global object to fire an event named error at worker.
|
||||
|
@ -180,7 +181,8 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataHolder mess
|
|||
worker_global_scope->set_internal_port(inside_port);
|
||||
|
||||
// 5. Entangle outside port and inside port.
|
||||
MUST(inside_port->transfer_receiving_steps(message_port_data));
|
||||
Web::HTML::TransferDataDecoder decoder { move(message_port_data) };
|
||||
MUST(inside_port->transfer_receiving_steps(decoder));
|
||||
|
||||
// 6. Create a new WorkerLocation object and associate it with worker global scope.
|
||||
worker_global_scope->set_location(realm.create<Web::HTML::WorkerLocation>(*worker_global_scope));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue