mirror of https://github.com/lukechilds/node.git
Browse Source
- Create a handle scope before invoking the async completion callback, because it is basically always needed, easy for user code to forget, and this makes it more consistent with ordinary N-API function callbacks. - Check for an unhandled JS exception after invoking an async completion callback, and report it via `node::FatalException()`. - Add a corresponding test case for an exception in async callback. Previously, any unhandled JS exception thrown from a `napi_async_complete_callback` would be silently ignored. Among other things this meant assertions in some test cases could be undetected. PR-URL: https://github.com/nodejs/node/pull/12838 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>v6
committed by
Michael Dawson
4 changed files with 38 additions and 27 deletions
@ -1,12 +1,30 @@ |
|||
'use strict'; |
|||
const common = require('../../common'); |
|||
const assert = require('assert'); |
|||
const child_process = require('child_process'); |
|||
const test_async = require(`./build/${common.buildType}/test_async`); |
|||
|
|||
const testException = 'test_async_cb_exception'; |
|||
|
|||
// Exception thrown from async completion callback.
|
|||
// (Tested in a spawned process because the exception is fatal.)
|
|||
if (process.argv[2] === 'child') { |
|||
test_async.Test(1, common.mustCall(function(err, val) { |
|||
throw new Error(testException); |
|||
})); |
|||
return; |
|||
} |
|||
const p = child_process.spawnSync( |
|||
process.execPath, [ '--napi-modules', __filename, 'child' ]); |
|||
assert.ifError(p.error); |
|||
assert.ok(p.stderr.toString().includes(testException)); |
|||
|
|||
// Successful async execution and completion callback.
|
|||
test_async.Test(5, common.mustCall(function(err, val) { |
|||
assert.strictEqual(err, null); |
|||
assert.strictEqual(val, 10); |
|||
process.nextTick(common.mustCall()); |
|||
})); |
|||
|
|||
// Async work item cancellation with callback.
|
|||
test_async.TestCancel(common.mustCall()); |
|||
|
Loading…
Reference in new issue