From 8f8dcf8ed63b19a6c20915e12af83a3ad792f1d2 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 30 Jun 2010 15:03:45 -0700 Subject: [PATCH] Fix 'uncaughtException' for top level exceptions Done by not evaluating the code in the first tick. This breaks one test in test-error-reporting.js but I believe this to be a V8 error and I have reported it in http://code.google.com/p/v8/issues/detail?id=764 --- lib/module.js | 6 ++++-- src/node.cc | 5 ++--- src/node.js | 2 +- test/simple/test-error-reporting.js | 8 ++++---- test/simple/test-uncaught-exception.js | 13 +++++++++++++ 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 test/simple/test-uncaught-exception.js diff --git a/lib/module.js b/lib/module.js index b9067d2..1a1b01b 100644 --- a/lib/module.js +++ b/lib/module.js @@ -437,9 +437,11 @@ Module.prototype._waitChildrenLoad = function (callback) { // bootstrap main module. -exports.runMain = function () { +exports.runMain = function (filename) { // Load the main module--the command line argument. process.mainModule = new Module("."); - process.mainModule.loadSync(process.argv[1]); + process.mainModule.load(filename, function (err) { + if (err) throw err; + }); } diff --git a/src/node.cc b/src/node.cc index 5aa3712..f1e47ef 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1805,9 +1805,8 @@ static void Load(int argc, char *argv[]) { f->Call(global, 1, args); - if (try_catch.HasCaught()) { - ReportException(try_catch, true); - exit(11); + if (try_catch.HasCaught()) { + FatalException(try_catch); } } diff --git a/src/node.js b/src/node.js index 97b1f1b..b3dc069 100644 --- a/src/node.js +++ b/src/node.js @@ -239,7 +239,7 @@ if (process.argv[1]) { process.argv[1] = path.join(cwd, process.argv[1]); } - module.runMain(); + module.runMain(process.argv[1]); } else { // No arguments, run the repl var repl = module.requireNative('repl'); diff --git a/test/simple/test-error-reporting.js b/test/simple/test-error-reporting.js index 46c8982..c283e7b 100644 --- a/test/simple/test-error-reporting.js +++ b/test/simple/test-error-reporting.js @@ -33,14 +33,14 @@ errExec('throws_error.js', function (err, stdout, stderr) { }); -// Trying to JSON.parse(undefined) -errExec('throws_error2.js', function (err, stdout, stderr) { +// Trying to JSON.parse(undefined) in nextTick +errExec('throws_error3.js', function (err, stdout, stderr) { assert.ok(/JSON/.test(stderr)); }); -// Trying to JSON.parse(undefined) in nextTick -errExec('throws_error3.js', function (err, stdout, stderr) { +// Trying to JSON.parse(undefined) +errExec('throws_error2.js', function (err, stdout, stderr) { assert.ok(/JSON/.test(stderr)); }); diff --git a/test/simple/test-uncaught-exception.js b/test/simple/test-uncaught-exception.js new file mode 100644 index 0000000..739d994 --- /dev/null +++ b/test/simple/test-uncaught-exception.js @@ -0,0 +1,13 @@ +require('../common') + +process.addListener('uncaughtException', function (err) { + puts('Caught exception: ' + err); +}); + +setTimeout(function () { + puts('This will still run.'); +}, 500); + +// Intentionally cause an exception, but don't catch it. +nonexistentFunc(); +puts('This will not run.'); -- 2.7.4