summaryrefslogtreecommitdiff
path: root/test/parallel/test-domain-thrown-error-handler-stack.js
blob: 564fd8a5d707008c156241be05f1157d2702c14f (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';

const common = require('../common');
const domain = require('domain');

/*
 * Make sure that when an erorr is thrown from a nested domain, its error
 * handler runs outside of that domain, but within the context of any parent
 * domain.
 */

const d = domain.create();
const d2 = domain.create();

d2.on('error', common.mustCall((err) => {
  if (domain._stack.length !== 1) {
    console.error('domains stack length should be 1 but is %d',
                  domain._stack.length);
    process.exit(1);
  }

  if (process.domain !== d) {
    console.error('active domain should be %j but is %j', d, process.domain);
    process.exit(1);
  }

  process.nextTick(() => {
    if (domain._stack.length !== 1) {
      console.error('domains stack length should be 1 but is %d',
                    domain._stack.length);
      process.exit(1);
    }

    if (process.domain !== d) {
      console.error('active domain should be %j but is %j', d,
                    process.domain);
      process.exit(1);
    }
  });
}));

d.run(() => {
  d2.run(() => {
    throw new Error('oops');
  });
});