1'use strict'; 2const { 3 SymbolFor, 4} = primordials; 5 6class MessageEvent { 7 constructor(data, target, type) { 8 this.data = data; 9 this.target = target; 10 this.type = type; 11 } 12} 13 14const kHybridDispatch = SymbolFor('nodejs.internal.kHybridDispatch'); 15 16exports.emitMessage = function(data, type) { 17 if (typeof this[kHybridDispatch] === 'function') { 18 this[kHybridDispatch](data, type, undefined); 19 return; 20 } 21 22 const event = new MessageEvent(data, this, type); 23 if (type === 'message') { 24 if (typeof this.onmessage === 'function') 25 this.onmessage(event); 26 } else { 27 // eslint-disable-next-line no-lonely-if 28 if (typeof this.onmessageerror === 'function') 29 this.onmessageerror(event); 30 } 31}; 32