mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
LibWeb: Add the missing MessageEvent IDL constructor
This commit is contained in:
parent
9863de4609
commit
d44857d34d
4 changed files with 36 additions and 8 deletions
|
@ -10,13 +10,23 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
struct MessageEventInit : public DOM::EventInit {
|
||||||
|
JS::Value data { JS::js_null() };
|
||||||
|
String origin { "" };
|
||||||
|
String last_event_id { "" };
|
||||||
|
};
|
||||||
|
|
||||||
class MessageEvent : public DOM::Event {
|
class MessageEvent : public DOM::Event {
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::MessageEventWrapper;
|
using WrapperType = Bindings::MessageEventWrapper;
|
||||||
|
|
||||||
static NonnullRefPtr<MessageEvent> create(const FlyString& event_name, JS::Value data, String const& origin)
|
static NonnullRefPtr<MessageEvent> create(FlyString const& event_name, MessageEventInit const& event_init = {})
|
||||||
{
|
{
|
||||||
return adopt_ref(*new MessageEvent(event_name, data, origin));
|
return adopt_ref(*new MessageEvent(event_name, event_init));
|
||||||
|
}
|
||||||
|
static NonnullRefPtr<MessageEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, MessageEventInit const& event_init)
|
||||||
|
{
|
||||||
|
return MessageEvent::create(event_name, event_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MessageEvent() override = default;
|
virtual ~MessageEvent() override = default;
|
||||||
|
@ -26,10 +36,11 @@ public:
|
||||||
String const& last_event_id() const { return m_last_event_id; }
|
String const& last_event_id() const { return m_last_event_id; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MessageEvent(const FlyString& event_name, JS::Value data, String origin)
|
MessageEvent(FlyString const& event_name, MessageEventInit const& event_init)
|
||||||
: DOM::Event(event_name)
|
: DOM::Event(event_name, event_init)
|
||||||
, m_data(data)
|
, m_data(event_init.data)
|
||||||
, m_origin(move(origin))
|
, m_origin(event_init.origin)
|
||||||
|
, m_last_event_id(event_init.last_event_id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
#import <DOM/Event.idl>
|
||||||
|
|
||||||
interface MessageEvent : Event {
|
interface MessageEvent : Event {
|
||||||
|
constructor(DOMString type, optional MessageEventInit eventInitDict = {});
|
||||||
|
|
||||||
readonly attribute any data;
|
readonly attribute any data;
|
||||||
readonly attribute USVString origin;
|
readonly attribute USVString origin;
|
||||||
|
@ -6,3 +9,11 @@ interface MessageEvent : Event {
|
||||||
// FIXME: readonly attribute MessageEventSource? source;
|
// FIXME: readonly attribute MessageEventSource? source;
|
||||||
// FIXME: readonly attribute FrozenArray<MessagePort> ports;
|
// FIXME: readonly attribute FrozenArray<MessagePort> ports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary MessageEventInit : EventInit {
|
||||||
|
any data = null;
|
||||||
|
USVString origin = "";
|
||||||
|
DOMString lastEventId = "";
|
||||||
|
// FIXME: MessageEventSource? source = null;
|
||||||
|
// FIXME: sequence<MessagePort> ports = [];
|
||||||
|
};
|
||||||
|
|
|
@ -80,7 +80,10 @@ void MessagePort::post_message(JS::Value message)
|
||||||
// FIXME: This is an ad-hoc hack implementation instead, since we don't currently
|
// FIXME: This is an ad-hoc hack implementation instead, since we don't currently
|
||||||
// have serialization and deserialization of messages.
|
// have serialization and deserialization of messages.
|
||||||
main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [strong_port = NonnullRefPtr { *target_port }, message]() mutable {
|
main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [strong_port = NonnullRefPtr { *target_port }, message]() mutable {
|
||||||
strong_port->dispatch_event(MessageEvent::create(HTML::EventNames::message, message, "<origin>"));
|
MessageEventInit event_init {};
|
||||||
|
event_init.data = message;
|
||||||
|
event_init.origin = "<origin>";
|
||||||
|
strong_port->dispatch_event(MessageEvent::create(HTML::EventNames::message, event_init));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,10 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
|
||||||
return;
|
return;
|
||||||
if (is_text) {
|
if (is_text) {
|
||||||
auto text_message = String(ReadonlyBytes(message));
|
auto text_message = String(ReadonlyBytes(message));
|
||||||
dispatch_event(MessageEvent::create(EventNames::message, JS::js_string(wrapper()->vm(), text_message), url()));
|
MessageEventInit event_init {};
|
||||||
|
event_init.data = JS::js_string(wrapper()->vm(), text_message);
|
||||||
|
event_init.origin = url();
|
||||||
|
dispatch_event(MessageEvent::create(EventNames::message, event_init));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// type indicates that the data is Binary and binaryType is "blob"
|
// type indicates that the data is Binary and binaryType is "blob"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue