node/test/parallel/test-domain-thrown-error-handler-stack.js
Rich Trott f593f9e9ef test: adjust comments for upcoming lint rule
Enforce `//` for multiline comments. Some tests mixed and matched, and
at least one did so in a (to me) surprising way.

PR-URL: https://github.com/nodejs/node/pull/35485
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-10-07 04:36:02 -07:00

45 lines
1.1 KiB
JavaScript

'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');
});
});