node-addon-api
Advanced tools
Comparing version 3.0.0 to 3.0.1
# node-addon-api Changelog | ||
## 2020-07-13 Version 3.0.1, @NickNaso | ||
### Notable changes: | ||
#### API | ||
- Fixed the usage of `Napi::Reference` with `Napi::TypedArray`. | ||
- Fixed `Napi::ObjectWrap` inheritance. | ||
#### Documentation | ||
- Updated the example for `Napi::ObjectWrap`. | ||
- Added documentation for instance data APIs. | ||
- Some minor corrections all over the documentation. | ||
#### TEST | ||
- Fixed test for `Napi::ArrayBuffer` and `Napi::Buffer`. | ||
- Some minor corrections all over the test suite. | ||
### Commits | ||
* [[`40c7926342`](https://github.com/nodejs/node-addon-api/commit/40c7926342)] - **build**: ensure paths with spaces can be used (Lovell Fuller) [#757](https://github.com/nodejs/node-addon-api/pull/757) | ||
* [[`ef16dfb4a2`](https://github.com/nodejs/node-addon-api/commit/ef16dfb4a2)] - **doc**: update ObjectWrap example (Gabriel Schulhof) [#754](https://github.com/nodejs/node-addon-api/pull/754) | ||
* [[`48f6762bf6`](https://github.com/nodejs/node-addon-api/commit/48f6762bf6)] - **src**: add \_\_wasm32\_\_ guards (Gus Caplan) | ||
* [[`bd2c5ec502`](https://github.com/nodejs/node-addon-api/commit/bd2c5ec502)] - Fixes issue 745. (#748) (Nicola Del Gobbo) | ||
* [[`4c01af2d87`](https://github.com/nodejs/node-addon-api/commit/4c01af2d87)] - Fix typo in CHANGELOG (#715) (Kasumi Hanazuki) | ||
* [[`36e1af96d5`](https://github.com/nodejs/node-addon-api/commit/36e1af96d5)] - **src**: fix use of Reference with typed arrays (Michael Dawson) [#726](https://github.com/nodejs/node-addon-api/pull/726) | ||
* [[`d463f02bc7`](https://github.com/nodejs/node-addon-api/commit/d463f02bc7)] - **src**: fix testEnumerables on ObjectWrap (Ferdinand Holzer) [#736](https://github.com/nodejs/node-addon-api/pull/736) | ||
* [[`ba7ad37d44`](https://github.com/nodejs/node-addon-api/commit/ba7ad37d44)] - **src**: fix ObjectWrap inheritance (David Halls) [#732](https://github.com/nodejs/node-addon-api/pull/732) | ||
* [[`31504c862b`](https://github.com/nodejs/node-addon-api/commit/31504c862b)] - **doc**: fix minor typo in object\_wrap.md (#741) (Daniel Bevenius) [#741](https://github.com/nodejs/node-addon-api/pull/741) | ||
* [[`beccf2145d`](https://github.com/nodejs/node-addon-api/commit/beccf2145d)] - **test**: fix up delays for array buffer test (Michael Dawson) [#737](https://github.com/nodejs/node-addon-api/pull/737) | ||
* [[`45cb1d9748`](https://github.com/nodejs/node-addon-api/commit/45cb1d9748)] - Correct AsyncProgressWorker link in README (#716) (Jeroen Janssen) | ||
* [[`381c0da60c`](https://github.com/nodejs/node-addon-api/commit/381c0da60c)] - **doc**: add instance data APIs (Gabriel Schulhof) [#708](https://github.com/nodejs/node-addon-api/pull/708) | ||
## 2020-04-30 Version 3.0.0, @NickNaso | ||
@@ -17,3 +52,3 @@ | ||
- Added benchmarking framework. | ||
- Added support for natove addon instance data. | ||
- Added support for native addon instance data. | ||
- Added `Napi::AsyncProgressQueueWorker` api. | ||
@@ -25,3 +60,3 @@ - Changed the guards to `NAPI_VERSION > 5`. | ||
- Removed erroneous finalizer cleanup in `Napi::ThreadSafeFunction`. | ||
- Disabled cahcing in `Napi::ArrayBuffer`. | ||
- Disabled caching in `Napi::ArrayBuffer`. | ||
- Explicitly disallow assign and copy operator. | ||
@@ -28,0 +63,0 @@ - Some minor corrections and improvements. |
@@ -82,3 +82,3 @@ # BigInt | ||
```cpp | ||
void Napi::BigInt::ToWords(size_t* word_count, int* sign_bit, uint64_t* words); | ||
void Napi::BigInt::ToWords(int* sign_bit, size_t* word_count, uint64_t* words); | ||
``` | ||
@@ -85,0 +85,0 @@ |
@@ -78,1 +78,56 @@ # Env | ||
- `const std::string &` | ||
### GetInstanceData | ||
```cpp | ||
template <typename T> T* GetInstanceData(); | ||
``` | ||
Returns the instance data that was previously associated with the environment, | ||
or `nullptr` if none was associated. | ||
### SetInstanceData | ||
```cpp | ||
template <typename T> using Finalizer = void (*)(Env, T*); | ||
template <typename T, Finalizer<T> fini = Env::DefaultFini<T>> | ||
void SetInstanceData(T* data); | ||
``` | ||
- `[template] fini`: A function to call when the instance data is to be deleted. | ||
Accepts a function of the form `void CleanupData(Napi::Env env, T* data)`. If | ||
not given, the default finalizer will be used, which simply uses the `delete` | ||
operator to destroy `T*` when the addon instance is unloaded. | ||
- `[in] data`: A pointer to data that will be associated with the instance of | ||
the addon for the duration of its lifecycle. | ||
Associates a data item stored at `T* data` with the current instance of the | ||
addon. The item will be passed to the function `fini` which gets called when an | ||
instance of the addon is unloaded. | ||
### SetInstanceData | ||
```cpp | ||
template <typename DataType, typename HintType> | ||
using FinalizerWithHint = void (*)(Env, DataType*, HintType*); | ||
template <typename DataType, | ||
typename HintType, | ||
FinalizerWithHint<DataType, HintType> fini = | ||
Env::DefaultFiniWithHint<DataType, HintType>> | ||
void SetInstanceData(DataType* data, HintType* hint); | ||
``` | ||
- `[template] fini`: A function to call when the instance data is to be deleted. | ||
Accepts a function of the form | ||
`void CleanupData(Napi::Env env, DataType* data, HintType* hint)`. If not given, | ||
the default finalizer will be used, which simply uses the `delete` operator to | ||
destroy `T*` when the addon instance is unloaded. | ||
- `[in] data`: A pointer to data that will be associated with the instance of | ||
the addon for the duration of its lifecycle. | ||
- `[in] hint`: A pointer to data that will be associated with the instance of | ||
the addon for the duration of its lifecycle and will be passed as a hint to | ||
`fini` when the addon instance is unloaded. | ||
Associates a data item stored at `T* data` with the current instance of the | ||
addon. The item will be passed to the function `fini` which gets called when an | ||
instance of the addon is unloaded. This overload accepts an additional hint to | ||
be passed to `fini`. |
@@ -25,9 +25,9 @@ # Object Wrap | ||
static Napi::Object Init(Napi::Env env, Napi::Object exports); | ||
Example(const Napi::CallbackInfo &info); | ||
Example(const Napi::CallbackInfo& info); | ||
static Napi::Value CreateNewItem(const Napi::CallbackInfo& info); | ||
private: | ||
static Napi::FunctionReference constructor; | ||
double _value; | ||
Napi::Value GetValue(const Napi::CallbackInfo &info); | ||
Napi::Value SetValue(const Napi::CallbackInfo &info); | ||
Napi::Value GetValue(const Napi::CallbackInfo& info); | ||
Napi::Value SetValue(const Napi::CallbackInfo& info); | ||
}; | ||
@@ -39,18 +39,28 @@ | ||
InstanceMethod<&Example::GetValue>("GetValue"), | ||
InstanceMethod<&Example::SetValue>("SetValue") | ||
InstanceMethod<&Example::SetValue>("SetValue"), | ||
StaticMethod<&Example::CreateNewItem>("CreateNewItem"), | ||
}); | ||
Napi::FunctionReference* constructor = new Napi::FunctionReference(); | ||
// Create a peristent reference to the class constructor. This will allow | ||
// a function called on a class prototype and a function | ||
// called on instance of a class to be distinguished from each other. | ||
constructor = Napi::Persistent(func); | ||
// Call the SuppressDestruct() method on the static data prevent the calling | ||
// to this destructor to reset the reference when the environment is no longer | ||
// available. | ||
constructor.SuppressDestruct(); | ||
*constructor = Napi::Persistent(func); | ||
exports.Set("Example", func); | ||
// Store the constructor as the add-on instance data. This will allow this | ||
// add-on to support multiple instances of itself running on multiple worker | ||
// threads, as well as multiple instances of itself running in different | ||
// contexts on the same thread. | ||
// | ||
// By default, the value set on the environment here will be destroyed when | ||
// the add-on is unloaded using the `delete` operator, but it is also | ||
// possible to supply a custom deleter. | ||
env.SetInstanceData<Napi::FunctionReference>(constructor); | ||
return exports; | ||
} | ||
Example::Example(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Example>(info) { | ||
Example::Example(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Example>(info) { | ||
Napi::Env env = info.Env(); | ||
@@ -62,5 +72,3 @@ // ... | ||
Napi::FunctionReference Example::constructor; | ||
Napi::Value Example::GetValue(const Napi::CallbackInfo &info){ | ||
Napi::Value Example::GetValue(const Napi::CallbackInfo& info){ | ||
Napi::Env env = info.Env(); | ||
@@ -70,3 +78,3 @@ return Napi::Number::New(env, this->_value); | ||
Napi::Value Example::SetValue(const Napi::CallbackInfo &info){ | ||
Napi::Value Example::SetValue(const Napi::CallbackInfo& info){ | ||
Napi::Env env = info.Env(); | ||
@@ -85,2 +93,12 @@ // ... | ||
// Create a new item using the constructor stored during Init. | ||
Napi::Value Example::CreateNewItem(const Napi::CallbackInfo& info) { | ||
// Retrieve the instance data we stored during `Init()`. We only stored the | ||
// constructor there, so we retrieve it here to create a new instance of the | ||
// JS class the constructor represents. | ||
Napi::FunctionReference* constructor = | ||
info.Env().GetInstanceData<Napi::FunctionReference>(); | ||
return constructor->New({ Napi::Number::New(info.Env(), 42) }); | ||
} | ||
// Register and initialize native add-on | ||
@@ -145,3 +163,3 @@ NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) | ||
Returns a native instace wrapped in a JavaScript object. Given the | ||
Returns a native instance wrapped in a JavaScript object. Given the | ||
Napi:Object, this allows a method to get a pointer to the wrapped | ||
@@ -148,0 +166,0 @@ C++ object and then reference fields, call methods, etc. within that class. |
const path = require('path'); | ||
const include = path.relative('.', __dirname); | ||
module.exports = { | ||
include: `"${__dirname}"`, | ||
gyp: path.join(__dirname, 'node_api.gyp:nothing'), | ||
include: include, | ||
gyp: path.join(include, 'node_api.gyp:nothing'), | ||
isNodeApiBuiltin: true, | ||
needsFlag: false | ||
}; |
@@ -63,2 +63,6 @@ { | ||
{ | ||
"name": "Daniel Bevenius", | ||
"url": "https://github.com/danbev" | ||
}, | ||
{ | ||
"name": "David Halls", | ||
@@ -112,2 +116,6 @@ "url": "https://github.com/davedoesdev" | ||
{ | ||
"name": "Jeroen Janssen", | ||
"url": "https://github.com/japj" | ||
}, | ||
{ | ||
"name": "Jim Schlight", | ||
@@ -125,2 +133,6 @@ "url": "https://github.com/jschlight" | ||
{ | ||
"name": "Kasumi Hanazuki", | ||
"url": "https://github.com/hanazuki" | ||
}, | ||
{ | ||
"name": "Kelvin", | ||
@@ -146,2 +158,6 @@ "url": "https://github.com/kelvinhammond" | ||
{ | ||
"name": "Lovell Fuller", | ||
"url": "https://github.com/lovell" | ||
}, | ||
{ | ||
"name": "Luciano Martorella", | ||
@@ -279,3 +295,3 @@ "url": "https://github.com/lmartorella" | ||
}, | ||
"version": "3.0.0" | ||
"version": "3.0.1" | ||
} |
@@ -50,3 +50,3 @@ # **node-addon-api module** | ||
## **Current version: 3.0.0** | ||
## **Current version: 3.0.1** | ||
@@ -59,4 +59,4 @@ (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog) | ||
node-addon-api is based on [N-API](https://nodejs.org/api/n-api.html) and supports using different N-API versions. | ||
This allows addons built with it to run with Node.js versions which support the targeted N-API version. | ||
node-addon-api is based on [N-API](https://nodejs.org/api/n-api.html) and supports using different N-API versions. | ||
This allows addons built with it to run with Node.js versions which support the targeted N-API version. | ||
**However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that | ||
@@ -120,3 +120,3 @@ every year there will be a new major which drops support for the Node.js LTS version which has gone out of service. | ||
- [AsyncContext](doc/async_context.md) | ||
- [AsyncProgressWorker](doc/async_progress_worker.md) | ||
- [AsyncWorker Variants](doc/async_worker_variants.md) | ||
- [Thread-safe Functions](doc/threadsafe_function.md) | ||
@@ -123,0 +123,0 @@ - [Promises](doc/promises.md) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
719815
449