src: honor --abort_on_uncaught_exception flag
authorEvan Lucas <evanlucas@me.com>
Wed, 16 Sep 2015 17:44:28 +0000 (12:44 -0500)
committerJeremiah Senkpiel <fishrock123@rocketmail.com>
Sun, 20 Sep 2015 17:30:52 +0000 (10:30 -0700)
Fix regression introduced in 0af4c9ea7434e4f505dbe071357e4bc3b4ab2a8a
that ignores the --abort-on-uncaught-exception flag. Prior to that
commit, the flag was passed through to v8. After that commit, the
process just calls exit(1).

PR-URL: https://github.com/nodejs/node/pull/2776
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
src/node.cc
test/abort/test-abort-uncaught-exception.js [new file with mode: 0644]

index cb32bcb..1673352 100644 (file)
@@ -2192,7 +2192,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 (file)
index 0000000..0d9fa68
--- /dev/null
@@ -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);
+    }
+  }));
+}