diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp index 777eea5afc..f34d27fe59 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.cpp @@ -24,6 +24,7 @@ MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, Messag , m_data(event_init.data) , m_origin(event_init.origin) , m_last_event_id(event_init.last_event_id) + , m_source(event_init.source) { } @@ -41,4 +42,12 @@ void MessageEvent::visit_edges(Cell::Visitor& visitor) visitor.visit(m_data); } +Variant, JS::Handle, Empty> MessageEvent::source() const +{ + if (!m_source.has_value()) + return Empty {}; + + return m_source.value().downcast, JS::Handle>(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.h b/Userland/Libraries/LibWeb/HTML/MessageEvent.h index 32fbb9fc95..0c3d4b523e 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.h +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.h @@ -12,10 +12,14 @@ namespace Web::HTML { +// FIXME: Include ServiceWorker +using MessageEventSource = Variant, JS::Handle>; + struct MessageEventInit : public DOM::EventInit { JS::Value data { JS::js_null() }; String origin; String last_event_id; + Optional source; }; class MessageEvent : public DOM::Event { @@ -31,6 +35,7 @@ public: JS::Value data() const { return m_data; } String const& origin() const { return m_origin; } String const& last_event_id() const { return m_last_event_id; } + Variant, JS::Handle, Empty> source() const; private: virtual void initialize(JS::Realm&) override; @@ -39,6 +44,7 @@ private: JS::Value m_data; String m_origin; String m_last_event_id; + Optional m_source; }; } diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl index f394f7b6d2..0b3168a09d 100644 --- a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl +++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl @@ -1,4 +1,8 @@ #import +#import + +// FIXME: typedef (WindowProxy or MessagePort or ServiceWorker) MessageEventSource; +typedef (WindowProxy or MessagePort) MessageEventSource; // https://html.spec.whatwg.org/multipage/comms.html#messageevent [Exposed=(Window,Worker)] @@ -8,7 +12,7 @@ interface MessageEvent : Event { readonly attribute any data; readonly attribute USVString origin; readonly attribute DOMString lastEventId; - // FIXME: readonly attribute MessageEventSource? source; + readonly attribute MessageEventSource? source; // FIXME: readonly attribute FrozenArray ports; }; @@ -16,6 +20,6 @@ dictionary MessageEventInit : EventInit { any data = null; USVString origin = ""; DOMString lastEventId = ""; - // FIXME: MessageEventSource? source = null; + MessageEventSource? source = null; // FIXME: sequence ports = []; };