mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Allow creating a MessagePort with a different primary interface
This is needed to transfer streams, which use message ports as the means of transport.
This commit is contained in:
Notes:
github-actions[bot]
2025-05-21 10:56:14 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/ee9d860ba29 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4828 Reviewed-by: https://github.com/shannonbooth ✅
@@ -20,13 +20,14 @@
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/web-messaging.html#message-ports
|
||||
class MessagePort final : public DOM::EventTarget
|
||||
class MessagePort final
|
||||
: public DOM::EventTarget
|
||||
, public Bindings::Transferable {
|
||||
WEB_PLATFORM_OBJECT(MessagePort, DOM::EventTarget);
|
||||
GC_DECLARE_ALLOCATOR(MessagePort);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static GC::Ref<MessagePort> create(JS::Realm&);
|
||||
[[nodiscard]] static GC::Ref<MessagePort> create(JS::Realm&, HTML::TransferType primary_interface = HTML::TransferType::MessagePort);
|
||||
|
||||
static void for_each_message_port(Function<void(MessagePort&)>);
|
||||
|
||||
@@ -59,14 +60,14 @@ public:
|
||||
// ^Transferable
|
||||
virtual WebIDL::ExceptionOr<void> transfer_steps(HTML::TransferDataHolder&) override;
|
||||
virtual WebIDL::ExceptionOr<void> transfer_receiving_steps(HTML::TransferDataHolder&) override;
|
||||
virtual HTML::TransferType primary_interface() const override { return HTML::TransferType::MessagePort; }
|
||||
virtual HTML::TransferType primary_interface() const override { return m_primary_interface; }
|
||||
|
||||
void set_worker_event_target(GC::Ref<DOM::EventTarget>);
|
||||
|
||||
WebIDL::ExceptionOr<void> message_port_post_message_steps(GC::Ptr<MessagePort> target_port, JS::Value message, StructuredSerializeOptions const& options);
|
||||
|
||||
private:
|
||||
explicit MessagePort(JS::Realm&);
|
||||
explicit MessagePort(JS::Realm&, HTML::TransferType primary_interface);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void finalize() override;
|
||||
@@ -79,6 +80,8 @@ private:
|
||||
ErrorOr<void> send_message_on_transport(SerializedTransferRecord const&);
|
||||
void read_from_transport();
|
||||
|
||||
HTML::TransferType m_primary_interface { HTML::TransferType::MessagePort };
|
||||
|
||||
// The HTML spec implies(!) that this is MessagePort.[[RemotePort]]
|
||||
GC::Ptr<MessagePort> m_remote_port;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user