From 4a0cc800939d69e3fee412dc28c0dd6166bc3d9f Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 14 Dec 2020 19:10:51 +0800 Subject: [PATCH] node-api: emit uncaught-exception on unhandled tsfn callbacks PR-URL: https://github.com/nodejs/node/pull/36510 Fixes: https://github.com/nodejs/node/issues/36402 Reviewed-By: Michael Dawson Reviewed-By: James M Snell --- doc/api/cli.md | 13 +++ src/js_native_api_v8.h | 22 ++-- src/node_api.cc | 101 +++++++++++------- src/node_api_internals.h | 8 ++ src/node_options.cc | 6 ++ src/node_options.h | 1 + .../test_reference/test_finalizer.js | 20 ++++ .../test_reference/test_reference.c | 43 +++++++- test/node-api/test_buffer/test_buffer.c | 36 +++++++ test/node-api/test_buffer/test_finalizer.js | 21 ++++ .../test_threadsafe_function/binding.c | 30 ++++++ .../test_force_uncaught_exception.js | 22 ++++ .../test_uncaught_exception.js | 27 +++++ 13 files changed, 304 insertions(+), 46 deletions(-) create mode 100644 test/js-native-api/test_reference/test_finalizer.js create mode 100644 test/node-api/test_buffer/test_finalizer.js create mode 100644 test/node-api/test_threadsafe_function/test_force_uncaught_exception.js create mode 100644 test/node-api/test_threadsafe_function/test_uncaught_exception.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 69555cf153200b..e844881b1899f9 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -419,6 +419,18 @@ under this flag. To allow polyfills to be added, `--require` runs before freezing intrinsics. +### `--force-node-api-uncaught-exceptions-policy` + + + +Enforces `uncaughtException` event on Node-API asynchronous callbacks. + +To prevent from an existing add-on from crashing the process, this flag is not +enabled by default. In the future, this flag will be enabled by default to +enforce the correct behavior. + ### `--heapsnapshot-near-heap-limit=max_count`