node-addon-api 8.2.1 → 8.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ and exception handling semantics with low overhead.
19
19
  API references are available in the [doc](doc/README.md) directory.
20
20
 
21
21
  <!-- x-release-please-start-version -->
22
- ## Current version: 8.2.1
22
+ ## Current version: 8.2.2
23
23
  <!-- x-release-please-end -->
24
24
 
25
25
  (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
package/napi-inl.h CHANGED
@@ -3341,6 +3341,8 @@ template <typename T>
3341
3341
  inline Reference<T>::~Reference() {
3342
3342
  if (_ref != nullptr) {
3343
3343
  if (!_suppressDestruct) {
3344
+ // TODO(legendecas): napi_delete_reference should be invoked immediately.
3345
+ // Fix this when https://github.com/nodejs/node/pull/55620 lands.
3344
3346
  #ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
3345
3347
  Env().PostFinalizer(
3346
3348
  [](Napi::Env env, napi_ref ref) { napi_delete_reference(env, ref); },
@@ -4595,7 +4597,7 @@ template <typename T>
4595
4597
  inline ObjectWrap<T>::~ObjectWrap() {
4596
4598
  // If the JS object still exists at this point, remove the finalizer added
4597
4599
  // through `napi_wrap()`.
4598
- if (!IsEmpty()) {
4600
+ if (!IsEmpty() && !_finalized) {
4599
4601
  Object object = Value();
4600
4602
  // It is not valid to call `napi_remove_wrap()` with an empty `object`.
4601
4603
  // This happens e.g. during garbage collection.
@@ -5044,8 +5046,10 @@ inline void ObjectWrap<T>::FinalizeCallback(node_addon_api_basic_env env,
5044
5046
  (void)env;
5045
5047
  T* instance = static_cast<T*>(data);
5046
5048
 
5047
- // Prevent ~ObjectWrap from calling napi_remove_wrap
5048
- instance->_ref = nullptr;
5049
+ // Prevent ~ObjectWrap from calling napi_remove_wrap.
5050
+ // The instance->_ref should be deleted with napi_delete_reference in
5051
+ // ~Reference.
5052
+ instance->_finalized = true;
5049
5053
 
5050
5054
  // If class overrides the basic finalizer, execute it.
5051
5055
  if constexpr (details::HasBasicFinalizer<T>::value) {
@@ -6699,12 +6703,14 @@ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
6699
6703
  // Memory Management class
6700
6704
  ////////////////////////////////////////////////////////////////////////////////
6701
6705
 
6702
- inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
6706
+ inline int64_t MemoryManagement::AdjustExternalMemory(BasicEnv env,
6703
6707
  int64_t change_in_bytes) {
6704
6708
  int64_t result;
6705
6709
  napi_status status =
6706
6710
  napi_adjust_external_memory(env, change_in_bytes, &result);
6707
- NAPI_THROW_IF_FAILED(env, status, 0);
6711
+ NAPI_FATAL_IF_FAILED(status,
6712
+ "MemoryManagement::AdjustExternalMemory",
6713
+ "napi_adjust_external_memory");
6708
6714
  return result;
6709
6715
  }
6710
6716
 
@@ -6712,17 +6718,20 @@ inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
6712
6718
  // Version Management class
6713
6719
  ////////////////////////////////////////////////////////////////////////////////
6714
6720
 
6715
- inline uint32_t VersionManagement::GetNapiVersion(Env env) {
6721
+ inline uint32_t VersionManagement::GetNapiVersion(BasicEnv env) {
6716
6722
  uint32_t result;
6717
6723
  napi_status status = napi_get_version(env, &result);
6718
- NAPI_THROW_IF_FAILED(env, status, 0);
6724
+ NAPI_FATAL_IF_FAILED(
6725
+ status, "VersionManagement::GetNapiVersion", "napi_get_version");
6719
6726
  return result;
6720
6727
  }
6721
6728
 
6722
- inline const napi_node_version* VersionManagement::GetNodeVersion(Env env) {
6729
+ inline const napi_node_version* VersionManagement::GetNodeVersion(
6730
+ BasicEnv env) {
6723
6731
  const napi_node_version* result;
6724
6732
  napi_status status = napi_get_node_version(env, &result);
6725
- NAPI_THROW_IF_FAILED(env, status, 0);
6733
+ NAPI_FATAL_IF_FAILED(
6734
+ status, "VersionManagement::GetNodeVersion", "napi_get_node_version");
6726
6735
  return result;
6727
6736
  }
6728
6737
 
package/napi.h CHANGED
@@ -2514,6 +2514,7 @@ class ObjectWrap : public InstanceWrap<T>, public Reference<Object> {
2514
2514
  }
2515
2515
 
2516
2516
  bool _construction_failed = true;
2517
+ bool _finalized = false;
2517
2518
  };
2518
2519
 
2519
2520
  class HandleScope {
@@ -3234,14 +3235,14 @@ class AsyncProgressQueueWorker
3234
3235
  // Memory management.
3235
3236
  class MemoryManagement {
3236
3237
  public:
3237
- static int64_t AdjustExternalMemory(Env env, int64_t change_in_bytes);
3238
+ static int64_t AdjustExternalMemory(BasicEnv env, int64_t change_in_bytes);
3238
3239
  };
3239
3240
 
3240
3241
  // Version management
3241
3242
  class VersionManagement {
3242
3243
  public:
3243
- static uint32_t GetNapiVersion(Env env);
3244
- static const napi_node_version* GetNodeVersion(Env env);
3244
+ static uint32_t GetNapiVersion(BasicEnv env);
3245
+ static const napi_node_version* GetNodeVersion(BasicEnv env);
3245
3246
  };
3246
3247
 
3247
3248
  #if NAPI_VERSION > 5
package/package.json CHANGED
@@ -478,7 +478,7 @@
478
478
  "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
479
479
  },
480
480
  "pre-commit": "lint",
481
- "version": "8.2.1",
481
+ "version": "8.2.2",
482
482
  "support": true,
483
483
  "engines": {
484
484
  "node": "^18 || ^20 || >= 21"