All files / lib/internal/per_context messageport.js

100% Statements 31/31
100% Branches 8/8
100% Functions 2/2
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 323x 3x 3x 3x 3x 3x 3x 6x 6x 6x 6x 3x 3x 3x 3x 3x 43986x 43980x 43980x 43980x 6x 6x 6x 2x 2x 5x 4x 4x 4x 4x 3x  
'use strict';
const {
  SymbolFor,
} = primordials;
 
class MessageEvent {
  constructor(data, target, type) {
    this.data = data;
    this.target = target;
    this.type = type;
  }
}
 
const kHybridDispatch = SymbolFor('nodejs.internal.kHybridDispatch');
 
exports.emitMessage = function(data, type) {
  if (typeof this[kHybridDispatch] === 'function') {
    this[kHybridDispatch](data, type, undefined);
    return;
  }
 
  const event = new MessageEvent(data, this, type);
  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);
  }
};