From cc2b8df405abeceb4cb4d29ba09b784a680352ed Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 13 Nov 2024 04:37:46 +0800 Subject: [PATCH 1/8] chore: upgrade devdependencies (#1613) --- .eslintrc.js | 6 ------ eslint.config.js | 5 +++++ package.json | 10 ++-------- test/buffer.js | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 eslint.config.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index edc9cc529..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - parserOptions: { - sourceType: 'script' - }, - extends: ['semistandard'] -}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..d02c6f529 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = require('neostandard')({ + semi: true, +}); diff --git a/package.json b/package.json index b9430b30c..19cb08633 100644 --- a/package.json +++ b/package.json @@ -421,16 +421,10 @@ "benchmark": "^2.1.4", "bindings": "^1.5.0", "clang-format": "^1.4.0", - "eslint": "^7.32.0", - "eslint-config-semistandard": "^16.0.0", - "eslint-config-standard": "^16.0.3", - "eslint-plugin-import": "^2.24.2", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.0", + "eslint": "^9.13.0", "fs-extra": "^11.1.1", - "path": "^0.12.7", + "neostandard": "^0.11.7", "pre-commit": "^1.2.2", - "safe-buffer": "^5.1.1", "semver": "^7.6.0" }, "directories": {}, diff --git a/test/buffer.js b/test/buffer.js index 8b190b79f..3f49201a7 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -2,7 +2,6 @@ const assert = require('assert'); const testUtil = require('./testUtil'); -const safeBuffer = require('safe-buffer'); module.exports = require('./common').runTest(test); @@ -14,7 +13,7 @@ function test (binding) { binding.buffer.checkBuffer(test); assert.ok(test instanceof Buffer); - const test2 = safeBuffer.Buffer.alloc(test.length); + const test2 = Buffer.alloc(test.length); test.copy(test2); binding.buffer.checkBuffer(test2); }, From 504133b2e872c99f31cd7dc37fbd08a60893f7bc Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Sat, 16 Nov 2024 00:29:02 +0800 Subject: [PATCH 2/8] chore: use eslint directly (#1616) --- package.json | 4 +- test/array_buffer.js | 2 +- test/async_context.js | 4 +- test/async_progress_queue_worker.js | 6 +-- test/async_progress_worker.js | 6 +-- test/async_worker.js | 10 ++-- test/function.js | 2 +- test/function_reference.js | 4 +- test/type_taggable.js | 7 ++- tools/eslint-format.js | 79 ----------------------------- 10 files changed, 22 insertions(+), 102 deletions(-) delete mode 100644 tools/eslint-format.js diff --git a/package.json b/package.json index 19cb08633..3bd157cd7 100644 --- a/package.json +++ b/package.json @@ -468,8 +468,8 @@ "predev:incremental": "node-gyp configure build -C test --debug", "dev:incremental": "node test", "doc": "doxygen doc/Doxyfile", - "lint": "node tools/eslint-format && node tools/clang-format", - "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix" + "lint": "eslint && node tools/clang-format", + "lint:fix": "eslint --fix && node tools/clang-format --fix" }, "pre-commit": "lint", "version": "8.2.2", diff --git a/test/array_buffer.js b/test/array_buffer.js index d6853e50d..08547ed7e 100644 --- a/test/array_buffer.js +++ b/test/array_buffer.js @@ -58,7 +58,7 @@ function test (binding) { 'ArrayBuffer updates data pointer and length when detached', () => { // Detach the ArrayBuffer in JavaScript. - // eslint-disable-next-line no-undef + const mem = new WebAssembly.Memory({ initial: 1 }); binding.arraybuffer.checkDetachUpdatesData(mem.buffer, () => mem.grow(1)); diff --git a/test/async_context.js b/test/async_context.js index 6a4bef662..6cf0418f6 100644 --- a/test/async_context.js +++ b/test/async_context.js @@ -73,7 +73,7 @@ async function makeCallbackWithResource (binding) { { eventName: 'init', type: 'async_context_test', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -95,7 +95,7 @@ async function makeCallbackWithoutResource (binding) { { eventName: 'init', type: 'async_context_no_res_test', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { } }, { eventName: 'before' }, diff --git a/test/async_progress_queue_worker.js b/test/async_progress_queue_worker.js index 3f031a415..b72a55c71 100644 --- a/test/async_progress_queue_worker.js +++ b/test/async_progress_queue_worker.js @@ -42,7 +42,7 @@ async function asyncProgressWorkerCallbackOverloads (bindingFunction) { { eventName: 'init', type: 'cbResources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -90,7 +90,7 @@ async function asyncProgressWorkerRecvOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, @@ -131,7 +131,7 @@ async function asyncProgressWorkerNoCbOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, diff --git a/test/async_progress_worker.js b/test/async_progress_worker.js index 78ba7b63d..d96ab64b8 100644 --- a/test/async_progress_worker.js +++ b/test/async_progress_worker.js @@ -44,7 +44,7 @@ async function asyncProgressWorkerCallbackOverloads (bindingFunction) { { eventName: 'init', type: 'cbResources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -92,7 +92,7 @@ async function asyncProgressWorkerRecvOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, @@ -133,7 +133,7 @@ async function asyncProgressWorkerNoCbOverloads (bindingFunction) { { eventName: 'init', type: asyncResName, - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: asyncResObject }, { eventName: 'before' }, diff --git a/test/async_worker.js b/test/async_worker.js index 304a3247f..16e2a8e96 100644 --- a/test/async_worker.js +++ b/test/async_worker.js @@ -139,7 +139,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'fooBar' } }, { eventName: 'before' }, @@ -167,7 +167,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { } }, { eventName: 'before' }, @@ -194,7 +194,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -224,7 +224,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, @@ -252,7 +252,7 @@ async function test (binding) { { eventName: 'init', type: 'TestResource', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: { foo: 'foo' } }, { eventName: 'before' }, diff --git a/test/function.js b/test/function.js index 7cd8c04e2..c5514db36 100644 --- a/test/function.js +++ b/test/function.js @@ -18,7 +18,7 @@ function test (binding) { assert.deepStrictEqual(binding.valueCallback(), { foo: 'bar' }); - /* eslint-disable-next-line no-new, new-cap */ + /* eslint-disable-next-line new-cap */ assert.strictEqual(new binding.newTargetCallback(), binding.newTargetCallback); assert.strictEqual(binding.newTargetCallback(), undefined); diff --git a/test/function_reference.js b/test/function_reference.js index 84263fce9..e69fc8e5b 100644 --- a/test/function_reference.js +++ b/test/function_reference.js @@ -95,7 +95,7 @@ async function canCallAsyncFunctionWithDifferentOverloads (binding) { { eventName: 'init', type: 'func_ref_resources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, @@ -113,7 +113,7 @@ async function canCallAsyncFunctionWithDifferentOverloads (binding) { { eventName: 'init', type: 'func_ref_resources', - triggerAsyncId: triggerAsyncId, + triggerAsyncId, resource: {} }, { eventName: 'before' }, diff --git a/test/type_taggable.js b/test/type_taggable.js index 263befa9d..7bc843cf6 100644 --- a/test/type_taggable.js +++ b/test/type_taggable.js @@ -53,8 +53,7 @@ function testTypeTaggable ({ typeTaggedInstance, checkTypeTag }) { assert.strictEqual(checkTypeTag(4, obj3), false); } -// eslint-disable-next-line camelcase -function test ({ type_taggable }) { - testTypeTaggable(type_taggable.external); - testTypeTaggable(type_taggable.object); +function test (binding) { + testTypeTaggable(binding.type_taggable.external); + testTypeTaggable(binding.type_taggable.object); } diff --git a/tools/eslint-format.js b/tools/eslint-format.js deleted file mode 100644 index 6923ab7b6..000000000 --- a/tools/eslint-format.js +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env node - -const spawn = require('child_process').spawnSync; - -const filesToCheck = '*.js'; -const FORMAT_START = process.env.FORMAT_START || 'main'; -const IS_WIN = process.platform === 'win32'; -const ESLINT_PATH = IS_WIN ? 'node_modules\\.bin\\eslint.cmd' : 'node_modules/.bin/eslint'; - -function main (args) { - let fix = false; - while (args.length > 0) { - switch (args[0]) { - case '-f': - case '--fix': - fix = true; - break; - default: - } - args.shift(); - } - - // Check js files that change on unstaged file - const fileUnStaged = spawn( - 'git', - ['diff', '--name-only', '--diff-filter=d', FORMAT_START, filesToCheck], - { - encoding: 'utf-8' - } - ); - - // Check js files that change on staged file - const fileStaged = spawn( - 'git', - ['diff', '--name-only', '--cached', '--diff-filter=d', FORMAT_START, filesToCheck], - { - encoding: 'utf-8' - } - ); - - const options = [ - ...fileStaged.stdout.split('\n').filter((f) => f !== ''), - ...fileUnStaged.stdout.split('\n').filter((f) => f !== '') - ]; - - if (fix) { - options.push('--fix'); - } - - const result = spawn(ESLINT_PATH, [...options], { - encoding: 'utf-8' - }); - - if (result.error && result.error.errno === 'ENOENT') { - console.error('Eslint not found! Eslint is supposed to be found at ', ESLINT_PATH); - return 2; - } - - if (result.status === 1) { - console.error('Eslint error:', result.stdout); - const fixCmd = 'npm run lint:fix'; - console.error(`ERROR: please run "${fixCmd}" to format changes in your commit - Note that when running the command locally, please keep your local - main branch and working branch up to date with nodejs/node-addon-api - to exclude un-related complains. - Or you can run "env FORMAT_START=upstream/main ${fixCmd}". - Also fix JS files by yourself if necessary.`); - return 1; - } - - if (result.stderr) { - console.error('Error running eslint:', result.stderr); - return 2; - } -} - -if (require.main === module) { - process.exitCode = main(process.argv.slice(2)); -} From 0776de2d2870bfd987f5ad0739c67387501d5794 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:46:26 -0500 Subject: [PATCH 3/8] chore(deps): bump github/codeql-action in the all group (#1614) Bumps the all group with 1 update: [github/codeql-action](https://github.com/github/codeql-action). Updates `github/codeql-action` from 3.27.0 to 3.27.1 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/662472033e021d55d94146f66f6058822b0b39fd...4f3212b61783c3c68e8309a0f18a699764811cda) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/scorecards.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0e4023e84..12484121e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -50,7 +50,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + uses: github/codeql-action/init@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -80,6 +80,6 @@ jobs: npx node-gyp rebuild -C test - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + uses: github/codeql-action/analyze@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 29c1e8ce1..9013e3336 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -71,6 +71,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0 + uses: github/codeql-action/upload-sarif@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 with: sarif_file: results.sarif From c679f6f4c9dc6bf9fc0d99cbe5982bd24a5e2c7b Mon Sep 17 00:00:00 2001 From: Kevin Eady <8634912+KevinEady@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:16:37 +0100 Subject: [PATCH 4/8] feat: allow catching all exceptions (#1593) * feat: allow catching all exceptions * Address review comments --- doc/cmake-js.md | 19 ++++++ doc/error_handling.md | 12 ++++ doc/setup.md | 14 ++++- napi-inl.h | 143 +++++++++++++++++++++++++++--------------- napi.h | 71 +++++++++++++-------- node_addon_api.gyp | 10 +++ noexcept.gypi | 2 +- test/binding.gyp | 8 +++ test/except_all.cc | 21 +++++++ test/except_all.js | 14 +++++ 10 files changed, 237 insertions(+), 77 deletions(-) create mode 100644 test/except_all.cc create mode 100644 test/except_all.js diff --git a/doc/cmake-js.md b/doc/cmake-js.md index 85bdf9412..9b79a4a00 100644 --- a/doc/cmake-js.md +++ b/doc/cmake-js.md @@ -45,6 +45,25 @@ The following line in the `CMakeLists.txt` file will enable Node-API experimenta add_definitions(-DNAPI_EXPERIMENTAL) ``` +### Exception Handling + +To enable C++ exception handling (for more info see: [Setup](setup.md)), define +the corresponding preprocessor directives depending on which exception handling +behavior is desired. + +To enable C++ exception handling with `Napi::Error` objects only: + +``` +add_definitions(-DNAPI_EXPERIMENTAL) +``` + +To enable C++ exception handling for all exceptions thrown: + +``` +add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS) +add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS_ALL) +``` + ### node-addon-api If your Node-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#node-api-and-node-addon-api). diff --git a/doc/error_handling.md b/doc/error_handling.md index 5bb7481aa..b4b4ca238 100644 --- a/doc/error_handling.md +++ b/doc/error_handling.md @@ -48,6 +48,18 @@ method. If a C++ exception of type `Napi::Error` escapes from a Node-API C++ callback, then the Node-API wrapper automatically converts and throws it as a JavaScript exception. +If other types of C++ exceptions are thrown, node-addon-api will either abort +the process or wrap the exception in an `Napi::Error` in order to throw it as a +JavaScript exception. This behavior is determined by which node-gyp dependency +used: + +- When using the `node_addon_api_except` dependency, only `Napi::Error` objects + will be handled. +- When using the `node_addon_api_except_all` dependency, all exceptions will be +handled. For exceptions derived from `std::exception`, an `Napi::Error` will be +created with the message of the exception's `what()` member function. For all +other exceptions, an `Napi::Error` will be created with a generic error message. + On return from a native method, node-addon-api will automatically convert a pending `Napi::Error` C++ exception to a JavaScript exception. diff --git a/doc/setup.md b/doc/setup.md index 86a1b0f38..b3b7effc6 100644 --- a/doc/setup.md +++ b/doc/setup.md @@ -38,7 +38,10 @@ To use **Node-API** in a native module: ], ``` - To enable that capability, add an alternative dependency in `binding.gyp`: + To enable that capability, add an alternative dependency in `binding.gyp` + depending on if you want to integrate C++ exception handling for exceptions + derived from `Napi::Error` or all C++ exceptions. To catch only + `Napi::Error` exceptions, use: ```gyp 'dependencies': [ @@ -46,6 +49,15 @@ To use **Node-API** in a native module: ], ``` + Or, to allow catching all native C++ exceptions, use the + `node_addon_api_except_all` dependency: + + ```gyp + 'dependencies': [ + " -inline napi_value WrapCallback(Callable callback) { -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL +inline napi_value WrapCallback(napi_env env, Callable callback) { +#else +inline napi_value WrapCallback(napi_env, Callable callback) { +#endif +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS try { return callback(); } catch (const Error& e) { e.ThrowAsJavaScriptException(); return nullptr; } -#else // NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL + catch (const std::exception& e) { + Napi::Error::New(env, e.what()).ThrowAsJavaScriptException(); + return nullptr; + } catch (...) { + Napi::Error::New(env, "A native exception was thrown") + .ThrowAsJavaScriptException(); + return nullptr; + } +#endif // NODE_ADDON_API_CPP_EXCEPTIONS_ALL +#else // NODE_ADDON_API_CPP_EXCEPTIONS // When C++ exceptions are disabled, errors are immediately thrown as JS // exceptions, so there is no need to catch and rethrow them here. return callback(); -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS } // For use in JS to C++ void callback wrappers to catch any Napi::Error @@ -99,7 +113,7 @@ inline napi_value WrapCallback(Callable callback) { // the callback. template inline void WrapVoidCallback(Callable callback) { -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS try { callback(); } catch (const Error& e) { @@ -112,10 +126,41 @@ inline void WrapVoidCallback(Callable callback) { #endif // NAPI_CPP_EXCEPTIONS } +// For use in JS to C++ void callback wrappers to catch _any_ thrown exception +// and rethrow them as JavaScript exceptions before returning from the callback, +// wrapping in an Napi::Error as needed. +template +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL +inline void WrapVoidCallback(napi_env env, Callable callback) { +#else +inline void WrapVoidCallback(napi_env, Callable callback) { +#endif +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS + try { + callback(); + } catch (const Error& e) { + e.ThrowAsJavaScriptException(); + } +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS_ALL + catch (const std::exception& e) { + Napi::Error::New(env, e.what()).ThrowAsJavaScriptException(); + } catch (...) { + Napi::Error::New(env, "A native exception was thrown") + .ThrowAsJavaScriptException(); + } +#endif // NODE_ADDON_API_CPP_EXCEPTIONS_ALL +#else + // When C++ exceptions are disabled, there is no need to catch and rethrow C++ + // exceptions. JS errors should be thrown with + // `Error::ThrowAsJavaScriptException`. + callback(); +#endif // NODE_ADDON_API_CPP_EXCEPTIONS +} + template struct CallbackData { static inline napi_value Wrapper(napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); CallbackData* callbackData = static_cast(callbackInfo.Data()); @@ -131,7 +176,7 @@ struct CallbackData { template struct CallbackData { static inline napi_value Wrapper(napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); CallbackData* callbackData = static_cast(callbackInfo.Data()); @@ -148,7 +193,7 @@ struct CallbackData { template napi_value TemplatedVoidCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo cbInfo(env, info); Callback(cbInfo); return nullptr; @@ -158,7 +203,7 @@ napi_value TemplatedVoidCallback(napi_env env, template napi_value TemplatedCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo cbInfo(env, info); // MSVC requires to copy 'Callback' function pointer to a local variable // before invoking it. @@ -171,7 +216,7 @@ template napi_value TemplatedInstanceCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo cbInfo(env, info); T* instance = T::Unwrap(cbInfo.This().As()); return instance ? (instance->*UnwrapCallback)(cbInfo) : Napi::Value(); @@ -181,7 +226,7 @@ napi_value TemplatedInstanceCallback(napi_env env, template napi_value TemplatedInstanceVoidCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo cbInfo(env, info); T* instance = T::Unwrap(cbInfo.This().As()); if (instance) (instance->*UnwrapCallback)(cbInfo); @@ -264,7 +309,7 @@ struct FinalizeData { static inline void WrapperGCWithoutData(napi_env env, void* /*data*/, void* finalizeHint) NAPI_NOEXCEPT { - WrapVoidCallback([&] { + WrapVoidCallback(env, [&] { FinalizeData* finalizeData = static_cast(finalizeHint); finalizeData->callback(env); delete finalizeData; @@ -274,7 +319,7 @@ struct FinalizeData { static inline void WrapperGC(napi_env env, void* data, void* finalizeHint) NAPI_NOEXCEPT { - WrapVoidCallback([&] { + WrapVoidCallback(env, [&] { FinalizeData* finalizeData = static_cast(finalizeHint); finalizeData->callback(env, static_cast(data)); delete finalizeData; @@ -284,7 +329,7 @@ struct FinalizeData { static inline void WrapperGCWithHint(napi_env env, void* data, void* finalizeHint) NAPI_NOEXCEPT { - WrapVoidCallback([&] { + WrapVoidCallback(env, [&] { FinalizeData* finalizeData = static_cast(finalizeHint); finalizeData->callback(env, static_cast(data), finalizeData->hint); delete finalizeData; @@ -351,7 +396,7 @@ struct ThreadSafeFinalize { template inline typename std::enable_if(nullptr)>::type CallJsWrapper(napi_env env, napi_value jsCallback, void* context, void* data) { - details::WrapVoidCallback([&]() { + details::WrapVoidCallback(env, [&]() { call(env, Function(env, jsCallback), static_cast(context), @@ -365,7 +410,7 @@ CallJsWrapper(napi_env env, napi_value jsCallback, void* /*context*/, void* /*data*/) { - details::WrapVoidCallback([&]() { + details::WrapVoidCallback(env, [&]() { if (jsCallback != nullptr) { Function(env, jsCallback).Call(0, nullptr); } @@ -399,7 +444,7 @@ template struct AccessorCallbackData { static inline napi_value GetterWrapper(napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); AccessorCallbackData* callbackData = static_cast(callbackInfo.Data()); @@ -410,7 +455,7 @@ struct AccessorCallbackData { static inline napi_value SetterWrapper(napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); AccessorCallbackData* callbackData = static_cast(callbackInfo.Data()); @@ -501,7 +546,7 @@ class HasBasicFinalizer { inline napi_value RegisterModule(napi_env env, napi_value exports, ModuleRegisterCallback registerCallback) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { return napi_value( registerCallback(Napi::Env(env), Napi::Object(env, exports))); }); @@ -1808,7 +1853,7 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, } } -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS inline Object::const_iterator::const_iterator(const Object* object, const Type type) { _object = object; @@ -1883,7 +1928,7 @@ Object::iterator::operator*() { PropertyLValue value = (*_object)[key]; return {key, value}; } -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS #if NAPI_VERSION >= 8 inline MaybeOrValue Object::Freeze() const { @@ -3159,14 +3204,14 @@ inline Error& Error::operator=(const Error& other) { inline const std::string& Error::Message() const NAPI_NOEXCEPT { if (_message.size() == 0 && _env != nullptr) { -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS try { _message = Get("message").As(); } catch (...) { // Catch all errors here, to include e.g. a std::bad_alloc from // the std::string::operator=, because this method may not throw. } -#else // NAPI_CPP_EXCEPTIONS +#else // NODE_ADDON_API_CPP_EXCEPTIONS #if defined(NODE_ADDON_API_ENABLE_MAYBE) Napi::Value message_val; if (Get("message").UnwrapTo(&message_val)) { @@ -3175,7 +3220,7 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT { #else _message = Get("message").As(); #endif -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS } return _message; } @@ -3222,24 +3267,24 @@ inline void Error::ThrowAsJavaScriptException() const { napi_status status = napi_throw(_env, Value()); #endif -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS if (status != napi_ok) { throw Error::New(_env); } -#else // NAPI_CPP_EXCEPTIONS +#else // NODE_ADDON_API_CPP_EXCEPTIONS NAPI_FATAL_IF_FAILED( status, "Error::ThrowAsJavaScriptException", "napi_throw"); -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS } } -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS inline const char* Error::what() const NAPI_NOEXCEPT { return Message().c_str(); } -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT { return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal"; @@ -4508,7 +4553,7 @@ inline ClassPropertyDescriptor InstanceWrap::InstanceValue( template inline napi_value InstanceWrap::InstanceVoidMethodCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); InstanceVoidMethodCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -4523,7 +4568,7 @@ inline napi_value InstanceWrap::InstanceVoidMethodCallbackWrapper( template inline napi_value InstanceWrap::InstanceMethodCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); InstanceMethodCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -4537,7 +4582,7 @@ inline napi_value InstanceWrap::InstanceMethodCallbackWrapper( template inline napi_value InstanceWrap::InstanceGetterCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); InstanceAccessorCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -4551,7 +4596,7 @@ inline napi_value InstanceWrap::InstanceGetterCallbackWrapper( template inline napi_value InstanceWrap::InstanceSetterCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); InstanceAccessorCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -4567,7 +4612,7 @@ template template ::InstanceSetterCallback method> inline napi_value InstanceWrap::WrappedMethod( napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { const CallbackInfo cbInfo(env, info); T* instance = T::Unwrap(cbInfo.This().As()); if (instance) (instance->*method)(cbInfo, cbInfo[0]); @@ -4962,13 +5007,13 @@ inline napi_value ObjectWrap::ConstructorCallbackWrapper( bool isConstructCall = (new_target != nullptr); if (!isConstructCall) { return details::WrapCallback( - [&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); }); + env, [&] { return T::OnCalledAsFunction(CallbackInfo(env, info)); }); } - napi_value wrapper = details::WrapCallback([&] { + napi_value wrapper = details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); T* instance = new T(callbackInfo); -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS instance->_construction_failed = false; #else if (callbackInfo.Env().IsExceptionPending()) { @@ -4979,7 +5024,7 @@ inline napi_value ObjectWrap::ConstructorCallbackWrapper( } else { instance->_construction_failed = false; } -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS return callbackInfo.This(); }); @@ -4989,7 +5034,7 @@ inline napi_value ObjectWrap::ConstructorCallbackWrapper( template inline napi_value ObjectWrap::StaticVoidMethodCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); StaticVoidMethodCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -5002,7 +5047,7 @@ inline napi_value ObjectWrap::StaticVoidMethodCallbackWrapper( template inline napi_value ObjectWrap::StaticMethodCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); StaticMethodCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -5014,7 +5059,7 @@ inline napi_value ObjectWrap::StaticMethodCallbackWrapper( template inline napi_value ObjectWrap::StaticGetterCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); StaticAccessorCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -5026,7 +5071,7 @@ inline napi_value ObjectWrap::StaticGetterCallbackWrapper( template inline napi_value ObjectWrap::StaticSetterCallbackWrapper( napi_env env, napi_callback_info info) { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { CallbackInfo callbackInfo(env, info); StaticAccessorCallbackData* callbackData = reinterpret_cast(callbackInfo.Data()); @@ -5101,7 +5146,7 @@ template template ::StaticSetterCallback method> inline napi_value ObjectWrap::WrappedMethod( napi_env env, napi_callback_info info) NAPI_NOEXCEPT { - return details::WrapCallback([&] { + return details::WrapCallback(env, [&] { const CallbackInfo cbInfo(env, info); // MSVC requires to copy 'method' function pointer to a local variable // before invoking it. @@ -5402,15 +5447,15 @@ inline void AsyncWorker::OnAsyncWorkExecute(napi_env env, void* asyncworker) { // must not run any method that would cause JavaScript to run. In practice, // this means that almost any use of napi_env will be incorrect. inline void AsyncWorker::OnExecute(Napi::Env /*DO_NOT_USE*/) { -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS try { Execute(); } catch (const std::exception& e) { SetError(e.what()); } -#else // NAPI_CPP_EXCEPTIONS +#else // NODE_ADDON_API_CPP_EXCEPTIONS Execute(); -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS } inline void AsyncWorker::OnAsyncWorkComplete(napi_env env, @@ -5419,10 +5464,10 @@ inline void AsyncWorker::OnAsyncWorkComplete(napi_env env, AsyncWorker* self = static_cast(asyncworker); self->OnWorkComplete(env, status); } -inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) { +inline void AsyncWorker::OnWorkComplete(Napi::Env env, napi_status status) { if (status != napi_cancelled) { HandleScope scope(_env); - details::WrapCallback([&] { + details::WrapCallback(env, [&] { if (_error.size() == 0) { OnOK(); } else { @@ -6334,7 +6379,7 @@ inline void ThreadSafeFunction::CallJS(napi_env env, return; } - details::WrapVoidCallback([&]() { + details::WrapVoidCallback(env, [&]() { if (data != nullptr) { auto* callbackWrapper = static_cast(data); (*callbackWrapper)(env, Function(env, jsCallback)); diff --git a/napi.h b/napi.h index 99488f94e..4838be6cc 100644 --- a/napi.h +++ b/napi.h @@ -37,22 +37,40 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), #define NAPI_WIDE_TEXT(x) u##x #endif +// Backwards-compatibility to handle the rename of this macro definition, in +// case they are used within userland code. +#ifdef NAPI_CPP_EXCEPTIONS +#define NODE_ADDON_API_CPP_EXCEPTIONS +#endif +#if defined(NODE_ADDON_API_CPP_EXCEPTIONS) && !defined(NAPI_CPP_EXCEPTIONS) +#define NAPI_CPP_EXCEPTIONS +#endif +#ifdef NAPI_DISABLE_CPP_EXCEPTIONS +#define NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS +#endif +#if defined(NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS) && \ + !defined(NAPI_DISABLE_CPP_EXCEPTIONS) +#define NAPI_DISABLE_CPP_EXCEPTIONS +#endif + // If C++ exceptions are not explicitly enabled or disabled, enable them // if exceptions were enabled in the compiler settings. -#if !defined(NAPI_CPP_EXCEPTIONS) && !defined(NAPI_DISABLE_CPP_EXCEPTIONS) +#if !defined(NODE_ADDON_API_CPP_EXCEPTIONS) && \ + !defined(NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS) #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) -#define NAPI_CPP_EXCEPTIONS +#define NODE_ADDON_API_CPP_EXCEPTIONS #else #error Exception support not detected. \ - Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS. + Define either NODE_ADDON_API_CPP_EXCEPTIONS or NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS. #endif #endif -// If C++ NAPI_CPP_EXCEPTIONS are enabled, NODE_ADDON_API_ENABLE_MAYBE should -// not be set -#if defined(NAPI_CPP_EXCEPTIONS) && defined(NODE_ADDON_API_ENABLE_MAYBE) +// If C++ NODE_ADDON_API_CPP_EXCEPTIONS are enabled, NODE_ADDON_API_ENABLE_MAYBE +// should not be set +#if defined(NODE_ADDON_API_CPP_EXCEPTIONS) && \ + defined(NODE_ADDON_API_ENABLE_MAYBE) #error NODE_ADDON_API_ENABLE_MAYBE should not be set when \ - NAPI_CPP_EXCEPTIONS is defined. + NODE_ADDON_API_CPP_EXCEPTIONS is defined. #endif #ifdef _NOEXCEPT @@ -61,7 +79,7 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), #define NAPI_NOEXCEPT noexcept #endif -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS // When C++ exceptions are enabled, Errors are thrown directly. There is no need // to return anything after the throw statements. The variadic parameter is an @@ -78,7 +96,7 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), #define NAPI_THROW_IF_FAILED_VOID(env, status) \ if ((status) != napi_ok) throw Napi::Error::New(env); -#else // NAPI_CPP_EXCEPTIONS +#else // NODE_ADDON_API_CPP_EXCEPTIONS // When C++ exceptions are disabled, Errors are thrown as JavaScript exceptions, // which are pending until the callback returns to JS. The variadic parameter @@ -110,7 +128,7 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), return; \ } -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS #ifdef NODE_ADDON_API_ENABLE_MAYBE #define NAPI_MAYBE_THROW_IF_FAILED(env, status, type) \ @@ -1068,7 +1086,7 @@ class Object : public TypeTaggable { T* data, Hint* finalizeHint) const; -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS class const_iterator; inline const_iterator begin() const; @@ -1080,7 +1098,7 @@ class Object : public TypeTaggable { inline iterator begin(); inline iterator end(); -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS #if NAPI_VERSION >= 8 /// This operation can fail in case of Proxy.[[GetPrototypeOf]] calling into @@ -1132,7 +1150,7 @@ class Array : public Object { uint32_t Length() const; }; -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS class Object::const_iterator { private: enum class Type { BEGIN, END }; @@ -1179,7 +1197,7 @@ class Object::iterator { friend class Object; }; -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS /// A JavaScript array buffer value. class ArrayBuffer : public Object { @@ -1811,14 +1829,15 @@ FunctionReference Persistent(Function value); /// /// ### Handling Errors Without C++ Exceptions /// -/// If C++ exceptions are disabled (by defining `NAPI_DISABLE_CPP_EXCEPTIONS`) -/// then this class does not extend `std::exception`, and APIs in the `Napi` -/// namespace do not throw C++ exceptions when they fail. Instead, they raise -/// _pending_ JavaScript exceptions and return _empty_ `Value`s. Calling code -/// should check `Value::IsEmpty()` before attempting to use a returned value, -/// and may use methods on the `Env` class to check for, get, and clear a -/// pending JavaScript exception. If the pending exception is not cleared, it -/// will be thrown when the native callback returns to JavaScript. +/// If C++ exceptions are disabled (by defining +/// `NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS`) then this class does not extend +/// `std::exception`, and APIs in the `Napi` namespace do not throw C++ +/// exceptions when they fail. Instead, they raise _pending_ JavaScript +/// exceptions and return _empty_ `Value`s. Calling code should check +/// `Value::IsEmpty()` before attempting to use a returned value, and may use +/// methods on the `Env` class to check for, get, and clear a pending JavaScript +/// exception. If the pending exception is not cleared, it will be thrown when +/// the native callback returns to JavaScript. /// /// #### Example 1B - Throwing a JS exception /// @@ -1853,10 +1872,10 @@ FunctionReference Persistent(Function value); /// Since the exception was cleared here, it will not be propagated as a /// JavaScript exception after the native callback returns. class Error : public ObjectReference -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS , public std::exception -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS { public: static Error New(napi_env env); @@ -1879,9 +1898,9 @@ class Error : public ObjectReference Object Value() const; -#ifdef NAPI_CPP_EXCEPTIONS +#ifdef NODE_ADDON_API_CPP_EXCEPTIONS const char* what() const NAPI_NOEXCEPT override; -#endif // NAPI_CPP_EXCEPTIONS +#endif // NODE_ADDON_API_CPP_EXCEPTIONS protected: /// !cond INTERNAL diff --git a/node_addon_api.gyp b/node_addon_api.gyp index 29905ed47..8c099262a 100644 --- a/node_addon_api.gyp +++ b/node_addon_api.gyp @@ -18,6 +18,16 @@ 'includes': ['except.gypi'], } }, + { + 'target_name': 'node_addon_api_except_all', + 'type': 'none', + 'sources': [ 'napi.h', 'napi-inl.h' ], + 'direct_dependent_settings': { + 'include_dirs': [ '.' ], + 'includes': ['except.gypi'], + 'defines': [ 'NODE_ADDON_API_CPP_EXCEPTIONS_ALL' ] + } + }, { 'target_name': 'node_addon_api_maybe', 'type': 'none', diff --git a/noexcept.gypi b/noexcept.gypi index 404a05f30..83df4ddf0 100644 --- a/noexcept.gypi +++ b/noexcept.gypi @@ -1,5 +1,5 @@ { - 'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ], + 'defines': [ 'NODE_ADDON_API_DISABLE_CPP_EXCEPTIONS' ], 'cflags': [ '-fno-exceptions' ], 'cflags_cc': [ '-fno-exceptions' ], 'conditions': [ diff --git a/test/binding.gyp b/test/binding.gyp index 3dd861d0b..8ee391fb9 100644 --- a/test/binding.gyp +++ b/test/binding.gyp @@ -85,6 +85,9 @@ 'binding-swallowexcept.cc', 'error.cc', ], + 'build_sources_except_all': [ + 'except_all.cc', + ], 'build_sources_type_check': [ 'value_type_cast.cc' ], @@ -114,6 +117,11 @@ 'sources': ['>@(build_sources)'], 'defines': ['NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS'] }, + { + 'target_name': 'binding_except_all', + 'dependencies': ['../node_addon_api.gyp:node_addon_api_except_all'], + 'sources': [ '>@(build_sources_except_all)'] + }, { 'target_name': 'binding_noexcept', 'dependencies': ['../node_addon_api.gyp:node_addon_api'], diff --git a/test/except_all.cc b/test/except_all.cc new file mode 100644 index 000000000..ca91efdf3 --- /dev/null +++ b/test/except_all.cc @@ -0,0 +1,21 @@ +#include "napi.h" + +using namespace Napi; + +void ThrowStdException(const CallbackInfo& info) { + std::string message = info[0].As().Utf8Value(); + throw std::runtime_error(message); +} + +void ThrowPrimitiveException(const CallbackInfo&) { + throw 0; +} + +Object Init(Env env, Object exports) { + exports.Set("throwStdException", Napi::Function::New(env, ThrowStdException)); + exports.Set("throwPrimitiveException", + Napi::Function::New(env, ThrowPrimitiveException)); + return exports; +} + +NODE_API_MODULE(addon, Init) diff --git a/test/except_all.js b/test/except_all.js new file mode 100644 index 000000000..d650ece6f --- /dev/null +++ b/test/except_all.js @@ -0,0 +1,14 @@ +'use strict'; + +const assert = require('assert'); + +module.exports = require('./common').runTestWithBuildType(test); + +function test (buildType) { + const binding = require(`./build/${buildType}/binding_except_all.node`); + + const message = 'error message'; + assert.throws(binding.throwStdException.bind(undefined, message), { message }); + + assert.throws(binding.throwPrimitiveException.bind(undefined), { message: 'A native exception was thrown' }); +} From 5fa31a718d87fd805f5d352df1d8d519c3713bb8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:44:43 +0000 Subject: [PATCH 5/8] chore(deps): bump the all group with 2 updates (#1618) Bumps the all group with 2 updates: [github/codeql-action](https://github.com/github/codeql-action) and [codecov/codecov-action](https://github.com/codecov/codecov-action). Updates `github/codeql-action` from 3.27.1 to 3.27.4 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/4f3212b61783c3c68e8309a0f18a699764811cda...ea9e4e37992a54ee68a9622e985e60c8e8f12d9f) Updates `codecov/codecov-action` from 4.6.0 to 5.0.2 - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238...5c47607acb93fed5485fdbf7232e8a31425f672a) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/coverage-linux.yml | 2 +- .github/workflows/scorecards.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 12484121e..60fd19b08 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -50,7 +50,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 + uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -80,6 +80,6 @@ jobs: npx node-gyp rebuild -C test - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 + uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/coverage-linux.yml b/.github/workflows/coverage-linux.yml index b239374a2..01064f894 100644 --- a/.github/workflows/coverage-linux.yml +++ b/.github/workflows/coverage-linux.yml @@ -63,7 +63,7 @@ jobs: run: | npm run report-coverage-xml - name: Upload - uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 + uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2 with: directory: ./coverage-xml token: ${{ secrets.CODECOV_TOKEN }} # To bypass public API rate limiting, see https://github.com/codecov/codecov-action/issues/557 diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 9013e3336..94fd38861 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -71,6 +71,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1 + uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 with: sarif_file: results.sarif From 5853aadea014ae8aa8ecdcf15250b1c6773981aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 25 Nov 2024 11:44:49 +0100 Subject: [PATCH 6/8] chore: enable tokenless Codecov uploads (#1620) Refs: https://docs.codecov.com/docs/codecov-tokens#uploading-without-a-token --- .github/workflows/coverage-linux.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/coverage-linux.yml b/.github/workflows/coverage-linux.yml index 01064f894..85635f225 100644 --- a/.github/workflows/coverage-linux.yml +++ b/.github/workflows/coverage-linux.yml @@ -63,7 +63,6 @@ jobs: run: | npm run report-coverage-xml - name: Upload - uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2 + uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7 with: directory: ./coverage-xml - token: ${{ secrets.CODECOV_TOKEN }} # To bypass public API rate limiting, see https://github.com/codecov/codecov-action/issues/557 From 7341a635cd372ac61767e75fd900757b905b56aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 10:19:37 -0500 Subject: [PATCH 7/8] chore(deps): bump the all group across 1 directory with 3 updates (#1622) Bumps the all group with 3 updates in the / directory: [step-security/harden-runner](https://github.com/step-security/harden-runner), [github/codeql-action](https://github.com/github/codeql-action) and [actions/dependency-review-action](https://github.com/actions/dependency-review-action). Updates `step-security/harden-runner` from 2.10.1 to 2.10.2 - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/91182cccc01eb5e619899d80e4e971d6181294a7...0080882f6c36860b6ba35c610c98ce87d4e2f26f) Updates `github/codeql-action` from 3.27.4 to 3.27.5 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/ea9e4e37992a54ee68a9622e985e60c8e8f12d9f...f09c1c0a94de965c15400f5634aa42fac8fb8f88) Updates `actions/dependency-review-action` from 4.4.0 to 4.5.0 - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/4081bf99e2866ebe428fc0477b69eb4fcda7220a...3b139cfc5fae8b618d3eae3675e383bb1769c019) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: all - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-minor dependency-group: all ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci-win.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 6 +++--- .github/workflows/coverage-linux.yml | 2 +- .github/workflows/dependency-review.yml | 4 ++-- .github/workflows/linter.yml | 2 +- .github/workflows/node-api-headers.yml | 2 +- .github/workflows/release-please.yml | 4 ++-- .github/workflows/scorecards.yml | 4 ++-- .github/workflows/stale.yml | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci-win.yml b/.github/workflows/ci-win.yml index fc5224aa2..25070ce47 100644 --- a/.github/workflows/ci-win.yml +++ b/.github/workflows/ci-win.yml @@ -28,7 +28,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 615cd3fd7..55530c62f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 60fd19b08..95d91574e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -41,7 +41,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs @@ -50,7 +50,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 + uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -80,6 +80,6 @@ jobs: npx node-gyp rebuild -C test - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 + uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/coverage-linux.yml b/.github/workflows/coverage-linux.yml index 85635f225..9d9234602 100644 --- a/.github/workflows/coverage-linux.yml +++ b/.github/workflows/coverage-linux.yml @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index a5b5bf5af..63bb886a8 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -17,11 +17,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs - name: 'Checkout Repository' uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: 'Dependency Review' - uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 + uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index da74ef8d8..8520ce7d2 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/node-api-headers.yml b/.github/workflows/node-api-headers.yml index c5cd11903..0094caf61 100644 --- a/.github/workflows/node-api-headers.yml +++ b/.github/workflows/node-api-headers.yml @@ -30,7 +30,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 965d704b9..cd931a836 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -16,7 +16,7 @@ jobs: pull-requests: write steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit @@ -35,7 +35,7 @@ jobs: id-token: write steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 94fd38861..08ffaa97e 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -31,7 +31,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs @@ -71,6 +71,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4 + uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5 with: sarif_file: results.sarif diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 4c5b8ccf1..55b1fba86 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: egress-policy: audit From 398eec6b0b396fa5fae7d1a8bcac9f01758878ae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:18:56 +0000 Subject: [PATCH 8/8] chore: release v8.3.0 (#1617) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .release-please-manifest.json | 2 +- CHANGELOG.md | 7 +++++++ README.md | 2 +- package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 800909f2e..8d48393bb 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "8.2.2" + ".": "8.3.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a346676..10bf72949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # node-addon-api Changelog +## [8.3.0](https://github.com/nodejs/node-addon-api/compare/v8.2.2...v8.3.0) (2024-11-29) + + +### Features + +* allow catching all exceptions ([#1593](https://github.com/nodejs/node-addon-api/issues/1593)) ([c679f6f](https://github.com/nodejs/node-addon-api/commit/c679f6f4c9dc6bf9fc0d99cbe5982bd24a5e2c7b)) + ## [8.2.2](https://github.com/nodejs/node-addon-api/compare/v8.2.1...v8.2.2) (2024-11-07) diff --git a/README.md b/README.md index 38ac19ff1..3bec9f49f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ and exception handling semantics with low overhead. API references are available in the [doc](doc/README.md) directory. -## Current version: 8.2.2 +## Current version: 8.3.0 (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog) diff --git a/package.json b/package.json index 3bd157cd7..8faff2cd5 100644 --- a/package.json +++ b/package.json @@ -472,7 +472,7 @@ "lint:fix": "eslint --fix && node tools/clang-format --fix" }, "pre-commit": "lint", - "version": "8.2.2", + "version": "8.3.0", "support": true, "engines": { "node": "^18 || ^20 || >= 21"