UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

37 lines (32 loc) 1.09 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/per_context/messageport.js class MessageEvent { constructor(data, target, type, ports) { this.data = data; this.target = target; this.type = type; this.ports = ports ?? []; } } const kHybridDispatch = Symbol.for("nodejs.internal.kHybridDispatch"); const kCurrentlyReceivingPorts = Symbol.for( "nodejs.internal.kCurrentlyReceivingPorts", ); const _export_emitMessage_ = function (data, ports, type) { if (typeof this[kHybridDispatch] === "function") { this[kCurrentlyReceivingPorts] = ports; try { this[kHybridDispatch](data, type, undefined); } finally { this[kCurrentlyReceivingPorts] = undefined; } return; } const event = new MessageEvent(data, this, type, ports); if (type === "message") { if (typeof this.onmessage === "function") this.onmessage(event); } else { // eslint-disable-next-line no-lonely-if if (typeof this.onmessageerror === "function") this.onmessageerror(event); } }; export { _export_emitMessage_ as emitMessage };