From 10f9e2e34f6bbb699592e8e0e9d90f106ac0aa34 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 --- 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 c38d227d8d6aff..b29072164f9071 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -439,6 +439,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`