summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-01 18:39:03 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-01 20:14:45 +0200
commitd44857d34d0aebef52374297b846304321d355ac (patch)
tree5b5b1a69fe7215479c37157490b4da079c01b664 /Userland
parent9863de4609d81a0c6b97556e13f2bc19c2c8c449 (diff)
downloadserenity-d44857d34d0aebef52374297b846304321d355ac.zip
LibWeb: Add the missing MessageEvent IDL constructor
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/MessageEvent.h23
-rw-r--r--Userland/Libraries/LibWeb/HTML/MessageEvent.idl11
-rw-r--r--Userland/Libraries/LibWeb/HTML/MessagePort.cpp5
-rw-r--r--Userland/Libraries/LibWeb/HTML/WebSocket.cpp5
4 files changed, 36 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.h b/Userland/Libraries/LibWeb/HTML/MessageEvent.h
index 32b80883cb..e08c001eb0 100644
--- a/Userland/Libraries/LibWeb/HTML/MessageEvent.h
+++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.h
@@ -10,13 +10,23 @@
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 {
public:
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, event_init));
+ }
+ static NonnullRefPtr<MessageEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, MessageEventInit const& event_init)
{
- return adopt_ref(*new MessageEvent(event_name, data, origin));
+ return MessageEvent::create(event_name, event_init);
}
virtual ~MessageEvent() override = default;
@@ -26,10 +36,11 @@ public:
String const& last_event_id() const { return m_last_event_id; }
protected:
- MessageEvent(const FlyString& event_name, JS::Value data, String origin)
- : DOM::Event(event_name)
- , m_data(data)
- , m_origin(move(origin))
+ MessageEvent(FlyString const& event_name, MessageEventInit const& event_init)
+ : DOM::Event(event_name, event_init)
+ , m_data(event_init.data)
+ , m_origin(event_init.origin)
+ , m_last_event_id(event_init.last_event_id)
{
}
diff --git a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl
index 5eadf05c26..7f5970ddf3 100644
--- a/Userland/Libraries/LibWeb/HTML/MessageEvent.idl
+++ b/Userland/Libraries/LibWeb/HTML/MessageEvent.idl
@@ -1,4 +1,7 @@
+#import <DOM/Event.idl>
+
interface MessageEvent : Event {
+ constructor(DOMString type, optional MessageEventInit eventInitDict = {});
readonly attribute any data;
readonly attribute USVString origin;
@@ -6,3 +9,11 @@ interface MessageEvent : Event {
// FIXME: readonly attribute MessageEventSource? source;
// FIXME: readonly attribute FrozenArray<MessagePort> ports;
};
+
+dictionary MessageEventInit : EventInit {
+ any data = null;
+ USVString origin = "";
+ DOMString lastEventId = "";
+ // FIXME: MessageEventSource? source = null;
+ // FIXME: sequence<MessagePort> ports = [];
+};
diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp
index 9f94ba1f5e..2ae143647e 100644
--- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp
+++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp
@@ -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
// 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 {
- 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));
}));
}
diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
index a73df59177..5094174577 100644
--- a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
@@ -203,7 +203,10 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
return;
if (is_text) {
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;
}
// type indicates that the data is Binary and binaryType is "blob"