node-addon-api 6.1.0 → 7.0.0

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.
Files changed (3) hide show
  1. package/README.md +3 -2
  2. package/napi-inl.h +23 -7
  3. package/package.json +9 -1
package/README.md CHANGED
@@ -70,7 +70,7 @@ and node-addon-api.
70
70
  - **[Contributors](#contributors)**
71
71
  - **[License](#license)**
72
72
 
73
- ## **Current version: 6.1.0**
73
+ ## **Current version: 7.0.0**
74
74
 
75
75
  (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
76
76
 
@@ -83,7 +83,7 @@ This allows addons built with it to run with Node.js versions which support the
83
83
  **However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
84
84
  every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
85
85
 
86
- The oldest Node.js version supported by the current version of node-addon-api is Node.js 14.x.
86
+ The oldest Node.js version supported by the current version of node-addon-api is Node.js 16.x.
87
87
 
88
88
  ## Setup
89
89
  - [Installation and usage](doc/setup.md)
@@ -275,6 +275,7 @@ available:
275
275
  ![Node-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v6%20Badge.svg)
276
276
  ![Node-API v7 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v7%20Badge.svg)
277
277
  ![Node-API v8 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v8%20Badge.svg)
278
+ ![Node-API v9 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v9%20Badge.svg)
278
279
  ![Node-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20Experimental%20Version%20Badge.svg)
279
280
 
280
281
  ## **Contributing**
package/napi-inl.h CHANGED
@@ -165,7 +165,7 @@ napi_value TemplatedInstanceCallback(napi_env env,
165
165
  return details::WrapCallback([&] {
166
166
  CallbackInfo cbInfo(env, info);
167
167
  T* instance = T::Unwrap(cbInfo.This().As<Object>());
168
- return (instance->*UnwrapCallback)(cbInfo);
168
+ return instance ? (instance->*UnwrapCallback)(cbInfo) : Napi::Value();
169
169
  });
170
170
  }
171
171
 
@@ -175,7 +175,7 @@ napi_value TemplatedInstanceVoidCallback(napi_env env, napi_callback_info info)
175
175
  return details::WrapCallback([&] {
176
176
  CallbackInfo cbInfo(env, info);
177
177
  T* instance = T::Unwrap(cbInfo.This().As<Object>());
178
- (instance->*UnwrapCallback)(cbInfo);
178
+ if (instance) (instance->*UnwrapCallback)(cbInfo);
179
179
  return nullptr;
180
180
  });
181
181
  }
@@ -2937,6 +2937,22 @@ inline Error::Error(napi_env env, napi_value value)
2937
2937
  nullptr};
2938
2938
 
2939
2939
  status = napi_define_properties(env, wrappedErrorObj, 1, &wrapObjFlag);
2940
+ #ifdef NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS
2941
+ if (status == napi_pending_exception) {
2942
+ // Test if the pending exception was reported because the environment is
2943
+ // shutting down. We assume that a status of napi_pending_exception
2944
+ // coupled with the absence of an actual pending exception means that
2945
+ // the environment is shutting down. If so, we replace the
2946
+ // napi_pending_exception status with napi_ok.
2947
+ bool is_exception_pending = false;
2948
+ status = napi_is_exception_pending(env, &is_exception_pending);
2949
+ if (status == napi_ok && !is_exception_pending) {
2950
+ status = napi_ok;
2951
+ } else {
2952
+ status = napi_pending_exception;
2953
+ }
2954
+ }
2955
+ #endif // NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS
2940
2956
  NAPI_FATAL_IF_FAILED(status, "Error::Error", "napi_define_properties");
2941
2957
 
2942
2958
  // Create a reference on the newly wrapped object
@@ -4340,7 +4356,7 @@ inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
4340
4356
  callbackInfo.SetData(callbackData->data);
4341
4357
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4342
4358
  auto cb = callbackData->callback;
4343
- (instance->*cb)(callbackInfo);
4359
+ if (instance) (instance->*cb)(callbackInfo);
4344
4360
  return nullptr;
4345
4361
  });
4346
4362
  }
@@ -4355,7 +4371,7 @@ inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
4355
4371
  callbackInfo.SetData(callbackData->data);
4356
4372
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4357
4373
  auto cb = callbackData->callback;
4358
- return (instance->*cb)(callbackInfo);
4374
+ return instance ? (instance->*cb)(callbackInfo) : Napi::Value();
4359
4375
  });
4360
4376
  }
4361
4377
 
@@ -4369,7 +4385,7 @@ inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
4369
4385
  callbackInfo.SetData(callbackData->data);
4370
4386
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4371
4387
  auto cb = callbackData->getterCallback;
4372
- return (instance->*cb)(callbackInfo);
4388
+ return instance ? (instance->*cb)(callbackInfo) : Napi::Value();
4373
4389
  });
4374
4390
  }
4375
4391
 
@@ -4383,7 +4399,7 @@ inline napi_value InstanceWrap<T>::InstanceSetterCallbackWrapper(
4383
4399
  callbackInfo.SetData(callbackData->data);
4384
4400
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4385
4401
  auto cb = callbackData->setterCallback;
4386
- (instance->*cb)(callbackInfo, callbackInfo[0]);
4402
+ if (instance) (instance->*cb)(callbackInfo, callbackInfo[0]);
4387
4403
  return nullptr;
4388
4404
  });
4389
4405
  }
@@ -4395,7 +4411,7 @@ inline napi_value InstanceWrap<T>::WrappedMethod(
4395
4411
  return details::WrapCallback([&] {
4396
4412
  const CallbackInfo cbInfo(env, info);
4397
4413
  T* instance = T::Unwrap(cbInfo.This().As<Object>());
4398
- (instance->*method)(cbInfo, cbInfo[0]);
4414
+ if (instance) (instance->*method)(cbInfo, cbInfo[0]);
4399
4415
  return nullptr;
4400
4416
  });
4401
4417
  }
package/package.json CHANGED
@@ -399,6 +399,14 @@
399
399
  {
400
400
  "name": "Feng Yu",
401
401
  "url": "https://github.com/F3n67u"
402
+ },
403
+ {
404
+ "name": "wanlu wang",
405
+ "url": "https://github.com/wanlu"
406
+ },
407
+ {
408
+ "name": "Caleb Hearon",
409
+ "url": "https://github.com/chearon"
402
410
  }
403
411
  ],
404
412
  "description": "Node.js API (Node-API)",
@@ -459,6 +467,6 @@
459
467
  "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
460
468
  },
461
469
  "pre-commit": "lint",
462
- "version": "6.1.0",
470
+ "version": "7.0.0",
463
471
  "support": true
464
472
  }