-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #5756 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
- Loading branch information
1 parent
a485612
commit 6f16882
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!'); | ||
}); |