mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 15:35:08 +00:00
LibWeb: Add MessageEvent.source
This commit is contained in:
parent
eaa3b85864
commit
1607b2c978
3 changed files with 21 additions and 2 deletions
|
@ -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<WindowProxy>, JS::Handle<MessagePort>, Empty> MessageEvent::source() const
|
||||
{
|
||||
if (!m_source.has_value())
|
||||
return Empty {};
|
||||
|
||||
return m_source.value().downcast<JS::Handle<WindowProxy>, JS::Handle<MessagePort>>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,10 +12,14 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
// FIXME: Include ServiceWorker
|
||||
using MessageEventSource = Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>>;
|
||||
|
||||
struct MessageEventInit : public DOM::EventInit {
|
||||
JS::Value data { JS::js_null() };
|
||||
String origin;
|
||||
String last_event_id;
|
||||
Optional<MessageEventSource> 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<WindowProxy>, JS::Handle<MessagePort>, 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<MessageEventSource> m_source;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
#import <DOM/Event.idl>
|
||||
#import <HTML/MessagePort.idl>
|
||||
|
||||
// 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<MessagePort> ports;
|
||||
};
|
||||
|
||||
|
@ -16,6 +20,6 @@ dictionary MessageEventInit : EventInit {
|
|||
any data = null;
|
||||
USVString origin = "";
|
||||
DOMString lastEventId = "";
|
||||
// FIXME: MessageEventSource? source = null;
|
||||
MessageEventSource? source = null;
|
||||
// FIXME: sequence<MessagePort> ports = [];
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue