node-addon-api 2.0.2 → 3.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.
- package/.travis.yml +1 -4
- package/CHANGELOG.md +88 -30
- package/README.md +53 -7
- package/benchmark/README.md +47 -0
- package/benchmark/binding.gyp +25 -0
- package/benchmark/function_args.cc +153 -0
- package/benchmark/function_args.js +52 -0
- package/benchmark/index.js +34 -0
- package/benchmark/property_descriptor.cc +60 -0
- package/benchmark/property_descriptor.js +29 -0
- package/common.gypi +21 -0
- package/doc/async_worker.md +33 -4
- package/doc/{async_progress_worker.md → async_worker_variants.md} +115 -3
- package/doc/bigint.md +2 -1
- package/doc/class_property_descriptor.md +3 -3
- package/doc/creating_a_release.md +5 -5
- package/doc/env.md +14 -0
- package/doc/function.md +108 -1
- package/doc/object.md +40 -1
- package/doc/object_lifetime_management.md +1 -1
- package/doc/object_wrap.md +278 -2
- package/doc/property_descriptor.md +64 -9
- package/doc/setup.md +0 -1
- package/doc/string.md +1 -1
- package/doc/symbol.md +1 -1
- package/doc/value.md +1 -1
- package/except.gypi +16 -0
- package/index.js +5 -42
- package/napi-inl.h +727 -141
- package/napi.h +338 -83
- package/node_api.gyp +9 -0
- package/noexcept.gypi +16 -0
- package/{src/nothing.c → nothing.c} +0 -0
- package/package.json +33 -1
- package/tools/README.md +4 -4
- package/tools/conversion.js +0 -4
- package/external-napi/node_api.h +0 -7
- package/src/node_api.cc +0 -3655
- package/src/node_api.gyp +0 -21
- package/src/node_api.h +0 -588
- package/src/node_api_types.h +0 -115
- package/src/node_internals.cc +0 -142
- package/src/node_internals.h +0 -157
- package/src/util-inl.h +0 -38
- package/src/util.h +0 -7
package/.travis.yml
CHANGED
|
@@ -12,17 +12,14 @@ env:
|
|
|
12
12
|
# https://github.com/jasongin/nvs/blob/master/doc/CI.md
|
|
13
13
|
- NVS_VERSION=1.4.2
|
|
14
14
|
matrix:
|
|
15
|
-
- NODEJS_VERSION=node/6
|
|
16
|
-
- NODEJS_VERSION=node/8
|
|
17
15
|
- NODEJS_VERSION=node/10
|
|
18
16
|
- NODEJS_VERSION=node/12
|
|
19
|
-
- NODEJS_VERSION=node/
|
|
17
|
+
- NODEJS_VERSION=node/14
|
|
20
18
|
- NODEJS_VERSION=nightly
|
|
21
19
|
matrix:
|
|
22
20
|
fast_finish: true
|
|
23
21
|
allow_failures:
|
|
24
22
|
- env: NODEJS_VERSION=nightly
|
|
25
|
-
- env: NODEJS_VERSION=node/6
|
|
26
23
|
sudo: false
|
|
27
24
|
cache:
|
|
28
25
|
directories:
|
package/CHANGELOG.md
CHANGED
|
@@ -1,40 +1,98 @@
|
|
|
1
1
|
# node-addon-api Changelog
|
|
2
2
|
|
|
3
|
-
## 2020-
|
|
3
|
+
## 2020-04-30 Version 3.0.0, @NickNaso
|
|
4
4
|
|
|
5
5
|
### Notable changes:
|
|
6
6
|
|
|
7
7
|
#### API
|
|
8
8
|
|
|
9
|
-
- `Napi::
|
|
10
|
-
- `Napi::ObjectWrap
|
|
11
|
-
- `Napi::ObjectWrap
|
|
12
|
-
- `Napi::ObjectWrap
|
|
9
|
+
- `Napi::Object` added templated property descriptors.
|
|
10
|
+
- `Napi::ObjectWrap` added templated methods.
|
|
11
|
+
- `Napi::ObjectWrap` the wrap is removed only on failure.
|
|
12
|
+
- `Napi::ObjectWrap` the constructor's exceptions are gracefully handled.
|
|
13
|
+
- `Napi::Function` added templated factory functions.
|
|
14
|
+
- Added `Env::RunScript` method to run JavaScript code contained in a string.
|
|
15
|
+
- Added templated version of `Napi::Function`.
|
|
16
|
+
- Added benchmarking framework.
|
|
17
|
+
- Added support for natove addon instance data.
|
|
18
|
+
- Added `Napi::AsyncProgressQueueWorker` api.
|
|
19
|
+
- Changed the guards to `NAPI_VERSION > 5`.
|
|
20
|
+
- Removed N-API implementation (v6.x and v8.x support).
|
|
21
|
+
- `Napi::AsyncWorker::OnWorkComplete` and `Napi::AsyncWorker::OnExecute` methods
|
|
22
|
+
are override-able.
|
|
23
|
+
- Removed erroneous finalizer cleanup in `Napi::ThreadSafeFunction`.
|
|
24
|
+
- Disabled cahcing in `Napi::ArrayBuffer`.
|
|
25
|
+
- Explicitly disallow assign and copy operator.
|
|
26
|
+
- Some minor corrections and improvements.
|
|
13
27
|
|
|
14
|
-
####
|
|
15
|
-
|
|
16
|
-
- Updated `Napi::BigInt` test for recent change in core.
|
|
17
|
-
|
|
18
|
-
### Commmits
|
|
19
|
-
|
|
20
|
-
* [[`5abf60257d`](https://github.com/nodejs/node-addon-api/commit/5abf60257d)] - Merge pull request #723 from gabrielschulhof/backport-4e885069-pr-475 (Nicola Del Gobbo)
|
|
21
|
-
* [[`470f130666`](https://github.com/nodejs/node-addon-api/commit/470f130666)] - **objectwrap**: avoid double-free on old Node.js (Gabriel Schulhof)
|
|
22
|
-
* [[`81e2eac7ba`](https://github.com/nodejs/node-addon-api/commit/81e2eac7ba)] - **test**: update BigInt test for recent change in core (Michael Dawson) [#649](https://github.com/nodejs/node-addon-api/pull/649)
|
|
23
|
-
* [[`204f07252c`](https://github.com/nodejs/node-addon-api/commit/204f07252c)] - **objectwrap**: remove wrap only on failure (Gabriel Schulhof)
|
|
24
|
-
* [[`a552a384dd`](https://github.com/nodejs/node-addon-api/commit/a552a384dd)] - **src**: call `napi\_remove\_wrap()` in `ObjectWrap` dtor (Anna Henningsen) [#475](https://github.com/nodejs/node-addon-api/pull/475)
|
|
25
|
-
* [[`1a51067438`](https://github.com/nodejs/node-addon-api/commit/1a51067438)] - **objectwrap**: gracefully handle constructor exceptions (Gabriel Schulhof)
|
|
26
|
-
|
|
27
|
-
## 2020-06-02 Version 2.0.1, @NickNaso
|
|
28
|
+
#### Documentation
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
- Updated documentation for `Napi::Object`.
|
|
31
|
+
- Updated documentation for `Napi::Function`.
|
|
32
|
+
- Updated documentation for `Napi::ObjectWrap`.
|
|
33
|
+
- Added documentation on how to add benchmark.
|
|
34
|
+
- Added documentation for `Napi::AsyncProgressQueueWorker`.
|
|
35
|
+
- Added suggestion about tags to use on NPM.
|
|
36
|
+
- Added reference to N-API badges.
|
|
37
|
+
- Some minor corrections all over the documentation.
|
|
30
38
|
|
|
31
|
-
####
|
|
39
|
+
#### TEST
|
|
32
40
|
|
|
33
|
-
-
|
|
41
|
+
- Updated test cases for `Napi::Object`.
|
|
42
|
+
- Updated test cases for `Napi::Function`.
|
|
43
|
+
- Updated test cases for `Napi::ObjectWrap`.
|
|
44
|
+
- Updated test cases for `Napi::Env`.
|
|
45
|
+
- Added test cases for `Napi::AsyncProgressQueueWorker`.
|
|
46
|
+
- Some minor corrections all over the test suite.
|
|
34
47
|
|
|
35
|
-
###
|
|
48
|
+
### Commits
|
|
36
49
|
|
|
37
|
-
* [[`
|
|
50
|
+
* [[`187318e37f`](https://github.com/nodejs/node-addon-api/commit/187318e37f)] - **doc**: Removed references to Node.js lower than 10.x. (#709) (Nicola Del Gobbo)
|
|
51
|
+
* [[`9c9accfbbe`](https://github.com/nodejs/node-addon-api/commit/9c9accfbbe)] - **src**: add support for addon instance data (Gabriel Schulhof) [#663](https://github.com/nodejs/node-addon-api/pull/663)
|
|
52
|
+
* [[`82a96502a4`](https://github.com/nodejs/node-addon-api/commit/82a96502a4)] - **src**: change guards to NAPI\_VERSION \> 5 (Gabriel Schulhof) [#697](https://github.com/nodejs/node-addon-api/pull/697)
|
|
53
|
+
* [[`a64e8a5641`](https://github.com/nodejs/node-addon-api/commit/a64e8a5641)] - **ci**: move travis from 13 to 14 (#707) (Gabriel Schulhof)
|
|
54
|
+
* [[`4de23c9d6b`](https://github.com/nodejs/node-addon-api/commit/4de23c9d6b)] - **doc**: fix support bigint64/biguint64 guards (Yulong Wang) [#705](https://github.com/nodejs/node-addon-api/pull/705)
|
|
55
|
+
* [[`fedc8195e3`](https://github.com/nodejs/node-addon-api/commit/fedc8195e3)] - **doc**: fix semicolon missing in async\_worker.md (Azlan Mukhtar) [#701](https://github.com/nodejs/node-addon-api/pull/701)
|
|
56
|
+
* [[`cdb662506c`](https://github.com/nodejs/node-addon-api/commit/cdb662506c)] - **doc**: fix typo in bigint.md (#700) (Kelvin)
|
|
57
|
+
* [[`e1a827ae29`](https://github.com/nodejs/node-addon-api/commit/e1a827ae29)] - **src**: fix AsyncProgressQueueWorker compilation (#696) (Gabriel Schulhof) [#696](https://github.com/nodejs/node-addon-api/pull/696)
|
|
58
|
+
* [[`2c3d5df463`](https://github.com/nodejs/node-addon-api/commit/2c3d5df463)] - Merge pull request #692 from kelvinhammond/patch-1 (Nicola Del Gobbo)
|
|
59
|
+
* [[`623e876949`](https://github.com/nodejs/node-addon-api/commit/623e876949)] - Merge pull request #688 from NickNaso/badges (Nicola Del Gobbo)
|
|
60
|
+
* [[`6c97913d1f`](https://github.com/nodejs/node-addon-api/commit/6c97913d1f)] - Fix minor typo in object\_lifetime\_management.md (Kelvin)
|
|
61
|
+
* [[`6b8dd47c55`](https://github.com/nodejs/node-addon-api/commit/6b8dd47c55)] - Added badge section to documentation. (NickNaso)
|
|
62
|
+
* [[`89e62a9154`](https://github.com/nodejs/node-addon-api/commit/89e62a9154)] - **doc**: recommend tags of addon helpers (legendecas) [#683](https://github.com/nodejs/node-addon-api/pull/683)
|
|
63
|
+
* [[`ab018444ae`](https://github.com/nodejs/node-addon-api/commit/ab018444ae)] - **src**: implement AsyncProgressQueueWorker (legendecas) [#585](https://github.com/nodejs/node-addon-api/pull/585)
|
|
64
|
+
* [[`d43da6ac2b`](https://github.com/nodejs/node-addon-api/commit/d43da6ac2b)] - **doc**: add @legendecas to active member list (legendecas)
|
|
65
|
+
* [[`cb498bbe7f`](https://github.com/nodejs/node-addon-api/commit/cb498bbe7f)] - **doc**: Add Napi::BigInt::New() overload for uint64\_t (ikokostya)
|
|
66
|
+
* [[`baaaa8452c`](https://github.com/nodejs/node-addon-api/commit/baaaa8452c)] - **doc**: link threadsafe function from JS function (legendecas)
|
|
67
|
+
* [[`7f56a78ff7`](https://github.com/nodejs/node-addon-api/commit/7f56a78ff7)] - **objectwrap**: remove wrap only on failure (Gabriel Schulhof)
|
|
68
|
+
* [[`4d816183da`](https://github.com/nodejs/node-addon-api/commit/4d816183da)] - **doc**: fix example code (András Timár, Dr) [#657](https://github.com/nodejs/node-addon-api/pull/657)
|
|
69
|
+
* [[`7ac6e21801`](https://github.com/nodejs/node-addon-api/commit/7ac6e21801)] - **gyp**: fix gypfile name in index.js (Anna Henningsen) [#658](https://github.com/nodejs/node-addon-api/pull/658)
|
|
70
|
+
* [[`46484202ca`](https://github.com/nodejs/node-addon-api/commit/46484202ca)] - **test**: user data in function property descriptor (Kevin Eady) [#652](https://github.com/nodejs/node-addon-api/pull/652)
|
|
71
|
+
* [[`0f8d730483`](https://github.com/nodejs/node-addon-api/commit/0f8d730483)] - **doc**: fix syntax error in example (András Timár, Dr) [#650](https://github.com/nodejs/node-addon-api/pull/650)
|
|
72
|
+
* [[`4e885069f1`](https://github.com/nodejs/node-addon-api/commit/4e885069f1)] - **src**: call `napi\_remove\_wrap()` in `ObjectWrap` dtor (Anna Henningsen) [#475](https://github.com/nodejs/node-addon-api/pull/475)
|
|
73
|
+
* [[`2fde5c3ca3`](https://github.com/nodejs/node-addon-api/commit/2fde5c3ca3)] - **test**: update BigInt test for recent change in core (Michael Dawson) [#649](https://github.com/nodejs/node-addon-api/pull/649)
|
|
74
|
+
* [[`e8935bd8d9`](https://github.com/nodejs/node-addon-api/commit/e8935bd8d9)] - **test**: add test for own properties on ObjectWrap (Guenter Sandner) [#645](https://github.com/nodejs/node-addon-api/pull/645)
|
|
75
|
+
* [[`23ff7f0b24`](https://github.com/nodejs/node-addon-api/commit/23ff7f0b24)] - **src**: make OnWorkComplete and OnExecute override-able (legendecas) [#589](https://github.com/nodejs/node-addon-api/pull/589)
|
|
76
|
+
* [[`86384f94d3`](https://github.com/nodejs/node-addon-api/commit/86384f94d3)] - **objectwrap**: gracefully handle constructor exceptions (Gabriel Schulhof)
|
|
77
|
+
* [[`9af69da01f`](https://github.com/nodejs/node-addon-api/commit/9af69da01f)] - remove N-API implementation, v6.x and v8.x support (Gabriel Schulhof) [#643](https://github.com/nodejs/node-addon-api/pull/643)
|
|
78
|
+
* [[`920d544779`](https://github.com/nodejs/node-addon-api/commit/920d544779)] - **benchmark**: add templated version of Function (Gabriel Schulhof) [#637](https://github.com/nodejs/node-addon-api/pull/637)
|
|
79
|
+
* [[`03759f7759`](https://github.com/nodejs/node-addon-api/commit/03759f7759)] - ignore benchmark built archives (legendecas) [#631](https://github.com/nodejs/node-addon-api/pull/631)
|
|
80
|
+
* [[`5eeabb0214`](https://github.com/nodejs/node-addon-api/commit/5eeabb0214)] - **tsfn**: Remove erroneous finalizer cleanup (Kevin Eady) [#636](https://github.com/nodejs/node-addon-api/pull/636)
|
|
81
|
+
* [[`9e0e0f31e4`](https://github.com/nodejs/node-addon-api/commit/9e0e0f31e4)] - **src**: remove unnecessary forward declarations (Gabriel Schulhof) [#633](https://github.com/nodejs/node-addon-api/pull/633)
|
|
82
|
+
* [[`79deefb6f3`](https://github.com/nodejs/node-addon-api/commit/79deefb6f3)] - **src**: explicitly disallow assign and copy (legendecas) [#590](https://github.com/nodejs/node-addon-api/pull/590)
|
|
83
|
+
* [[`af50ac281b`](https://github.com/nodejs/node-addon-api/commit/af50ac281b)] - **error**: do not replace pending exception (Gabriel Schulhof) [#629](https://github.com/nodejs/node-addon-api/pull/629)
|
|
84
|
+
* [[`b72f1d6978`](https://github.com/nodejs/node-addon-api/commit/b72f1d6978)] - Disable caching in ArrayBuffer (Tobias Nießen) [#611](https://github.com/nodejs/node-addon-api/pull/611)
|
|
85
|
+
* [[`0e7483eb7b`](https://github.com/nodejs/node-addon-api/commit/0e7483eb7b)] - Fix code format in tests (Tobias Nießen) [#617](https://github.com/nodejs/node-addon-api/pull/617)
|
|
86
|
+
* [[`6a0646356d`](https://github.com/nodejs/node-addon-api/commit/6a0646356d)] - add benchmarking framework (Gabriel Schulhof) [#623](https://github.com/nodejs/node-addon-api/pull/623)
|
|
87
|
+
* [[`ffc71edd54`](https://github.com/nodejs/node-addon-api/commit/ffc71edd54)] - Add Env::RunScript (Tobias Nießen) [#616](https://github.com/nodejs/node-addon-api/pull/616)
|
|
88
|
+
* [[`a1b106066e`](https://github.com/nodejs/node-addon-api/commit/a1b106066e)] - **src**: add templated function factories (Gabriel Schulhof) [#608](https://github.com/nodejs/node-addon-api/pull/608)
|
|
89
|
+
* [[`c584343217`](https://github.com/nodejs/node-addon-api/commit/c584343217)] - Add GetPropertyNames, HasOwnProperty, Delete (#615) (Tobias Nießen) [#615](https://github.com/nodejs/node-addon-api/pull/615)
|
|
90
|
+
* [[`3acc4b32f5`](https://github.com/nodejs/node-addon-api/commit/3acc4b32f5)] - Fix std::string encoding (#619) (Tobias Nießen) [#619](https://github.com/nodejs/node-addon-api/pull/619)
|
|
91
|
+
* [[`e71d0eadcc`](https://github.com/nodejs/node-addon-api/commit/e71d0eadcc)] - \[doc\] Fixed links to array documentation (#613) (Nicola Del Gobbo)
|
|
92
|
+
* [[`3dfb1f0591`](https://github.com/nodejs/node-addon-api/commit/3dfb1f0591)] - Change "WG" to "team" (Tobias Nießen)
|
|
93
|
+
* [[`ce91e14860`](https://github.com/nodejs/node-addon-api/commit/ce91e14860)] - **objectwrap**: add template methods (Dmitry Ashkadov) [#604](https://github.com/nodejs/node-addon-api/pull/604)
|
|
94
|
+
* [[`cfa71b60f7`](https://github.com/nodejs/node-addon-api/commit/cfa71b60f7)] - **object**: add templated property descriptors (Gabriel Schulhof) [#610](https://github.com/nodejs/node-addon-api/pull/610)
|
|
95
|
+
* [[`734725e971`](https://github.com/nodejs/node-addon-api/commit/734725e971)] - Correctly define copy assignment operators. (Rolf Timmermans)
|
|
38
96
|
|
|
39
97
|
## 2019-11-21 Version 2.0.0, @NickNaso
|
|
40
98
|
|
|
@@ -66,7 +124,7 @@
|
|
|
66
124
|
- Added test cases for `Napi::Date` api.
|
|
67
125
|
- Added test cases for new features added to `Napi::ThreadSafeFunction`.
|
|
68
126
|
|
|
69
|
-
###
|
|
127
|
+
### Commits
|
|
70
128
|
|
|
71
129
|
* [[`c881168d49`](https://github.com/nodejs/node-addon-api/commit/c881168d49)] - **tsfn**: add error checking on GetContext (#583) (Kevin Eady) [#583](https://github.com/nodejs/node-addon-api/pull/583)
|
|
72
130
|
* [[`24d75dd82f`](https://github.com/nodejs/node-addon-api/commit/24d75dd82f)] - Merge pull request #588 from NickNaso/add-asyncprogress-worker-readme (Nicola Del Gobbo)
|
|
@@ -107,7 +165,7 @@
|
|
|
107
165
|
|
|
108
166
|
- Fixed compilation problems that happen on Node.js with N-API version less than 4.
|
|
109
167
|
|
|
110
|
-
###
|
|
168
|
+
### Commits
|
|
111
169
|
|
|
112
170
|
* [[`c20bcbd069`](https://github.com/nodejs/node-addon-api/commit/c20bcbd069)] - Merge pull request #518 from NickNaso/master (Nicola Del Gobbo)
|
|
113
171
|
* [[`6720d57253`](https://github.com/nodejs/node-addon-api/commit/6720d57253)] - Create the native threadsafe\_function for test only for N-API greater than 3. (NickNaso)
|
|
@@ -135,7 +193,7 @@
|
|
|
135
193
|
- Added test case for bool operator.
|
|
136
194
|
- Fixed test case for `Napi::ObjectWrap`.
|
|
137
195
|
|
|
138
|
-
###
|
|
196
|
+
### Commits
|
|
139
197
|
|
|
140
198
|
* [[`717c9ab163`](https://github.com/nodejs/node-addon-api/commit/717c9ab163)] - **AsyncWorker**: add GetResult() method (Kevin Eady) [#512](https://github.com/nodejs/node-addon-api/pull/512)
|
|
141
199
|
* [[`d9d991bbc9`](https://github.com/nodejs/node-addon-api/commit/d9d991bbc9)] - **doc**: add ThreadSafeFunction to main README (#513) (Kevin Eady) [#513](https://github.com/nodejs/node-addon-api/pull/513)
|
|
@@ -172,7 +230,7 @@
|
|
|
172
230
|
|
|
173
231
|
- Some minor corrections all over the documentation.
|
|
174
232
|
|
|
175
|
-
###
|
|
233
|
+
### Commits
|
|
176
234
|
|
|
177
235
|
* [[`83b41c2fe4`](https://github.com/nodejs/node-addon-api/commit/83b41c2fe4)] - Document adding -fvisibility=hidden flag for macOS users (Nicola Del Gobbo) [#460](https://github.com/nodejs/node-addon-api/pull/460)
|
|
178
236
|
* [[`1ed7ad8769`](https://github.com/nodejs/node-addon-api/commit/1ed7ad8769)] - **doc**: correct return type of Int32Value to int32\_t (Bill Gallafent) [#459](https://github.com/nodejs/node-addon-api/pull/459)
|
|
@@ -221,7 +279,7 @@
|
|
|
221
279
|
- Removed unused member on `Napi::CallbackScope`.
|
|
222
280
|
- Enabled `Napi::CallbackScope` only with N-API v3.
|
|
223
281
|
|
|
224
|
-
###
|
|
282
|
+
### Commits
|
|
225
283
|
|
|
226
284
|
* [[`e7cd292a74`](https://github.com/nodejs/node-addon-api/commit/e7cd292a74)] - **src**: remove unused CallbackScope member (Gabriel Schulhof) [#391](https://github.com/nodejs/node-addon-api/pull/391)
|
|
227
285
|
* [[`d47399fe25`](https://github.com/nodejs/node-addon-api/commit/d47399fe25)] - **src**: guard CallbackScope with N-API v3 (Michael Dawson) [#395](https://github.com/nodejs/node-addon-api/pull/395)
|
|
@@ -246,7 +304,7 @@ associated with a callback in place when making certain N-API calls
|
|
|
246
304
|
- Added tests for `Napi::Array` class.
|
|
247
305
|
- Added tests for `Napi::ArrayBuffer` class.
|
|
248
306
|
|
|
249
|
-
###
|
|
307
|
+
### Commits
|
|
250
308
|
|
|
251
309
|
* [[`8ce605c657`](https://github.com/nodejs/node-addon-api/commit/8ce605c657)] - **build**: avoid using package-lock.json (Jaeseok Yoon) [#359](https://github.com/nodejs/node-addon-api/pull/359)
|
|
252
310
|
* [[`fa3a6150b3`](https://github.com/nodejs/node-addon-api/commit/fa3a6150b3)] - **src**: use MakeCallback() -\> Call() in AsyncWorker (Jinho Bang) [#361](https://github.com/nodejs/node-addon-api/pull/361)
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ It is important to remember that *other* Node.js interfaces such as
|
|
|
21
21
|
`libuv` (included in a project via `#include <uv.h>`) are not ABI-stable across
|
|
22
22
|
Node.js major versions. Thus, an addon must use N-API and/or `node-addon-api`
|
|
23
23
|
exclusively and build against a version of Node.js that includes an
|
|
24
|
-
implementation of N-API (meaning
|
|
24
|
+
implementation of N-API (meaning an active LTS version of Node.js) in
|
|
25
25
|
order to benefit from ABI stability across Node.js major versions. Node.js
|
|
26
26
|
provides an [ABI stability guide][] containing a detailed explanation of ABI
|
|
27
27
|
stability in general, and the N-API ABI stability guarantee in particular.
|
|
@@ -42,11 +42,12 @@ to ideas specified in the **ECMA262 Language Specification**.
|
|
|
42
42
|
- **[Examples](#examples)**
|
|
43
43
|
- **[Tests](#tests)**
|
|
44
44
|
- **[More resource and info about native Addons](#resources)**
|
|
45
|
+
- **[Badges](#badges)**
|
|
45
46
|
- **[Code of Conduct](CODE_OF_CONDUCT.md)**
|
|
46
47
|
- **[Contributors](#contributors)**
|
|
47
48
|
- **[License](#license)**
|
|
48
49
|
|
|
49
|
-
## **Current version:
|
|
50
|
+
## **Current version: 3.0.0**
|
|
50
51
|
|
|
51
52
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|
|
52
53
|
|
|
@@ -54,6 +55,13 @@ to ideas specified in the **ECMA262 Language Specification**.
|
|
|
54
55
|
|
|
55
56
|
<a name="setup"></a>
|
|
56
57
|
|
|
58
|
+
node-addon-api is based on [N-API](https://nodejs.org/api/n-api.html) and supports using different N-API versions.
|
|
59
|
+
This allows addons built with it to run with Node.js versions which support the targeted N-API version.
|
|
60
|
+
**However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
|
|
61
|
+
every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
|
|
62
|
+
|
|
63
|
+
The oldest Node.js version supported by the current version of node-addon-api is Node.js 10.x.
|
|
64
|
+
|
|
57
65
|
## Setup
|
|
58
66
|
- [Installation and usage](doc/setup.md)
|
|
59
67
|
- [node-gyp](doc/node-gyp.md)
|
|
@@ -160,26 +168,63 @@ npm run-script dev:incremental
|
|
|
160
168
|
|
|
161
169
|
Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/master/test)**
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
### **Benchmarks**
|
|
164
172
|
|
|
165
|
-
|
|
173
|
+
You can run the available benchmarks using the following command:
|
|
166
174
|
|
|
167
|
-
|
|
168
|
-
|
|
175
|
+
```
|
|
176
|
+
npm run-script benchmark
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
See [benchmark/README.md](benchmark/README.md) for more details about running and adding benchmarks.
|
|
180
|
+
|
|
181
|
+
<a name="resources"></a>
|
|
169
182
|
|
|
170
183
|
### **More resource and info about native Addons**
|
|
171
184
|
- **[C++ Addons](https://nodejs.org/dist/latest/docs/api/addons.html)**
|
|
172
185
|
- **[N-API](https://nodejs.org/dist/latest/docs/api/n-api.html)**
|
|
173
186
|
- **[N-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)**
|
|
174
187
|
|
|
188
|
+
As node-addon-api's core mission is to expose the plain C N-API as C++
|
|
189
|
+
wrappers, tools that facilitate n-api/node-addon-api providing more
|
|
190
|
+
convenient patterns on developing a Node.js add-ons with n-api/node-addon-api
|
|
191
|
+
can be published to NPM as standalone packages. It is also recommended to tag
|
|
192
|
+
such packages with `node-addon-api` to provide more visibility to the community.
|
|
193
|
+
|
|
194
|
+
Quick links to NPM searches: [keywords:node-addon-api](https://www.npmjs.com/search?q=keywords%3Anode-addon-api).
|
|
195
|
+
|
|
196
|
+
<a name="badges"></a>
|
|
197
|
+
|
|
198
|
+
### **Badges**
|
|
199
|
+
|
|
200
|
+
The use of badges is recommended to indicate the minimum version of N-API
|
|
201
|
+
required for the module. This helps to determine which Node.js major versions are
|
|
202
|
+
supported. Addon maintainers can consult the [N-API support matrix][] to determine
|
|
203
|
+
which Node.js versions provide a given N-API version. The following badges are
|
|
204
|
+
available:
|
|
205
|
+
|
|
206
|
+

|
|
207
|
+

|
|
208
|
+

|
|
209
|
+

|
|
210
|
+

|
|
211
|
+

|
|
212
|
+

|
|
213
|
+
|
|
214
|
+
## **Contributing**
|
|
215
|
+
|
|
216
|
+
We love contributions from the community to **node-addon-api**!
|
|
217
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around extending this module.
|
|
218
|
+
|
|
175
219
|
<a name="contributors"></a>
|
|
176
220
|
|
|
177
|
-
##
|
|
221
|
+
## Team members
|
|
178
222
|
|
|
179
223
|
### Active
|
|
180
224
|
| Name | GitHub Link |
|
|
181
225
|
| ------------------- | ----------------------------------------------------- |
|
|
182
226
|
| Anna Henningsen | [addaleax](https://github.com/addaleax) |
|
|
227
|
+
| Chengzhong Wu | [legendecas](https://github.com/legendecas) |
|
|
183
228
|
| Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) |
|
|
184
229
|
| Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) |
|
|
185
230
|
| Jim Schlight | [jschlight](https://github.com/jschlight) |
|
|
@@ -201,3 +246,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around
|
|
|
201
246
|
Licensed under [MIT](./LICENSE.md)
|
|
202
247
|
|
|
203
248
|
[ABI stability guide]: https://nodejs.org/en/docs/guides/abi-stability/
|
|
249
|
+
[N-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Benchmarks
|
|
2
|
+
|
|
3
|
+
## Running the benchmarks
|
|
4
|
+
|
|
5
|
+
From the parent directory, run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run-script benchmark
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The above script supports the following arguments:
|
|
12
|
+
|
|
13
|
+
* `--benchmarks=...`: A semicolon-separated list of benchmark names. These names
|
|
14
|
+
will be mapped to file names in this directory by appending `.js`.
|
|
15
|
+
|
|
16
|
+
## Adding benchmarks
|
|
17
|
+
|
|
18
|
+
The steps below should be followed when adding new benchmarks.
|
|
19
|
+
|
|
20
|
+
0. Decide on a name for the benchmark. This name will be used in several places.
|
|
21
|
+
This example will use the name `new_benchmark`.
|
|
22
|
+
|
|
23
|
+
0. Create files `new_benchmark.cc` and `new_benchmark.js` in this directory.
|
|
24
|
+
|
|
25
|
+
0. Copy an existing benchmark in `binding.gyp` and change the target name prefix
|
|
26
|
+
and the source file name to `new_benchmark`. This should result in two new
|
|
27
|
+
targets which look like this:
|
|
28
|
+
|
|
29
|
+
```gyp
|
|
30
|
+
{
|
|
31
|
+
'target_name': 'new_benchmark',
|
|
32
|
+
'sources': [ 'new_benchmark.cc' ],
|
|
33
|
+
'includes': [ '../except.gypi' ],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
'target_name': 'new_benchmark_noexcept',
|
|
37
|
+
'sources': [ 'new_benchmark.cc' ],
|
|
38
|
+
'includes': [ '../noexcept.gypi' ],
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
There should always be a pair of targets: one bearing the name of the
|
|
43
|
+
benchmark and configured with C++ exceptions enabled, and one bearing the
|
|
44
|
+
same name followed by the suffix `_noexcept` and configured with C++
|
|
45
|
+
exceptions disabled. This will ensure that the benchmark can be written to
|
|
46
|
+
cover both the case where C++ exceptions are enabled and the case where they
|
|
47
|
+
are disabled.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
'target_defaults': { 'includes': ['../common.gypi'] },
|
|
3
|
+
'targets': [
|
|
4
|
+
{
|
|
5
|
+
'target_name': 'function_args',
|
|
6
|
+
'sources': [ 'function_args.cc' ],
|
|
7
|
+
'includes': [ '../except.gypi' ],
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
'target_name': 'function_args_noexcept',
|
|
11
|
+
'sources': [ 'function_args.cc' ],
|
|
12
|
+
'includes': [ '../noexcept.gypi' ],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
'target_name': 'property_descriptor',
|
|
16
|
+
'sources': [ 'property_descriptor.cc' ],
|
|
17
|
+
'includes': [ '../except.gypi' ],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
'target_name': 'property_descriptor_noexcept',
|
|
21
|
+
'sources': [ 'property_descriptor.cc' ],
|
|
22
|
+
'includes': [ '../noexcept.gypi' ],
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#include "napi.h"
|
|
2
|
+
|
|
3
|
+
static napi_value NoArgFunction_Core(napi_env env, napi_callback_info info) {
|
|
4
|
+
(void) env;
|
|
5
|
+
(void) info;
|
|
6
|
+
return nullptr;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static napi_value OneArgFunction_Core(napi_env env, napi_callback_info info) {
|
|
10
|
+
size_t argc = 1;
|
|
11
|
+
napi_value argv;
|
|
12
|
+
if (napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr) != napi_ok) {
|
|
13
|
+
return nullptr;
|
|
14
|
+
}
|
|
15
|
+
(void) argv;
|
|
16
|
+
return nullptr;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static napi_value TwoArgFunction_Core(napi_env env, napi_callback_info info) {
|
|
20
|
+
size_t argc = 2;
|
|
21
|
+
napi_value argv[2];
|
|
22
|
+
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
|
23
|
+
return nullptr;
|
|
24
|
+
}
|
|
25
|
+
(void) argv[0];
|
|
26
|
+
(void) argv[1];
|
|
27
|
+
return nullptr;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static napi_value ThreeArgFunction_Core(napi_env env, napi_callback_info info) {
|
|
31
|
+
size_t argc = 3;
|
|
32
|
+
napi_value argv[3];
|
|
33
|
+
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
|
34
|
+
return nullptr;
|
|
35
|
+
}
|
|
36
|
+
(void) argv[0];
|
|
37
|
+
(void) argv[1];
|
|
38
|
+
(void) argv[2];
|
|
39
|
+
return nullptr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static napi_value FourArgFunction_Core(napi_env env, napi_callback_info info) {
|
|
43
|
+
size_t argc = 4;
|
|
44
|
+
napi_value argv[4];
|
|
45
|
+
if (napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr) != napi_ok) {
|
|
46
|
+
return nullptr;
|
|
47
|
+
}
|
|
48
|
+
(void) argv[0];
|
|
49
|
+
(void) argv[1];
|
|
50
|
+
(void) argv[2];
|
|
51
|
+
(void) argv[3];
|
|
52
|
+
return nullptr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void NoArgFunction(const Napi::CallbackInfo& info) {
|
|
56
|
+
(void) info;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void OneArgFunction(const Napi::CallbackInfo& info) {
|
|
60
|
+
Napi::Value argv0 = info[0]; (void) argv0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void TwoArgFunction(const Napi::CallbackInfo& info) {
|
|
64
|
+
Napi::Value argv0 = info[0]; (void) argv0;
|
|
65
|
+
Napi::Value argv1 = info[1]; (void) argv1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static void ThreeArgFunction(const Napi::CallbackInfo& info) {
|
|
69
|
+
Napi::Value argv0 = info[0]; (void) argv0;
|
|
70
|
+
Napi::Value argv1 = info[1]; (void) argv1;
|
|
71
|
+
Napi::Value argv2 = info[2]; (void) argv2;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static void FourArgFunction(const Napi::CallbackInfo& info) {
|
|
75
|
+
Napi::Value argv0 = info[0]; (void) argv0;
|
|
76
|
+
Napi::Value argv1 = info[1]; (void) argv1;
|
|
77
|
+
Napi::Value argv2 = info[2]; (void) argv2;
|
|
78
|
+
Napi::Value argv3 = info[3]; (void) argv3;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
82
|
+
napi_value no_arg_function, one_arg_function, two_arg_function,
|
|
83
|
+
three_arg_function, four_arg_function;
|
|
84
|
+
napi_status status;
|
|
85
|
+
|
|
86
|
+
status = napi_create_function(env,
|
|
87
|
+
"noArgFunction",
|
|
88
|
+
NAPI_AUTO_LENGTH,
|
|
89
|
+
NoArgFunction_Core,
|
|
90
|
+
nullptr,
|
|
91
|
+
&no_arg_function);
|
|
92
|
+
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
|
93
|
+
|
|
94
|
+
status = napi_create_function(env,
|
|
95
|
+
"oneArgFunction",
|
|
96
|
+
NAPI_AUTO_LENGTH,
|
|
97
|
+
OneArgFunction_Core,
|
|
98
|
+
nullptr,
|
|
99
|
+
&one_arg_function);
|
|
100
|
+
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
|
101
|
+
|
|
102
|
+
status = napi_create_function(env,
|
|
103
|
+
"twoArgFunction",
|
|
104
|
+
NAPI_AUTO_LENGTH,
|
|
105
|
+
TwoArgFunction_Core,
|
|
106
|
+
nullptr,
|
|
107
|
+
&two_arg_function);
|
|
108
|
+
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
|
109
|
+
|
|
110
|
+
status = napi_create_function(env,
|
|
111
|
+
"threeArgFunction",
|
|
112
|
+
NAPI_AUTO_LENGTH,
|
|
113
|
+
ThreeArgFunction_Core,
|
|
114
|
+
nullptr,
|
|
115
|
+
&three_arg_function);
|
|
116
|
+
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
|
117
|
+
|
|
118
|
+
status = napi_create_function(env,
|
|
119
|
+
"fourArgFunction",
|
|
120
|
+
NAPI_AUTO_LENGTH,
|
|
121
|
+
FourArgFunction_Core,
|
|
122
|
+
nullptr,
|
|
123
|
+
&four_arg_function);
|
|
124
|
+
NAPI_THROW_IF_FAILED(env, status, Napi::Object());
|
|
125
|
+
|
|
126
|
+
Napi::Object core = Napi::Object::New(env);
|
|
127
|
+
core["noArgFunction"] = Napi::Value(env, no_arg_function);
|
|
128
|
+
core["oneArgFunction"] = Napi::Value(env, one_arg_function);
|
|
129
|
+
core["twoArgFunction"] = Napi::Value(env, two_arg_function);
|
|
130
|
+
core["threeArgFunction"] = Napi::Value(env, three_arg_function);
|
|
131
|
+
core["fourArgFunction"] = Napi::Value(env, four_arg_function);
|
|
132
|
+
exports["core"] = core;
|
|
133
|
+
|
|
134
|
+
Napi::Object cplusplus = Napi::Object::New(env);
|
|
135
|
+
cplusplus["noArgFunction"] = Napi::Function::New(env, NoArgFunction);
|
|
136
|
+
cplusplus["oneArgFunction"] = Napi::Function::New(env, OneArgFunction);
|
|
137
|
+
cplusplus["twoArgFunction"] = Napi::Function::New(env, TwoArgFunction);
|
|
138
|
+
cplusplus["threeArgFunction"] = Napi::Function::New(env, ThreeArgFunction);
|
|
139
|
+
cplusplus["fourArgFunction"] = Napi::Function::New(env, FourArgFunction);
|
|
140
|
+
exports["cplusplus"] = cplusplus;
|
|
141
|
+
|
|
142
|
+
Napi::Object templated = Napi::Object::New(env);
|
|
143
|
+
templated["noArgFunction"] = Napi::Function::New<NoArgFunction>(env);
|
|
144
|
+
templated["oneArgFunction"] = Napi::Function::New<OneArgFunction>(env);
|
|
145
|
+
templated["twoArgFunction"] = Napi::Function::New<TwoArgFunction>(env);
|
|
146
|
+
templated["threeArgFunction"] = Napi::Function::New<ThreeArgFunction>(env);
|
|
147
|
+
templated["fourArgFunction"] = Napi::Function::New<FourArgFunction>(env);
|
|
148
|
+
exports["templated"] = templated;
|
|
149
|
+
|
|
150
|
+
return exports;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const Benchmark = require('benchmark');
|
|
3
|
+
const addonName = path.basename(__filename, '.js');
|
|
4
|
+
|
|
5
|
+
[ addonName, addonName + '_noexcept' ]
|
|
6
|
+
.forEach((addonName) => {
|
|
7
|
+
const rootAddon = require(`./build/Release/${addonName}`);
|
|
8
|
+
const implems = Object.keys(rootAddon);
|
|
9
|
+
const anObject = {};
|
|
10
|
+
|
|
11
|
+
console.log(`${addonName}: `);
|
|
12
|
+
|
|
13
|
+
console.log('no arguments:');
|
|
14
|
+
implems.reduce((suite, implem) => {
|
|
15
|
+
const fn = rootAddon[implem].noArgFunction;
|
|
16
|
+
return suite.add(implem, () => fn());
|
|
17
|
+
}, new Benchmark.Suite)
|
|
18
|
+
.on('cycle', (event) => console.log(String(event.target)))
|
|
19
|
+
.run();
|
|
20
|
+
|
|
21
|
+
console.log('one argument:');
|
|
22
|
+
implems.reduce((suite, implem) => {
|
|
23
|
+
const fn = rootAddon[implem].oneArgFunction;
|
|
24
|
+
return suite.add(implem, () => fn('x'));
|
|
25
|
+
}, new Benchmark.Suite)
|
|
26
|
+
.on('cycle', (event) => console.log(String(event.target)))
|
|
27
|
+
.run();
|
|
28
|
+
|
|
29
|
+
console.log('two arguments:');
|
|
30
|
+
implems.reduce((suite, implem) => {
|
|
31
|
+
const fn = rootAddon[implem].twoArgFunction;
|
|
32
|
+
return suite.add(implem, () => fn('x', 12));
|
|
33
|
+
}, new Benchmark.Suite)
|
|
34
|
+
.on('cycle', (event) => console.log(String(event.target)))
|
|
35
|
+
.run();
|
|
36
|
+
|
|
37
|
+
console.log('three arguments:');
|
|
38
|
+
implems.reduce((suite, implem) => {
|
|
39
|
+
const fn = rootAddon[implem].threeArgFunction;
|
|
40
|
+
return suite.add(implem, () => fn('x', 12, true));
|
|
41
|
+
}, new Benchmark.Suite)
|
|
42
|
+
.on('cycle', (event) => console.log(String(event.target)))
|
|
43
|
+
.run();
|
|
44
|
+
|
|
45
|
+
console.log('four arguments:');
|
|
46
|
+
implems.reduce((suite, implem) => {
|
|
47
|
+
const fn = rootAddon[implem].fourArgFunction;
|
|
48
|
+
return suite.add(implem, () => fn('x', 12, true, anObject));
|
|
49
|
+
}, new Benchmark.Suite)
|
|
50
|
+
.on('cycle', (event) => console.log(String(event.target)))
|
|
51
|
+
.run();
|
|
52
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { readdirSync } = require('fs');
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
let benchmarks = [];
|
|
8
|
+
|
|
9
|
+
if (!!process.env.npm_config_benchmarks) {
|
|
10
|
+
benchmarks = process.env.npm_config_benchmarks
|
|
11
|
+
.split(';')
|
|
12
|
+
.map((item) => (item + '.js'));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Run each file in this directory or the list given on the command line except
|
|
16
|
+
// index.js as a Node.js process.
|
|
17
|
+
(benchmarks.length > 0 ? benchmarks : readdirSync(__dirname))
|
|
18
|
+
.filter((item) => (item !== 'index.js' && item.match(/\.js$/)))
|
|
19
|
+
.map((item) => path.join(__dirname, item))
|
|
20
|
+
.forEach((item) => {
|
|
21
|
+
const child = spawnSync(process.execPath, [
|
|
22
|
+
'--expose-gc',
|
|
23
|
+
item
|
|
24
|
+
], { stdio: 'inherit' });
|
|
25
|
+
if (child.signal) {
|
|
26
|
+
console.error(`Tests aborted with ${child.signal}`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
} else {
|
|
29
|
+
process.exitCode = child.status;
|
|
30
|
+
}
|
|
31
|
+
if (child.status !== 0) {
|
|
32
|
+
process.exit(process.exitCode);
|
|
33
|
+
}
|
|
34
|
+
});
|