1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:17:42 +00:00

LibWeb: Add ports attribute to MessageEvent and MessageEventInit

Still some FIXMEs left though, as the IDL generator doesn't know what
a FrozenArray is, nor how to properly create a sequence of a Platform
Object.
This commit is contained in:
Andrew Kaster 2023-12-12 13:28:38 -07:00 committed by Andrew Kaster
parent e464d484c4
commit 73697058b0
3 changed files with 21 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibJS/Runtime/Array.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/MessageEvent.h> #include <LibWeb/HTML/MessageEvent.h>
@ -27,6 +28,7 @@ MessageEvent::MessageEvent(JS::Realm& realm, FlyString const& event_name, Messag
, m_origin(event_init.origin) , m_origin(event_init.origin)
, m_last_event_id(event_init.last_event_id) , m_last_event_id(event_init.last_event_id)
, m_source(event_init.source) , m_source(event_init.source)
, m_ports(event_init.ports)
{ {
} }
@ -52,4 +54,17 @@ Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>, Empty> MessageEvent::s
return m_source.value().downcast<JS::Handle<WindowProxy>, JS::Handle<MessagePort>>(); return m_source.value().downcast<JS::Handle<WindowProxy>, JS::Handle<MessagePort>>();
} }
JS::NonnullGCPtr<JS::Object> MessageEvent::ports() const
{
if (!m_ports_array) {
Vector<JS::Value> port_vector;
for (auto const& port : m_ports) {
port_vector.append(JS::Value(port.ptr()));
}
m_ports_array = JS::Array::create_from(realm(), port_vector);
MUST(m_ports_array->set_integrity_level(IntegrityLevel::Frozen));
}
return *m_ports_array;
}
} }

View file

@ -20,6 +20,7 @@ struct MessageEventInit : public DOM::EventInit {
String origin {}; String origin {};
String last_event_id {}; String last_event_id {};
Optional<MessageEventSource> source; Optional<MessageEventSource> source;
Vector<JS::Handle<JS::Object>> ports;
}; };
class MessageEvent : public DOM::Event { class MessageEvent : public DOM::Event {
@ -36,6 +37,7 @@ public:
JS::Value data() const { return m_data; } JS::Value data() const { return m_data; }
String const& origin() const { return m_origin; } String const& origin() const { return m_origin; }
String const& last_event_id() const { return m_last_event_id; } String const& last_event_id() const { return m_last_event_id; }
JS::NonnullGCPtr<JS::Object> ports() const;
Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>, Empty> source() const; Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>, Empty> source() const;
private: private:
@ -46,6 +48,8 @@ private:
String m_origin; String m_origin;
String m_last_event_id; String m_last_event_id;
Optional<MessageEventSource> m_source; Optional<MessageEventSource> m_source;
Vector<JS::Handle<JS::Object>> m_ports;
mutable JS::GCPtr<JS::Array> m_ports_array;
}; };
} }

View file

@ -14,6 +14,7 @@ interface MessageEvent : Event {
readonly attribute DOMString lastEventId; readonly attribute DOMString lastEventId;
readonly attribute MessageEventSource? source; readonly attribute MessageEventSource? source;
// FIXME: readonly attribute FrozenArray<MessagePort> ports; // FIXME: readonly attribute FrozenArray<MessagePort> ports;
readonly attribute any ports;
}; };
dictionary MessageEventInit : EventInit { dictionary MessageEventInit : EventInit {
@ -22,4 +23,5 @@ dictionary MessageEventInit : EventInit {
DOMString lastEventId = ""; DOMString lastEventId = "";
MessageEventSource? source = null; MessageEventSource? source = null;
// FIXME: sequence<MessagePort> ports = []; // FIXME: sequence<MessagePort> ports = [];
sequence<object> ports = [];
}; };