diff --git a/src/node.cc b/src/node.cc index c139c509a2..1e63009e3b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2180,7 +2180,11 @@ void FatalException(Isolate* isolate, if (false == caught->BooleanValue()) { ReportException(env, error, message); - exit(1); + if (abort_on_uncaught_exception) { + ABORT(); + } else { + exit(1); + } } } diff --git a/test/abort/test-abort-uncaught-exception.js b/test/abort/test-abort-uncaught-exception.js new file mode 100644 index 0000000000..0d9fa6884d --- /dev/null +++ b/test/abort/test-abort-uncaught-exception.js @@ -0,0 +1,31 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const spawn = require('child_process').spawn; +const node = process.execPath; + +if (process.argv[2] === 'child') { + throw new Error('child error'); +} else { + run('', null); + run('--abort-on-uncaught-exception', 'SIGABRT'); +} + +function run(flags, signal) { + const args = [__filename, 'child']; + if (flags) + args.unshift(flags); + + const child = spawn(node, args); + child.on('exit', common.mustCall(function(code, sig) { + if (!common.isWindows) { + assert.strictEqual(sig, signal); + } else { + if (signal) + assert.strictEqual(code, 3); + else + assert.strictEqual(code, 1); + } + })); +}