Skip to content

MessageEvent

Generated from idl/messaging.webidl when the site was built at 7aa23e2.

MessageEvent is an interface in idl/messaging.webidl, inheriting Event, exposed in Window, Worker. What it does is on MDN; this page says what niso has of it.

The standard’s source is a MessageEventSource, (WindowProxy or MessagePort or ServiceWorker); niso’s is an EventTarget that the core checks is a Window or a MessagePort. The binding freezes ports and keeps the array it returned, as a FrozenArray attribute does.

The web features its members belong to, each with its Baseline status on the web and how much of the feature’s WPT suite passes in niso (see Web platform support).

Feature On the web In niso Members
postMessage Widely available Partial 70% 309 of 441 subtests pass 6
Channel messaging Widely available Partial 88% 340 of 385 subtests pass 1
constructor
constructor(DOMString type, optional MessageEventInit eventInitDict = {});
int32_t niso_message_event_new(niso_dom* dom, const char* type, size_t type_len, const niso_message_event_init* event_init_dict, niso_handle* out);
attribute
readonly attribute [NisoHeld] any data;
int32_t niso_message_event_get_data(niso_dom* dom, niso_handle self, void** out);
int32_t niso_message_event_set_data(niso_dom* dom, niso_handle self, niso_held data);

[NisoNative]: besides the value script sees, native code gets the serialization that arrived, or a WebSocket’s frame as a string or ArrayBuffer, and decodes a serialization with niso_structured_clone_decode (DECISIONS; docs/structured-clone.md).

attribute
readonly attribute USVString origin;
int32_t niso_message_event_get_origin(niso_dom* dom, niso_handle self, niso_str* out);
attribute
readonly attribute DOMString lastEventId;
int32_t niso_message_event_get_last_event_id(niso_dom* dom, niso_handle self, niso_str* out);
attribute
readonly attribute EventTarget? source;
int32_t niso_message_event_get_source(niso_dom* dom, niso_handle self, niso_handle* out);
attribute Channel messaging: Partial 88%
readonly attribute FrozenArray<MessagePort> ports;
int32_t niso_message_event_get_ports(niso_dom* dom, niso_handle self, niso_handles* out);
operation
undefined initMessageEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional [NisoHeld] any data = null, optional USVString origin = "", optional DOMString lastEventId = "", optional EventTarget? source = null, optional sequence<MessagePort> ports = []);
int32_t niso_message_event_init_message_event(niso_dom* dom, niso_handle self, const char* type, size_t type_len, bool bubbles, bool cancelable, niso_held data, const char* origin, size_t origin_len, const char* last_event_id, size_t last_event_id_len, niso_handle source, const niso_handle* ports, size_t ports_len);
operation native code only
[NisoNative] (USVString or ArrayBuffer)? nativeData();
int32_t niso_message_event_native_data(niso_dom* dom, niso_handle self, niso_buffer_or_string* out);

data is the binding’s own value, which native code cannot read (DECISIONS.md: how any crosses the C API); it reads these instead. A message the platform delivers arrives serialized (docs/structured-clone.md), where a transferred record is the index of one of this event’s ports: serializedData, which native code decodes with niso_structured_clone_decode. Data the platform makes (a WebSocket’s text or binary frame) arrives as it is, with no serialization: nativeData, the string or ArrayBuffer itself; null for a message that arrived serialized. Both are empty for an event a page made. Before the event is dispatched the core asks the binding to make data from them (the message hook), which sets it.

operation native code only
[NisoNative] ArrayBuffer serializedData();
int32_t niso_message_event_serialized_data(niso_dom* dom, niso_handle self, niso_bytes* out);
operation not in JS
[NisoInternal] undefined setData([NisoHeld] any data);
int32_t niso_message_event_set_data(niso_dom* dom, niso_handle self, niso_held data);