From 96009289fb44936a8b612deca3980b28096eac12 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 25 Sep 2023 12:23:58 +0800 Subject: [PATCH] node-api: enable uncaught exceptions policy by default This enables the option `--force-node-api-uncaught-exceptions-policy` for a specific Node-API addon when it is compiled with `NAPI_EXPERIMENTAL` (and this would be the default behavior when `NAPI_VERSION` 10 releases). This would not break existing Node-API addons. PR-URL: https://github.com/nodejs/node/pull/49313 Refs: https://github.com/nodejs/node/pull/36510 Reviewed-By: Michael Dawson Reviewed-By: Gabriel Schulhof --- doc/api/n-api.md | 8 ++ src/node_api.cc | 16 ++-- test/js-native-api/test_reference/binding.gyp | 6 ++ .../test_reference/test_finalizer.c | 71 ++++++++++++++++++ .../test_reference/test_finalizer.js | 4 +- .../test_reference/test_reference.c | 75 +++++-------------- test/node-api/test_buffer/binding.gyp | 4 + test/node-api/test_buffer/test_buffer.c | 50 ++----------- test/node-api/test_buffer/test_finalizer.c | 61 +++++++++++++++ test/node-api/test_buffer/test_finalizer.js | 2 +- .../test_threadsafe_function/binding.gyp | 14 ++++ ...n.js => test_legacy_uncaught_exception.js} | 2 +- .../test_uncaught_exception.c | 62 +++++++++++++++ .../test_uncaught_exception.js | 26 +------ .../test_uncaught_exception_v9.js | 8 ++ .../uncaught_exception.js | 31 ++++++++ 16 files changed, 307 insertions(+), 133 deletions(-) create mode 100644 test/js-native-api/test_reference/test_finalizer.c create mode 100644 test/node-api/test_buffer/test_finalizer.c rename test/node-api/test_threadsafe_function/{test_force_uncaught_exception.js => test_legacy_uncaught_exception.js} (85%) create mode 100644 test/node-api/test_threadsafe_function/test_uncaught_exception.c create mode 100644 test/node-api/test_threadsafe_function/test_uncaught_exception_v9.js create mode 100644 test/node-api/test_threadsafe_function/uncaught_exception.js diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 10b6dac61c4490..feb9fa6061ca4e 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -6245,6 +6245,13 @@ napi_create_threadsafe_function(napi_env env, [`napi_threadsafe_function_call_js`][] provides more details. * `[out] result`: The asynchronous thread-safe JavaScript function. +**Change History:** + +* Experimental (`NAPI_EXPERIMENTAL` is defined): + + Uncaught exceptions thrown in `call_js_cb` are handled with the + [`'uncaughtException'`][] event, instead of being ignored. + ### `napi_get_threadsafe_function_context`