#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)]
interface MessageEvent : Event {
    constructor(DOMString type, optional MessageEventInit eventInitDict = {});

    readonly attribute any data;
    readonly attribute USVString origin;
    readonly attribute DOMString lastEventId;
    readonly attribute MessageEventSource? source;
    // FIXME: This should be FrozenArray<MessagePort>, but must also always return the same object.
    readonly attribute any ports;

    undefined initMessageEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional any data = null, optional USVString origin = "", optional DOMString lastEventId = "", optional MessageEventSource? source = null, optional sequence<MessagePort> ports = []);
};

dictionary MessageEventInit : EventInit {
    any data = null;
    USVString origin = "";
    DOMString lastEventId = "";
    MessageEventSource? source = null;
    sequence<MessagePort> ports = [];
};
