summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2016-02-22 22:50:56 -0700
committerTrevor Norris <trev.norris@gmail.com>2016-03-28 11:32:44 -0600
commit20337addd6ad134f61684708754be691a3f2ec98 (patch)
treeba76d58a7d484e62e1144958d532a26de84dfd4f /test
parentf9938b61418a448a8ef835c1016233e41ed5948e (diff)
downloadnode-new-20337addd6ad134f61684708754be691a3f2ec98.tar.gz
async_wrap: notify post if intercepted exception
The second argument of the post callback is a boolean indicating whether the callback threw and was intercepted by uncaughtException or a domain. Currently node::MakeCallback has no way of retrieving a uid for the object. This is coming in a future patch. PR-URL: https://github.com/nodejs/node/pull/5756 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-async-wrap-post-did-throw.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/parallel/test-async-wrap-post-did-throw.js b/test/parallel/test-async-wrap-post-did-throw.js
new file mode 100644
index 0000000000..9781983f58
--- /dev/null
+++ b/test/parallel/test-async-wrap-post-did-throw.js
@@ -0,0 +1,34 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+const async_wrap = process.binding('async_wrap');
+var asyncThrows = 0;
+var uncaughtExceptionCount = 0;
+
+process.on('uncaughtException', (e) => {
+ assert.equal(e.message, 'oh noes!', 'error messages do not match');
+});
+
+process.on('exit', () => {
+ process.removeAllListeners('uncaughtException');
+ assert.equal(uncaughtExceptionCount, 1);
+ assert.equal(uncaughtExceptionCount, asyncThrows);
+});
+
+function init() { }
+function post(id, threw) {
+ if (threw)
+ uncaughtExceptionCount++;
+}
+
+async_wrap.setupHooks({ init, post });
+async_wrap.enable();
+
+// Timers still aren't supported, so use crypto API.
+// It's also important that the callback not happen in a nextTick, like many
+// error events in core.
+require('crypto').randomBytes(0, () => {
+ asyncThrows++;
+ throw new Error('oh noes!');
+});