• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const domain = require('domain');
6const EventEmitter = require('events');
7
8const d = new domain.Domain();
9let implicit;
10
11d.on('error', common.mustCall((err) => {
12  assert.strictEqual(err.message, 'foobar');
13  assert.strictEqual(err.domain, d);
14  assert.strictEqual(err.domainEmitter, implicit);
15  assert.strictEqual(err.domainBound, undefined);
16  assert.strictEqual(err.domainThrown, false);
17}));
18
19// Implicit addition of the EventEmitter by being created within a domain-bound
20// context.
21d.run(common.mustCall(() => {
22  implicit = new EventEmitter();
23}));
24
25setTimeout(common.mustCall(() => {
26  // Escape from the domain, but implicit is still bound to it.
27  implicit.emit('error', new Error('foobar'));
28}), 1);
29