node/test/parallel/test-domain-stack-empty-in-process-uncaughtexception.js
Julien Gilli 90204cc468 domains: clear stack when no error handler
Clear domains stack __even if no domain error handler is set__ so that
code running in the process' uncaughtException handler, or any code that
may be executed when an error is thrown and not caught and that is not
the domain's error handler, doesn't run in the context of the domain
within which the error was thrown.

PR: #4659
PR-URL: https://github.com/nodejs/node/pull/4659
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-01-13 10:55:15 -08:00

23 lines
552 B
JavaScript

'use strict';
const common = require('../common');
const domain = require('domain');
const assert = require('assert');
const d = domain.create();
process.on('uncaughtException', common.mustCall(function onUncaught() {
assert.equal(process.domain, null,
'domains stack should be empty in uncaughtException handler');
}));
process.on('beforeExit', common.mustCall(function onBeforeExit() {
assert.equal(process.domain, null,
'domains stack should be empty in beforeExit handler');
}));
d.run(function() {
throw new Error('boom');
});