From 2efb8901d559dfa0fb7b7ad82b242197bd2d437f Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 19 Jun 2023 17:34:38 +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. --- doc/api/n-api.md | 8 + src/node_api.cc | 16 +- test/js-native-api/test_reference/binding.gyp | 7 + .../test_reference/test_finalizer.c | 70 +++++++++ .../test_reference/test_finalizer.js | 4 +- .../test_reference/test_reference.c | 141 +++++++----------- 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 | 3 +- .../test_uncaught_exception_v9.js | 27 ++++ 15 files changed, 328 insertions(+), 143 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 diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 8b8f77f9d6a1f8..6fd70c16d0d0bd 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -6244,6 +6244,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` is handled with the + [`'uncaughtException'`][] event, instead of being ignored. + ### `napi_get_threadsafe_function_context`