mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
Fixes flakiness in worker tests that create a Worker or SharedWorker with a missing script URL and only attach an error handler to it. Once the test callback returns, nothing keeps the worker rooted from JavaScript. If GC ran before the WebWorker process reported the script fetch failure, the Worker/WorkerAgentParent cycle could be collected and the error event never delivered, leaving the test hung until timeout. Hold startup-pending WorkerAgentParents from the outside EnvironmentSettingsObject and release that edge once the script load succeeds, fails, or the worker closes. The worker now survives long enough to deliver its first script-load result.
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibURL/URL.h>
|
|
#include <LibWeb/Bindings/AgentType.h>
|
|
#include <LibWeb/Bindings/Request.h>
|
|
#include <LibWeb/Bindings/Worker.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
struct WorkerOptions {
|
|
String name { String {} };
|
|
Bindings::WorkerType type { Bindings::WorkerType::Classic };
|
|
Bindings::RequestCredentials credentials { Bindings::RequestCredentials::SameOrigin };
|
|
};
|
|
|
|
// FIXME: Figure out a better naming convention for this type of parent/child process pattern.
|
|
class WorkerAgentParent : public JS::Cell {
|
|
GC_CELL(WorkerAgentParent, JS::Cell);
|
|
GC_DECLARE_ALLOCATOR(WorkerAgentParent);
|
|
|
|
protected:
|
|
WorkerAgentParent(URL::URL url, WorkerOptions const& options, GC::Ptr<MessagePort> outside_port, GC::Ref<EnvironmentSettingsObject> outside_settings, GC::Ref<DOM::EventTarget> worker_event_target, Bindings::AgentType);
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
private:
|
|
void setup_worker_ipc_callbacks(JS::Realm&);
|
|
void release_startup_keep_alive();
|
|
|
|
WorkerOptions m_worker_options;
|
|
Bindings::AgentType m_agent_type { Bindings::AgentType::DedicatedWorker };
|
|
URL::URL m_url;
|
|
|
|
GC::Ptr<MessagePort> m_message_port;
|
|
GC::Ptr<MessagePort> m_outside_port;
|
|
GC::Ref<EnvironmentSettingsObject> m_outside_settings;
|
|
GC::Ref<DOM::EventTarget> m_worker_event_target;
|
|
|
|
RefPtr<Web::HTML::WebWorkerClient> m_worker_ipc;
|
|
};
|
|
|
|
}
|