diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 11a696cc2329a3..e2054031014680 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -193,7 +193,7 @@ Local AsyncWrap::MakeCallback(const Local cb, if (has_domain) { domain = domain_v.As(); if (domain->Get(env()->disposed_string())->IsTrue()) - return Undefined(env()->isolate()); + return Local(); } } @@ -220,7 +220,7 @@ Local AsyncWrap::MakeCallback(const Local cb, } if (ret.IsEmpty()) { - return Undefined(env()->isolate()); + return ret; } if (has_domain) { @@ -249,7 +249,7 @@ Local AsyncWrap::MakeCallback(const Local cb, } if (env()->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) { - return Undefined(env()->isolate()); + return Local(); } return ret; diff --git a/src/node.cc b/src/node.cc index 5b4b2f8c8affa0..056b3711f0c8da 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1177,7 +1177,11 @@ Local MakeCallback(Environment* env, } if (ret.IsEmpty()) { - return Undefined(env->isolate()); + if (callback_scope.in_makecallback()) + return ret; + // NOTE: Undefined() is returned here for backwards compatibility. + else + return Undefined(env->isolate()); } if (has_domain) { diff --git a/test/parallel/test-http-catch-uncaughtexception.js b/test/parallel/test-http-catch-uncaughtexception.js new file mode 100644 index 00000000000000..c4054aafbfb699 --- /dev/null +++ b/test/parallel/test-http-catch-uncaughtexception.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const http = require('http'); + +const uncaughtCallback = common.mustCall(function(er) { + assert.equal(er.message, 'get did fail'); +}); + +process.on('uncaughtException', uncaughtCallback); + +const server = http.createServer(function(req, res) { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('bye'); +}).listen(common.PORT, function() { + http.get({ port: common.PORT }, function(res) { + res.resume(); + throw new Error('get did fail'); + }).on('close', function() { + server.close(); + }); +});