summaryrefslogtreecommitdiff
path: root/test/parallel/test-event-emitter-emit-context.js
blob: e4c73cadc559ba6ab58f3ff2fe4b52f32e71083d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'use strict';
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events');

// Test emit called by other context
const EE = new EventEmitter();

// Works as expected if the context has no `constructor.name`
{
  const ctx = { __proto__: null };
  assert.throws(
    () => EE.emit.call(ctx, 'error', new Error('foo')),
    common.expectsError({ name: 'Error', message: 'foo' })
  );
}

assert.strictEqual(EE.emit.call({}, 'foo'), false);