mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb+WebWorker: Convert Workers to use MessagePorts for postMessage
This aligns Workers and Window and MessagePorts to all use the same mechanism for transferring serialized messages across realms. It also allows transferring more message ports into a worker. Re-enable the Worker-echo test, as none of the MessagePort tests have themselves been flaky, and those are now using the same underlying implementation.
This commit is contained in:
parent
37f2d49818
commit
b10fee00eb
21 changed files with 159 additions and 222 deletions
|
@ -32,8 +32,8 @@ class Worker : public DOM::EventTarget {
|
|||
JS_DECLARE_ALLOCATOR(Worker);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> create(String const& script_url, WorkerOptions const options, DOM::Document& document);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> construct_impl(JS::Realm& realm, String const& script_url, WorkerOptions const options)
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> create(String const& script_url, WorkerOptions const& options, DOM::Document& document);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Worker>> construct_impl(JS::Realm& realm, String const& script_url, WorkerOptions const& options)
|
||||
{
|
||||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
return Worker::create(script_url, options, window.associated_document());
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<void> terminate();
|
||||
|
||||
WebIDL::ExceptionOr<void> post_message(JS::Value message, JS::Value transfer);
|
||||
WebIDL::ExceptionOr<void> post_message(JS::Value message, StructuredSerializeOptions const&);
|
||||
|
||||
virtual ~Worker() = default;
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
#undef __ENUMERATE
|
||||
|
||||
protected:
|
||||
Worker(String const&, const WorkerOptions, DOM::Document&);
|
||||
Worker(String const&, WorkerOptions const&, DOM::Document&);
|
||||
|
||||
private:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
@ -66,17 +66,10 @@ private:
|
|||
|
||||
JS::GCPtr<DOM::Document> m_document;
|
||||
JS::GCPtr<MessagePort> m_outside_port;
|
||||
// FIXME: Move tihs state into the message port (and actually use it :) )
|
||||
enum class PortState : u8 {
|
||||
Header,
|
||||
Data,
|
||||
Error,
|
||||
} m_outside_port_state { PortState::Header };
|
||||
size_t m_outside_port_incoming_message_size { 0 };
|
||||
|
||||
JS::GCPtr<WorkerAgent> m_agent;
|
||||
|
||||
void run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, MessagePort& outside_port, WorkerOptions const& options);
|
||||
void run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_settings, JS::GCPtr<MessagePort> outside_port, WorkerOptions const& options);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue