From a128219a484f74e4e4a5d3db23824fb9b5efb5cd Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Thu, 4 May 2017 15:24:44 -0700 Subject: [PATCH] n-api: Handle fatal exception in async callback - 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. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/12838 Reviewed-By: Anna Henningsen Reviewed-By: Benjamin Gruenbaum Reviewed-By: Michael Dawson Reviewed-By: James M Snell --- doc/api/n-api.md | 7 ------- src/node_api.cc | 21 ++++++++++++++++++++- test/addons-napi/test_async/test.js | 18 ++++++++++++++++++ test/addons-napi/test_async/test_async.cc | 19 ------------------- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index f9e47a7b8d32a0..bc0499e4d09447 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -2855,13 +2855,6 @@ will be invoked with a status value of `napi_cancelled`. The work should not be deleted before the `complete` callback invocation, even when it was cancelled. -**Note:** As mentioned in the section on memory management, if -the code to be run in the callbacks will create N-API values, then -N-API handle scope functions must be used to create/destroy a -`napi_handle_scope` such that the scope is active when -objects can be created. - - ### napi_create_async_work