node-addon-api 1.6.2 → 1.6.3
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/CHANGELOG.md +43 -4
- package/README.md +27 -6
- package/doc/async_worker.md +9 -0
- package/doc/class_property_descriptor.md +2 -2
- package/doc/creating_a_release.md +37 -16
- package/doc/error_handling.md +31 -0
- package/doc/function_reference.md +2 -2
- package/doc/number.md +5 -5
- package/doc/object.md +3 -3
- package/doc/object_reference.md +2 -2
- package/doc/object_wrap.md +1 -1
- package/doc/property_descriptor.md +1 -1
- package/doc/setup.md +13 -2
- package/napi-inl.deprecated.h +2 -2
- package/napi-inl.h +64 -73
- package/napi.h +67 -9
- package/package.json +13 -1
- package/tools/README.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
# node-addon-api Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2019-04-03 Version 1.6.3, @NickNaso
|
|
4
|
+
|
|
5
|
+
### Notable changes:
|
|
6
|
+
|
|
7
|
+
#### API
|
|
8
|
+
|
|
9
|
+
- Added `SuppressDestruct` method to `Napi::AsyncWorker`.
|
|
10
|
+
- Added new build targets for debug.
|
|
11
|
+
- Exposed macros that throw errors.
|
|
12
|
+
- Fixed memory leaks caused by callback data when a napi error occurs.
|
|
13
|
+
- Fixed missing `void *data` usage in `Napi::PropertyDescriptors`.
|
|
14
|
+
|
|
15
|
+
#### Documentation
|
|
16
|
+
|
|
17
|
+
- Some minor corrections all over the documentation
|
|
18
|
+
|
|
19
|
+
### Commmits
|
|
20
|
+
|
|
21
|
+
* [[`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)
|
|
22
|
+
* [[`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)
|
|
23
|
+
* [[`b0f6b601aa`](https://github.com/nodejs/node-addon-api/commit/b0f6b601aa)] - **src**: add AsyncWorker destruction suppression (Gabriel Schulhof) [#407](https://github.com/nodejs/node-addon-api/pull/407)
|
|
24
|
+
* [[`72b1975cff`](https://github.com/nodejs/node-addon-api/commit/72b1975cff)] - **doc**: fix links to the Property Descriptor docs (Ryuichi Okumura) [#458](https://github.com/nodejs/node-addon-api/pull/458)
|
|
25
|
+
* [[`fcfc612728`](https://github.com/nodejs/node-addon-api/commit/fcfc612728)] - **build**: new build targets for debug purposes (Jinho Bang) [#186](https://github.com/nodejs/node-addon-api/pull/186)
|
|
26
|
+
* [[`c629553cd7`](https://github.com/nodejs/node-addon-api/commit/c629553cd7)] - **doc**: minor doc corrections and clarifications (Bruce A. MacNaughton) [#426](https://github.com/nodejs/node-addon-api/pull/426)
|
|
27
|
+
* [[`7b87e0b999`](https://github.com/nodejs/node-addon-api/commit/7b87e0b999)] - **doc**: update number.md (Bernardo Heynemann) [#436](https://github.com/nodejs/node-addon-api/pull/436)
|
|
28
|
+
* [[`fcf173d2a1`](https://github.com/nodejs/node-addon-api/commit/fcf173d2a1)] - **src**: expose macros that throw errors (Gabriel Schulhof) [#448](https://github.com/nodejs/node-addon-api/pull/448)
|
|
29
|
+
* [[`b409a2f987`](https://github.com/nodejs/node-addon-api/commit/b409a2f987)] - **package**: add npm search keywords (Sam Roberts) [#452](https://github.com/nodejs/node-addon-api/pull/452)
|
|
30
|
+
* [[`0bc7987806`](https://github.com/nodejs/node-addon-api/commit/0bc7987806)] - **doc**: fix references to Weak and Persistent (Jake Barnes) [#428](https://github.com/nodejs/node-addon-api/pull/428)
|
|
31
|
+
* [[`ad6f569f85`](https://github.com/nodejs/node-addon-api/commit/ad6f569f85)] - **doc**: dix typo (Abhishek Kumar Singh) [#435](https://github.com/nodejs/node-addon-api/pull/435)
|
|
32
|
+
* [[`28df833a49`](https://github.com/nodejs/node-addon-api/commit/28df833a49)] - Merge pull request #441 from jschlight/master (Jim Schlight)
|
|
33
|
+
* [[`4921e74d83`](https://github.com/nodejs/node-addon-api/commit/4921e74d83)] - Rearranges names to be alphabetical (Jim Schlight)
|
|
34
|
+
* [[`48220335b0`](https://github.com/nodejs/node-addon-api/commit/48220335b0)] - Membership review update (Jim Schlight)
|
|
35
|
+
* [[`44f0695533`](https://github.com/nodejs/node-addon-api/commit/44f0695533)] - Merge pull request #394 from NickNaso/create\_release (Nicola DelGobbo)
|
|
36
|
+
* [[`fa49d68416`](https://github.com/nodejs/node-addon-api/commit/fa49d68416)] - **doc**: fix some `Finalizer` signatures (Philipp Renoth) [#414](https://github.com/nodejs/node-addon-api/pull/414)
|
|
37
|
+
* [[`020ac4a628`](https://github.com/nodejs/node-addon-api/commit/020ac4a628)] - **src**: make `Object::GetPropertyNames()` const (Philipp Renoth)[#415](https://github.com/nodejs/node-addon-api/pull/415)
|
|
38
|
+
* [[`91eaa6f4cb`](https://github.com/nodejs/node-addon-api/commit/91eaa6f4cb)] - **src**: fix callbackData leaks on error napi status (Philipp Renoth) [#417](https://github.com/nodejs/node-addon-api/pull/417)
|
|
39
|
+
* [[`0b40275752`](https://github.com/nodejs/node-addon-api/commit/0b40275752)] - **src**: fix noexcept control flow issues (Philipp Renoth) [#420](https://github.com/nodejs/node-addon-api/pull/420)
|
|
40
|
+
* [[`c1ff2936f9`](https://github.com/nodejs/node-addon-api/commit/c1ff2936f9)] - **src**: fix missing void\*data usage in PropertyDescriptors (Luciano Martorella) [#374](https://github.com/nodejs/node-addon-api/pull/374)
|
|
41
|
+
|
|
42
|
+
## 2018-11-29 Version 1.6.2, @NickNaso
|
|
4
43
|
|
|
5
44
|
### Notable changes:
|
|
6
45
|
|
|
@@ -12,7 +51,7 @@
|
|
|
12
51
|
|
|
13
52
|
* [[`07a0fc4e95`](https://github.com/nodejs/node-addon-api/commit/07a0fc4e95)] - **src**: fix selection logic for 6.x (Michael Dawson) [#402](https://github.com/nodejs/node-addon-api/pull/402)
|
|
14
53
|
|
|
15
|
-
## 2018-11-14 Version 1.6.1
|
|
54
|
+
## 2018-11-14 Version 1.6.1, @NickNaso
|
|
16
55
|
|
|
17
56
|
### Notable changes:
|
|
18
57
|
|
|
@@ -33,7 +72,7 @@
|
|
|
33
72
|
* [[`29a0262ab9`](https://github.com/nodejs/node-addon-api/commit/29a0262ab9)] - **doc**: fix typo (Dongjin Na) [#385](https://github.com/nodejs/node-addon-api/pull/385)
|
|
34
73
|
* [[`b6dc15b88d`](https://github.com/nodejs/node-addon-api/commit/b6dc15b88d)] - **doc**: make links point to node-addon-examples repo (Nicola Del Gobbo) [#389](https://github.com/nodejs/node-addon-api/pull/389)
|
|
35
74
|
|
|
36
|
-
## 2018-11-02 Version 1.6.0
|
|
75
|
+
## 2018-11-02 Version 1.6.0, @NickNaso
|
|
37
76
|
|
|
38
77
|
### Notable changes:
|
|
39
78
|
|
|
@@ -63,7 +102,7 @@ associated with a callback in place when making certain N-API calls
|
|
|
63
102
|
* [[`fd65078e3c`](https://github.com/nodejs/node-addon-api/commit/fd65078e3c)] - README.md: link to new ABI stability guide (Gabriel Schulhof) [#367](https://github.com/nodejs/node-addon-api/pull/367)
|
|
64
103
|
* [[`ffebf9ba9a`](https://github.com/nodejs/node-addon-api/commit/ffebf9ba9a)] - Updates for release 1.5.0 (NickNaso)
|
|
65
104
|
|
|
66
|
-
## 2018-10-03 Version 1.5.0
|
|
105
|
+
## 2018-10-03 Version 1.5.0, @NickNaso
|
|
67
106
|
|
|
68
107
|
### Notable changes:
|
|
69
108
|
|
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ to ideas specified in the **ECMA262 Language Specification**.
|
|
|
46
46
|
- **[Contributors](#contributors)**
|
|
47
47
|
- **[License](#license)**
|
|
48
48
|
|
|
49
|
-
## **Current version: 1.6.
|
|
49
|
+
## **Current version: 1.6.3**
|
|
50
50
|
|
|
51
51
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|
|
52
52
|
|
|
@@ -141,6 +141,20 @@ npm install
|
|
|
141
141
|
npm test --disable-deprecated
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
### **Debug**
|
|
145
|
+
|
|
146
|
+
To run the **node-addon-api** tests with `--debug` option:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
npm run-script dev
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
If you want faster build, you might use the following option:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
npm run-script dev:incremental
|
|
156
|
+
```
|
|
157
|
+
|
|
144
158
|
Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/master/test)**
|
|
145
159
|
|
|
146
160
|
<a name="resources"></a>
|
|
@@ -152,20 +166,27 @@ Take a look and get inspired by our **[test suite](https://github.com/nodejs/nod
|
|
|
152
166
|
|
|
153
167
|
<a name="contributors"></a>
|
|
154
168
|
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
## WG Members / Collaborators
|
|
170
|
+
|
|
171
|
+
### Active
|
|
172
|
+
| Name | GitHub Link |
|
|
157
173
|
| ------------------- | ----------------------------------------------------- |
|
|
158
174
|
| Anna Henningsen | [addaleax](https://github.com/addaleax) |
|
|
159
175
|
| Arunesh Chandra | [aruneshchandra](https://github.com/aruneshchandra) |
|
|
160
|
-
| Benjamin Byholm | [kkoopa](https://github.com/kkoopa) |
|
|
161
176
|
| Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) |
|
|
162
177
|
| Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) |
|
|
163
|
-
|
|
|
178
|
+
| Jim Schlight | [jschlight](https://github.com/jschlight) |
|
|
164
179
|
| Michael Dawson | [mhdawson](https://github.com/mhdawson) |
|
|
165
180
|
| Nicola Del Gobbo | [NickNaso](https://github.com/NickNaso) |
|
|
166
|
-
| Sampson Gao | [sampsongao](https://github.com/sampsongao) |
|
|
167
181
|
| Taylor Woll | [boingoing](https://github.com/boingoing) |
|
|
168
182
|
|
|
183
|
+
### Emeritus
|
|
184
|
+
| Name | GitHub Link |
|
|
185
|
+
| ------------------- | ----------------------------------------------------- |
|
|
186
|
+
| Benjamin Byholm | [kkoopa](https://github.com/kkoopa) |
|
|
187
|
+
| Jason Ginchereau | [jasongin](https://github.com/jasongin) |
|
|
188
|
+
| Sampson Gao | [sampsongao](https://github.com/sampsongao) |
|
|
189
|
+
|
|
169
190
|
<a name="license"></a>
|
|
170
191
|
|
|
171
192
|
Licensed under [MIT](./LICENSE.md)
|
package/doc/async_worker.md
CHANGED
|
@@ -66,6 +66,15 @@ the computation that happened in the `Napi::AsyncWorker::Execute` method, unless
|
|
|
66
66
|
the default implementation of `Napi::AsyncWorker::OnOK` or
|
|
67
67
|
`Napi::AsyncWorker::OnError` is overridden.
|
|
68
68
|
|
|
69
|
+
### SuppressDestruct
|
|
70
|
+
|
|
71
|
+
```cpp
|
|
72
|
+
void Napi::AsyncWorker::SuppressDestruct();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Prevents the destruction of the `Napi::AsyncWorker` instance upon completion of
|
|
76
|
+
the `Napi::AsyncWorker::OnOK` callback.
|
|
77
|
+
|
|
69
78
|
### SetError
|
|
70
79
|
|
|
71
80
|
Sets the error message for the error that happened during the execution. Setting
|
|
@@ -8,7 +8,7 @@ This prevents using descriptors from a different class when defining a new class
|
|
|
8
8
|
|
|
9
9
|
## Methods
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Constructor
|
|
12
12
|
|
|
13
13
|
Creates new instance of `Napi::ClassPropertyDescriptor` descriptor object.
|
|
14
14
|
|
|
@@ -33,4 +33,4 @@ Returns the original N-API `napi_property_descriptor` wrapped inside the `Napi::
|
|
|
33
33
|
operator const napi_property_descriptor&() const { return _desc; }
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
Returns the original N-API `napi_property_descriptor` wrapped inside the `Napi::ClassPropertyDescriptor`
|
|
36
|
+
Returns the original N-API `napi_property_descriptor` wrapped inside the `Napi::ClassPropertyDescriptor`
|
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
# Creating a release
|
|
2
2
|
|
|
3
|
-
Only collaborators in npm for node-addon-api can create releases.
|
|
3
|
+
Only collaborators in npm for **node-addon-api** can create releases.
|
|
4
4
|
If you want to be able to do releases ask one of the existing
|
|
5
|
-
collaborators to add you.
|
|
5
|
+
collaborators to add you. If necessary you can ask the build
|
|
6
6
|
Working Group who manages the Node.js npm user to add you if
|
|
7
7
|
there are no other active collaborators.
|
|
8
8
|
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
Before to start creating a new release check if you have installed the following
|
|
12
|
+
tools:
|
|
13
|
+
|
|
14
|
+
* [Changelog maker](https://www.npmjs.com/package/changelog-maker)
|
|
15
|
+
|
|
16
|
+
If not please follow the instruction reported in the tool's documentation to
|
|
17
|
+
install it.
|
|
18
|
+
|
|
19
|
+
## Publish new release
|
|
20
|
+
|
|
9
21
|
These are the steps to follow to create a new release:
|
|
10
22
|
|
|
11
|
-
* Open an issue in the node-addon-api repo documenting
|
|
12
|
-
|
|
13
|
-
time to comment or suggest PRs that should land first.
|
|
23
|
+
* Open an issue in the **node-addon-api** repo documenting the intent to create a
|
|
24
|
+
new release. Give people some time to comment or suggest PRs that should land first.
|
|
14
25
|
|
|
15
26
|
* Validate all tests pass by running npm test on master.
|
|
16
27
|
|
|
17
|
-
*
|
|
18
|
-
to validate tests pass for latest 9, 8, 6, 4 releases
|
|
19
|
-
(note there are still some issues on SmartOS and
|
|
20
|
-
Windows in the testing).
|
|
28
|
+
* Update the version in **package.json** appropriately.
|
|
21
29
|
|
|
22
|
-
* Update the
|
|
30
|
+
* Update the [README.md](https://github.com/nodejs/node-addon-api/blob/master/README.md)
|
|
31
|
+
to show the new version as the latest.
|
|
23
32
|
|
|
24
|
-
*
|
|
33
|
+
* Generate the changelog for the new version using **changelog maker** tool. From
|
|
34
|
+
the route folder of the repo launch the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
> changelog-maker
|
|
38
|
+
```
|
|
39
|
+
* Use the output generated by **changelog maker** to pdate the [CHANGELOG.md](https://github.com/nodejs/node-addon-api/blob/master/CHANGELOG.md)
|
|
40
|
+
following the style used in publishing the previous release.
|
|
41
|
+
|
|
42
|
+
* Add any new contributors to the "contributors" section in the package.json
|
|
43
|
+
|
|
44
|
+
* Validate all tests pass by running npm test on master.
|
|
25
45
|
|
|
26
|
-
*
|
|
27
|
-
|
|
46
|
+
* Use **[CI](https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api/)**
|
|
47
|
+
to validate tests pass for latest 11, 10, 8, 6 releases (note there are still some issues on SmartOS and
|
|
48
|
+
Windows in the testing).
|
|
28
49
|
|
|
29
50
|
* Do a clean checkout of node-addon-api.
|
|
30
51
|
|
|
@@ -33,9 +54,9 @@ These are the steps to follow to create a new release:
|
|
|
33
54
|
* Create a release in Github (look at existing releases for an example).
|
|
34
55
|
|
|
35
56
|
* Validate that you can run `npm install node-addon-api` successfully
|
|
36
|
-
|
|
57
|
+
and that the correct version is installed.
|
|
37
58
|
|
|
38
|
-
* Comment on the issue opened in the first step that the
|
|
39
|
-
|
|
59
|
+
* Comment on the issue opened in the first step that the release has been created
|
|
60
|
+
and close the issue.
|
|
40
61
|
|
|
41
62
|
* Tweet that the release has been created.
|
package/doc/error_handling.md
CHANGED
|
@@ -153,3 +153,34 @@ if (env.IsExceptionPending()) {
|
|
|
153
153
|
|
|
154
154
|
Since the exception was cleared here, it will not be propagated as a JavaScript
|
|
155
155
|
exception after the native callback returns.
|
|
156
|
+
|
|
157
|
+
## Calling N-API directly from a **node-addon-api** addon
|
|
158
|
+
|
|
159
|
+
**node-addon-api** provides macros for throwing errors in response to non-OK
|
|
160
|
+
`napi_status` results when calling [N-API](https://nodejs.org/docs/latest/api/n-api.html)
|
|
161
|
+
functions from within a native addon. These macros are defined differently
|
|
162
|
+
depending on whether C++ exceptions are enabled or not, but are available for
|
|
163
|
+
use in either case.
|
|
164
|
+
|
|
165
|
+
### `NAPI_THROW(e, ...)`
|
|
166
|
+
|
|
167
|
+
This macro accepts a `Napi::Error`, throws it, and returns the value given as
|
|
168
|
+
the last parameter. If C++ exceptions are enabled (by defining
|
|
169
|
+
`NAPI_CPP_EXCEPTIONS` during the build), the return value will be ignored.
|
|
170
|
+
|
|
171
|
+
### `NAPI_THROW_IF_FAILED(env, status, ...)`
|
|
172
|
+
|
|
173
|
+
This macro accepts a `Napi::Env` and a `napi_status`. It constructs an error
|
|
174
|
+
from the `napi_status`, throws it, and returns the value given as the last
|
|
175
|
+
parameter. If C++ exceptions are enabled (by defining `NAPI_CPP_EXCEPTIONS`
|
|
176
|
+
during the build), the return value will be ignored.
|
|
177
|
+
|
|
178
|
+
### `NAPI_THROW_IF_FAILED_VOID(env, status)`
|
|
179
|
+
|
|
180
|
+
This macro accepts a `Napi::Env` and a `napi_status`. It constructs an error
|
|
181
|
+
from the `napi_status`, throws it, and returns.
|
|
182
|
+
|
|
183
|
+
### `NAPI_FATAL_IF_FAILED(status, location, message)`
|
|
184
|
+
|
|
185
|
+
This macro accepts a `napi_status`, a C string indicating the location where the
|
|
186
|
+
error occurred, and a second C string for the message to display.
|
|
@@ -23,7 +23,7 @@ Creates a "weak" reference to the value, in that the initial reference count is
|
|
|
23
23
|
set to 0.
|
|
24
24
|
|
|
25
25
|
```cpp
|
|
26
|
-
static Napi::FunctionReference Napi::
|
|
26
|
+
static Napi::FunctionReference Napi::Weak(const Napi::Function& value);
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
- `[in] value`: The value which is to be referenced.
|
|
@@ -36,7 +36,7 @@ Creates a "persistent" reference to the value, in that the initial reference
|
|
|
36
36
|
count is set to 1.
|
|
37
37
|
|
|
38
38
|
```cpp
|
|
39
|
-
static Napi::FunctionReference Napi::
|
|
39
|
+
static Napi::FunctionReference Napi::Persistent(const Napi::Function& value);
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
- `[in] value`: The value which is to be referenced.
|
package/doc/number.md
CHANGED
|
@@ -24,8 +24,8 @@ Creates a new instance of a `Napi::Number` object.
|
|
|
24
24
|
Napi::Number(napi_env env, napi_value value);
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::
|
|
28
|
-
- `[in] value`: The
|
|
27
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Number` object.
|
|
28
|
+
- `[in] value`: The JavaScript value holding a number.
|
|
29
29
|
|
|
30
30
|
Returns a non-empty `Napi::Number` object.
|
|
31
31
|
|
|
@@ -36,14 +36,14 @@ Napi::Number(napi_env env, napi_value value);
|
|
|
36
36
|
```cpp
|
|
37
37
|
Napi::Number Napi::Number::New(napi_env env, double value);
|
|
38
38
|
```
|
|
39
|
-
- `[in] env`: The `napi_env` environment in which to construct the `Napi::
|
|
40
|
-
- `[in] value`: The
|
|
39
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Number` object.
|
|
40
|
+
- `[in] value`: The C++ primitive from which to instantiate the `Napi::Number`.
|
|
41
41
|
|
|
42
42
|
Creates a new instance of a `Napi::Number` object.
|
|
43
43
|
|
|
44
44
|
### Int32Value
|
|
45
45
|
|
|
46
|
-
Converts a `Napi::Number` value to a `
|
|
46
|
+
Converts a `Napi::Number` value to a `int32_t` primitive type.
|
|
47
47
|
|
|
48
48
|
```cpp
|
|
49
49
|
Napi::Number::Int32Value() const;
|
package/doc/object.md
CHANGED
|
@@ -108,7 +108,7 @@ Napi::Value Napi::Object::Get(____ key);
|
|
|
108
108
|
```
|
|
109
109
|
- `[in] key`: The name of the property to return the value for.
|
|
110
110
|
|
|
111
|
-
Returns the [`Napi::Value`](value.md) associated with the key property. Returns
|
|
111
|
+
Returns the [`Napi::Value`](value.md) associated with the key property. Returns the value *undefined* if the key does not exist.
|
|
112
112
|
|
|
113
113
|
The `key` can be any of the following types:
|
|
114
114
|
- `napi_value`
|
|
@@ -142,7 +142,7 @@ Note: This is equivalent to the JavaScript instanceof operator.
|
|
|
142
142
|
```cpp
|
|
143
143
|
void Napi::Object::DefineProperty (const Napi::PropertyDescriptor& property);
|
|
144
144
|
```
|
|
145
|
-
- `[in] property`: A [`Napi::PropertyDescriptor`](
|
|
145
|
+
- `[in] property`: A [`Napi::PropertyDescriptor`](property_descriptor.md).
|
|
146
146
|
|
|
147
147
|
Define a property on the object.
|
|
148
148
|
|
|
@@ -151,7 +151,7 @@ Define a property on the object.
|
|
|
151
151
|
```cpp
|
|
152
152
|
void Napi::Object::DefineProperties (____ properties)
|
|
153
153
|
```
|
|
154
|
-
- `[in] properties`: A list of [`Napi::PropertyDescriptor`](
|
|
154
|
+
- `[in] properties`: A list of [`Napi::PropertyDescriptor`](property_descriptor.md). Can be one of the following types:
|
|
155
155
|
- const std::initializer_list<Napi::PropertyDescriptor>&
|
|
156
156
|
- const std::vector<Napi::PropertyDescriptor>&
|
|
157
157
|
|
package/doc/object_reference.md
CHANGED
|
@@ -40,7 +40,7 @@ static Napi::ObjectReference Napi::ObjectReference::New(const Napi::Object& valu
|
|
|
40
40
|
Returns the newly created reference.
|
|
41
41
|
|
|
42
42
|
```cpp
|
|
43
|
-
static Napi::ObjectReference Napi::
|
|
43
|
+
static Napi::ObjectReference Napi::Weak(const Napi::Object& value);
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
Creates a "weak" reference to the value, in that the initial count of number of references is set to 0.
|
|
@@ -50,7 +50,7 @@ Creates a "weak" reference to the value, in that the initial count of number of
|
|
|
50
50
|
Returns the newly created reference.
|
|
51
51
|
|
|
52
52
|
```cpp
|
|
53
|
-
static Napi::ObjectReference Napi::
|
|
53
|
+
static Napi::ObjectReference Napi::Persistent(const Napi::Object& value);
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
Creates a "persistent" reference to the value, in that the initial count of number of references is set to 1.
|
package/doc/object_wrap.md
CHANGED
|
@@ -192,7 +192,7 @@ static Napi::PropertyDescriptor Napi::PropertyDescriptor::Function (
|
|
|
192
192
|
void *data = nullptr);
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
* `[in] env`: The
|
|
195
|
+
* `[in] env`: The environment in which to create this accessor.
|
|
196
196
|
* `[in] name`: The name of the Callable function.
|
|
197
197
|
* `[in] cb`: The function
|
|
198
198
|
* `[in] attributes`: Potential attributes for the getter function.
|
package/doc/setup.md
CHANGED
|
@@ -55,8 +55,19 @@ To use **N-API** in a native module:
|
|
|
55
55
|
```gyp
|
|
56
56
|
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
|
|
57
57
|
```
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
4. If you would like your native addon to support OSX, please also add the
|
|
59
|
+
following settings in the `binding.gyp` file:
|
|
60
|
+
|
|
61
|
+
```gyp
|
|
62
|
+
['OS=="mac"', {
|
|
63
|
+
'cflags+': ['-fvisibility=hidden'],
|
|
64
|
+
'xcode_settings': {
|
|
65
|
+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
|
|
66
|
+
}
|
|
67
|
+
}]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
5. Include `napi.h` in the native module code.
|
|
60
71
|
To ensure only ABI-stable APIs are used, DO NOT include
|
|
61
72
|
`node.h`, `nan.h`, or `v8.h`.
|
|
62
73
|
|
package/napi-inl.deprecated.h
CHANGED
|
@@ -73,7 +73,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(const char* utf8name,
|
|
|
73
73
|
void* /*data*/) {
|
|
74
74
|
typedef details::AccessorCallbackData<Getter, Setter> CbData;
|
|
75
75
|
// TODO: Delete when the function is destroyed
|
|
76
|
-
auto callbackData = new CbData({ getter, setter });
|
|
76
|
+
auto callbackData = new CbData({ getter, setter, nullptr });
|
|
77
77
|
|
|
78
78
|
return PropertyDescriptor({
|
|
79
79
|
utf8name,
|
|
@@ -104,7 +104,7 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
|
|
|
104
104
|
void* /*data*/) {
|
|
105
105
|
typedef details::AccessorCallbackData<Getter, Setter> CbData;
|
|
106
106
|
// TODO: Delete when the function is destroyed
|
|
107
|
-
auto callbackData = new CbData({ getter, setter });
|
|
107
|
+
auto callbackData = new CbData({ getter, setter, nullptr });
|
|
108
108
|
|
|
109
109
|
return PropertyDescriptor({
|
|
110
110
|
nullptr,
|
package/napi-inl.h
CHANGED
|
@@ -17,49 +17,6 @@ namespace Napi {
|
|
|
17
17
|
// Helpers to handle functions exposed from C++.
|
|
18
18
|
namespace details {
|
|
19
19
|
|
|
20
|
-
#ifdef NAPI_CPP_EXCEPTIONS
|
|
21
|
-
|
|
22
|
-
#define NAPI_THROW(e) throw e
|
|
23
|
-
|
|
24
|
-
// When C++ exceptions are enabled, Errors are thrown directly. There is no need
|
|
25
|
-
// to return anything after the throw statement. The variadic parameter is an
|
|
26
|
-
// optional return value that is ignored.
|
|
27
|
-
#define NAPI_THROW_IF_FAILED(env, status, ...) \
|
|
28
|
-
if ((status) != napi_ok) throw Error::New(env);
|
|
29
|
-
|
|
30
|
-
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
|
|
31
|
-
if ((status) != napi_ok) throw Error::New(env);
|
|
32
|
-
|
|
33
|
-
#else // NAPI_CPP_EXCEPTIONS
|
|
34
|
-
|
|
35
|
-
#define NAPI_THROW(e) (e).ThrowAsJavaScriptException();
|
|
36
|
-
|
|
37
|
-
// When C++ exceptions are disabled, Errors are thrown as JavaScript exceptions,
|
|
38
|
-
// which are pending until the callback returns to JS. The variadic parameter
|
|
39
|
-
// is an optional return value; usually it is an empty result.
|
|
40
|
-
#define NAPI_THROW_IF_FAILED(env, status, ...) \
|
|
41
|
-
if ((status) != napi_ok) { \
|
|
42
|
-
Error::New(env).ThrowAsJavaScriptException(); \
|
|
43
|
-
return __VA_ARGS__; \
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// We need a _VOID version of this macro to avoid warnings resulting from
|
|
47
|
-
// leaving the NAPI_THROW_IF_FAILED `...` argument empty.
|
|
48
|
-
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
|
|
49
|
-
if ((status) != napi_ok) { \
|
|
50
|
-
Error::New(env).ThrowAsJavaScriptException(); \
|
|
51
|
-
return; \
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
#endif // NAPI_CPP_EXCEPTIONS
|
|
55
|
-
|
|
56
|
-
#define NAPI_FATAL_IF_FAILED(status, location, message) \
|
|
57
|
-
do { \
|
|
58
|
-
if ((status) != napi_ok) { \
|
|
59
|
-
Error::Fatal((location), (message)); \
|
|
60
|
-
} \
|
|
61
|
-
} while (0)
|
|
62
|
-
|
|
63
20
|
// Attach a data item to an object and delete it when the object gets
|
|
64
21
|
// garbage-collected.
|
|
65
22
|
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
|
|
@@ -176,6 +133,7 @@ struct AccessorCallbackData {
|
|
|
176
133
|
CallbackInfo callbackInfo(env, info);
|
|
177
134
|
AccessorCallbackData* callbackData =
|
|
178
135
|
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
136
|
+
callbackInfo.SetData(callbackData->data);
|
|
179
137
|
return callbackData->getterCallback(callbackInfo);
|
|
180
138
|
});
|
|
181
139
|
}
|
|
@@ -186,6 +144,7 @@ struct AccessorCallbackData {
|
|
|
186
144
|
CallbackInfo callbackInfo(env, info);
|
|
187
145
|
AccessorCallbackData* callbackData =
|
|
188
146
|
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
147
|
+
callbackInfo.SetData(callbackData->data);
|
|
189
148
|
callbackData->setterCallback(callbackInfo);
|
|
190
149
|
return nullptr;
|
|
191
150
|
});
|
|
@@ -193,6 +152,7 @@ struct AccessorCallbackData {
|
|
|
193
152
|
|
|
194
153
|
Getter getterCallback;
|
|
195
154
|
Setter setterCallback;
|
|
155
|
+
void* data;
|
|
196
156
|
};
|
|
197
157
|
|
|
198
158
|
} // namespace details
|
|
@@ -1060,7 +1020,7 @@ inline bool Object::Delete(uint32_t index) {
|
|
|
1060
1020
|
return result;
|
|
1061
1021
|
}
|
|
1062
1022
|
|
|
1063
|
-
inline Array Object::GetPropertyNames() {
|
|
1023
|
+
inline Array Object::GetPropertyNames() const {
|
|
1064
1024
|
napi_value result;
|
|
1065
1025
|
napi_status status = napi_get_property_names(_env, _value, &result);
|
|
1066
1026
|
NAPI_THROW_IF_FAILED(_env, status, Array());
|
|
@@ -1309,8 +1269,8 @@ inline DataView DataView::New(napi_env env,
|
|
|
1309
1269
|
size_t byteOffset) {
|
|
1310
1270
|
if (byteOffset > arrayBuffer.ByteLength()) {
|
|
1311
1271
|
NAPI_THROW(RangeError::New(env,
|
|
1312
|
-
"Start offset is outside the bounds of the buffer")
|
|
1313
|
-
|
|
1272
|
+
"Start offset is outside the bounds of the buffer"),
|
|
1273
|
+
DataView());
|
|
1314
1274
|
}
|
|
1315
1275
|
return New(env, arrayBuffer, byteOffset,
|
|
1316
1276
|
arrayBuffer.ByteLength() - byteOffset);
|
|
@@ -1321,8 +1281,8 @@ inline DataView DataView::New(napi_env env,
|
|
|
1321
1281
|
size_t byteOffset,
|
|
1322
1282
|
size_t byteLength) {
|
|
1323
1283
|
if (byteOffset + byteLength > arrayBuffer.ByteLength()) {
|
|
1324
|
-
NAPI_THROW(RangeError::New(env, "Invalid DataView length")
|
|
1325
|
-
|
|
1284
|
+
NAPI_THROW(RangeError::New(env, "Invalid DataView length"),
|
|
1285
|
+
DataView());
|
|
1326
1286
|
}
|
|
1327
1287
|
napi_value value;
|
|
1328
1288
|
napi_status status = napi_create_dataview(
|
|
@@ -1448,8 +1408,7 @@ inline T DataView::ReadData(size_t byteOffset) const {
|
|
|
1448
1408
|
if (byteOffset + sizeof(T) > _length ||
|
|
1449
1409
|
byteOffset + sizeof(T) < byteOffset) { // overflow
|
|
1450
1410
|
NAPI_THROW(RangeError::New(_env,
|
|
1451
|
-
"Offset is outside the bounds of the DataView"));
|
|
1452
|
-
return 0;
|
|
1411
|
+
"Offset is outside the bounds of the DataView"), 0);
|
|
1453
1412
|
}
|
|
1454
1413
|
|
|
1455
1414
|
return *reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset);
|
|
@@ -1459,9 +1418,8 @@ template <typename T>
|
|
|
1459
1418
|
inline void DataView::WriteData(size_t byteOffset, T value) const {
|
|
1460
1419
|
if (byteOffset + sizeof(T) > _length ||
|
|
1461
1420
|
byteOffset + sizeof(T) < byteOffset) { // overflow
|
|
1462
|
-
|
|
1421
|
+
NAPI_THROW_VOID(RangeError::New(_env,
|
|
1463
1422
|
"Offset is outside the bounds of the DataView"));
|
|
1464
|
-
return;
|
|
1465
1423
|
}
|
|
1466
1424
|
|
|
1467
1425
|
*reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset) = value;
|
|
@@ -1597,7 +1555,7 @@ inline TypedArrayOf<T>::TypedArrayOf(napi_env env,
|
|
|
1597
1555
|
: TypedArray(env, value, type, length), _data(data) {
|
|
1598
1556
|
if (!(type == TypedArrayTypeForPrimitiveType<T>() ||
|
|
1599
1557
|
(type == napi_uint8_clamped_array && std::is_same<T, uint8_t>::value))) {
|
|
1600
|
-
|
|
1558
|
+
NAPI_THROW_VOID(TypeError::New(env, "Array type must match the template parameter. "
|
|
1601
1559
|
"(Uint8 arrays may optionally have the \"clamped\" array type.)"));
|
|
1602
1560
|
}
|
|
1603
1561
|
}
|
|
@@ -1657,7 +1615,11 @@ inline Function Function::New(napi_env env,
|
|
|
1657
1615
|
CbData::Wrapper,
|
|
1658
1616
|
callbackData,
|
|
1659
1617
|
&value);
|
|
1660
|
-
|
|
1618
|
+
if (status != napi_ok) {
|
|
1619
|
+
delete callbackData;
|
|
1620
|
+
NAPI_THROW_IF_FAILED(env, status, Function());
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1661
1623
|
return Function(env, value);
|
|
1662
1624
|
}
|
|
1663
1625
|
|
|
@@ -2031,8 +1993,20 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
|
|
|
2031
1993
|
inline void Error::ThrowAsJavaScriptException() const {
|
|
2032
1994
|
HandleScope scope(_env);
|
|
2033
1995
|
if (!IsEmpty()) {
|
|
1996
|
+
|
|
1997
|
+
// We intentionally don't use `NAPI_THROW_*` macros here to ensure
|
|
1998
|
+
// that there is no possible recursion as `ThrowAsJavaScriptException`
|
|
1999
|
+
// is part of `NAPI_THROW_*` macro definition for noexcept.
|
|
2000
|
+
|
|
2034
2001
|
napi_status status = napi_throw(_env, Value());
|
|
2035
|
-
|
|
2002
|
+
|
|
2003
|
+
#ifdef NAPI_CPP_EXCEPTIONS
|
|
2004
|
+
if (status != napi_ok) {
|
|
2005
|
+
throw Error::New(_env);
|
|
2006
|
+
}
|
|
2007
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
2008
|
+
NAPI_FATAL_IF_FAILED(status, "Error::ThrowAsJavaScriptException", "napi_throw");
|
|
2009
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
2036
2010
|
}
|
|
2037
2011
|
}
|
|
2038
2012
|
|
|
@@ -2603,12 +2577,15 @@ PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
2603
2577
|
const char* utf8name,
|
|
2604
2578
|
Getter getter,
|
|
2605
2579
|
napi_property_attributes attributes,
|
|
2606
|
-
void*
|
|
2580
|
+
void* data) {
|
|
2607
2581
|
typedef details::CallbackData<Getter, Napi::Value> CbData;
|
|
2608
|
-
auto callbackData = new CbData({ getter,
|
|
2582
|
+
auto callbackData = new CbData({ getter, data });
|
|
2609
2583
|
|
|
2610
2584
|
napi_status status = AttachData(env, object, callbackData);
|
|
2611
|
-
|
|
2585
|
+
if (status != napi_ok) {
|
|
2586
|
+
delete callbackData;
|
|
2587
|
+
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
2588
|
+
}
|
|
2612
2589
|
|
|
2613
2590
|
return PropertyDescriptor({
|
|
2614
2591
|
utf8name,
|
|
@@ -2638,12 +2615,15 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
2638
2615
|
Name name,
|
|
2639
2616
|
Getter getter,
|
|
2640
2617
|
napi_property_attributes attributes,
|
|
2641
|
-
void*
|
|
2618
|
+
void* data) {
|
|
2642
2619
|
typedef details::CallbackData<Getter, Napi::Value> CbData;
|
|
2643
|
-
auto callbackData = new CbData({ getter,
|
|
2620
|
+
auto callbackData = new CbData({ getter, data });
|
|
2644
2621
|
|
|
2645
2622
|
napi_status status = AttachData(env, object, callbackData);
|
|
2646
|
-
|
|
2623
|
+
if (status != napi_ok) {
|
|
2624
|
+
delete callbackData;
|
|
2625
|
+
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
2626
|
+
}
|
|
2647
2627
|
|
|
2648
2628
|
return PropertyDescriptor({
|
|
2649
2629
|
nullptr,
|
|
@@ -2664,12 +2644,15 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
2664
2644
|
Getter getter,
|
|
2665
2645
|
Setter setter,
|
|
2666
2646
|
napi_property_attributes attributes,
|
|
2667
|
-
void*
|
|
2647
|
+
void* data) {
|
|
2668
2648
|
typedef details::AccessorCallbackData<Getter, Setter> CbData;
|
|
2669
|
-
auto callbackData = new CbData({ getter, setter });
|
|
2649
|
+
auto callbackData = new CbData({ getter, setter, data });
|
|
2670
2650
|
|
|
2671
2651
|
napi_status status = AttachData(env, object, callbackData);
|
|
2672
|
-
|
|
2652
|
+
if (status != napi_ok) {
|
|
2653
|
+
delete callbackData;
|
|
2654
|
+
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
2655
|
+
}
|
|
2673
2656
|
|
|
2674
2657
|
return PropertyDescriptor({
|
|
2675
2658
|
utf8name,
|
|
@@ -2701,12 +2684,15 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
2701
2684
|
Getter getter,
|
|
2702
2685
|
Setter setter,
|
|
2703
2686
|
napi_property_attributes attributes,
|
|
2704
|
-
void*
|
|
2687
|
+
void* data) {
|
|
2705
2688
|
typedef details::AccessorCallbackData<Getter, Setter> CbData;
|
|
2706
|
-
auto callbackData = new CbData({ getter, setter });
|
|
2689
|
+
auto callbackData = new CbData({ getter, setter, data });
|
|
2707
2690
|
|
|
2708
2691
|
napi_status status = AttachData(env, object, callbackData);
|
|
2709
|
-
|
|
2692
|
+
if (status != napi_ok) {
|
|
2693
|
+
delete callbackData;
|
|
2694
|
+
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
2695
|
+
}
|
|
2710
2696
|
|
|
2711
2697
|
return PropertyDescriptor({
|
|
2712
2698
|
nullptr,
|
|
@@ -3524,7 +3510,8 @@ inline AsyncWorker::AsyncWorker(const Object& receiver,
|
|
|
3524
3510
|
const Object& resource)
|
|
3525
3511
|
: _env(callback.Env()),
|
|
3526
3512
|
_receiver(Napi::Persistent(receiver)),
|
|
3527
|
-
_callback(Napi::Persistent(callback))
|
|
3513
|
+
_callback(Napi::Persistent(callback)),
|
|
3514
|
+
_suppress_destruct(false) {
|
|
3528
3515
|
napi_value resource_id;
|
|
3529
3516
|
napi_status status = napi_create_string_latin1(
|
|
3530
3517
|
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
|
|
@@ -3550,6 +3537,7 @@ inline AsyncWorker::AsyncWorker(AsyncWorker&& other) {
|
|
|
3550
3537
|
_receiver = std::move(other._receiver);
|
|
3551
3538
|
_callback = std::move(other._callback);
|
|
3552
3539
|
_error = std::move(other._error);
|
|
3540
|
+
_suppress_destruct = other._suppress_destruct;
|
|
3553
3541
|
}
|
|
3554
3542
|
|
|
3555
3543
|
inline AsyncWorker& AsyncWorker::operator =(AsyncWorker&& other) {
|
|
@@ -3560,6 +3548,7 @@ inline AsyncWorker& AsyncWorker::operator =(AsyncWorker&& other) {
|
|
|
3560
3548
|
_receiver = std::move(other._receiver);
|
|
3561
3549
|
_callback = std::move(other._callback);
|
|
3562
3550
|
_error = std::move(other._error);
|
|
3551
|
+
_suppress_destruct = other._suppress_destruct;
|
|
3563
3552
|
return *this;
|
|
3564
3553
|
}
|
|
3565
3554
|
|
|
@@ -3589,6 +3578,10 @@ inline FunctionReference& AsyncWorker::Callback() {
|
|
|
3589
3578
|
return _callback;
|
|
3590
3579
|
}
|
|
3591
3580
|
|
|
3581
|
+
inline void AsyncWorker::SuppressDestruct() {
|
|
3582
|
+
_suppress_destruct = true;
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3592
3585
|
inline void AsyncWorker::OnOK() {
|
|
3593
3586
|
_callback.Call(_receiver.Value(), std::initializer_list<napi_value>{});
|
|
3594
3587
|
}
|
|
@@ -3629,7 +3622,9 @@ inline void AsyncWorker::OnWorkComplete(
|
|
|
3629
3622
|
return nullptr;
|
|
3630
3623
|
});
|
|
3631
3624
|
}
|
|
3632
|
-
|
|
3625
|
+
if (!self->_suppress_destruct) {
|
|
3626
|
+
delete self;
|
|
3627
|
+
}
|
|
3633
3628
|
}
|
|
3634
3629
|
|
|
3635
3630
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -3661,10 +3656,6 @@ inline const napi_node_version* VersionManagement::GetNodeVersion(Env env) {
|
|
|
3661
3656
|
return result;
|
|
3662
3657
|
}
|
|
3663
3658
|
|
|
3664
|
-
// These macros shouldn't be useful in user code.
|
|
3665
|
-
#undef NAPI_THROW
|
|
3666
|
-
#undef NAPI_THROW_IF_FAILED
|
|
3667
|
-
|
|
3668
3659
|
} // namespace Napi
|
|
3669
3660
|
|
|
3670
3661
|
#endif // SRC_NAPI_INL_H_
|
package/napi.h
CHANGED
|
@@ -38,6 +38,64 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t), "Size mismatch between char16
|
|
|
38
38
|
#define NAPI_NOEXCEPT noexcept
|
|
39
39
|
#endif
|
|
40
40
|
|
|
41
|
+
#ifdef NAPI_CPP_EXCEPTIONS
|
|
42
|
+
|
|
43
|
+
// When C++ exceptions are enabled, Errors are thrown directly. There is no need
|
|
44
|
+
// to return anything after the throw statements. The variadic parameter is an
|
|
45
|
+
// optional return value that is ignored.
|
|
46
|
+
// We need _VOID versions of the macros to avoid warnings resulting from
|
|
47
|
+
// leaving the NAPI_THROW_* `...` argument empty.
|
|
48
|
+
|
|
49
|
+
#define NAPI_THROW(e, ...) throw e
|
|
50
|
+
#define NAPI_THROW_VOID(e) throw e
|
|
51
|
+
|
|
52
|
+
#define NAPI_THROW_IF_FAILED(env, status, ...) \
|
|
53
|
+
if ((status) != napi_ok) throw Error::New(env);
|
|
54
|
+
|
|
55
|
+
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
|
|
56
|
+
if ((status) != napi_ok) throw Error::New(env);
|
|
57
|
+
|
|
58
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
59
|
+
|
|
60
|
+
// When C++ exceptions are disabled, Errors are thrown as JavaScript exceptions,
|
|
61
|
+
// which are pending until the callback returns to JS. The variadic parameter
|
|
62
|
+
// is an optional return value; usually it is an empty result.
|
|
63
|
+
// We need _VOID versions of the macros to avoid warnings resulting from
|
|
64
|
+
// leaving the NAPI_THROW_* `...` argument empty.
|
|
65
|
+
|
|
66
|
+
#define NAPI_THROW(e, ...) \
|
|
67
|
+
do { \
|
|
68
|
+
(e).ThrowAsJavaScriptException(); \
|
|
69
|
+
return __VA_ARGS__; \
|
|
70
|
+
} while (0)
|
|
71
|
+
|
|
72
|
+
#define NAPI_THROW_VOID(e) \
|
|
73
|
+
do { \
|
|
74
|
+
(e).ThrowAsJavaScriptException(); \
|
|
75
|
+
return; \
|
|
76
|
+
} while (0)
|
|
77
|
+
|
|
78
|
+
#define NAPI_THROW_IF_FAILED(env, status, ...) \
|
|
79
|
+
if ((status) != napi_ok) { \
|
|
80
|
+
Error::New(env).ThrowAsJavaScriptException(); \
|
|
81
|
+
return __VA_ARGS__; \
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#define NAPI_THROW_IF_FAILED_VOID(env, status) \
|
|
85
|
+
if ((status) != napi_ok) { \
|
|
86
|
+
Error::New(env).ThrowAsJavaScriptException(); \
|
|
87
|
+
return; \
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
91
|
+
|
|
92
|
+
#define NAPI_FATAL_IF_FAILED(status, location, message) \
|
|
93
|
+
do { \
|
|
94
|
+
if ((status) != napi_ok) { \
|
|
95
|
+
Error::Fatal((location), (message)); \
|
|
96
|
+
} \
|
|
97
|
+
} while (0)
|
|
98
|
+
|
|
41
99
|
////////////////////////////////////////////////////////////////////////////////
|
|
42
100
|
/// N-API C++ Wrapper Classes
|
|
43
101
|
///
|
|
@@ -601,7 +659,7 @@ namespace Napi {
|
|
|
601
659
|
uint32_t index ///< Property / element index
|
|
602
660
|
);
|
|
603
661
|
|
|
604
|
-
Array GetPropertyNames(); ///< Get all property names
|
|
662
|
+
Array GetPropertyNames() const; ///< Get all property names
|
|
605
663
|
|
|
606
664
|
/// Defines a property on the object.
|
|
607
665
|
void DefineProperty(
|
|
@@ -633,12 +691,12 @@ namespace Napi {
|
|
|
633
691
|
public:
|
|
634
692
|
static External New(napi_env env, T* data);
|
|
635
693
|
|
|
636
|
-
// Finalizer must implement operator()
|
|
694
|
+
// Finalizer must implement `void operator()(Env env, T* data)`.
|
|
637
695
|
template <typename Finalizer>
|
|
638
696
|
static External New(napi_env env,
|
|
639
697
|
T* data,
|
|
640
698
|
Finalizer finalizeCallback);
|
|
641
|
-
// Finalizer must implement operator()
|
|
699
|
+
// Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`.
|
|
642
700
|
template <typename Finalizer, typename Hint>
|
|
643
701
|
static External New(napi_env env,
|
|
644
702
|
T* data,
|
|
@@ -686,8 +744,7 @@ namespace Napi {
|
|
|
686
744
|
size_t byteLength, ///< Length of the external buffer to be used by the array,
|
|
687
745
|
/// in bytes
|
|
688
746
|
Finalizer finalizeCallback ///< Function to be called when the array buffer is destroyed;
|
|
689
|
-
/// must implement `operator()
|
|
690
|
-
/// data buffer pointer), and return `void`
|
|
747
|
+
/// must implement `void operator()(Env env, void* externalData)`
|
|
691
748
|
);
|
|
692
749
|
|
|
693
750
|
/// Creates a new ArrayBuffer instance, using an external buffer with specified byte length.
|
|
@@ -698,8 +755,7 @@ namespace Napi {
|
|
|
698
755
|
size_t byteLength, ///< Length of the external buffer to be used by the array,
|
|
699
756
|
/// in bytes
|
|
700
757
|
Finalizer finalizeCallback, ///< Function to be called when the array buffer is destroyed;
|
|
701
|
-
/// must implement `operator()
|
|
702
|
-
/// data buffer pointer) and `Hint*`, and return `void`
|
|
758
|
+
/// must implement `void operator()(Env env, void* externalData, Hint* hint)`
|
|
703
759
|
Hint* finalizeHint ///< Hint (second parameter) to be passed to the finalize callback
|
|
704
760
|
);
|
|
705
761
|
|
|
@@ -969,12 +1025,12 @@ namespace Napi {
|
|
|
969
1025
|
static Buffer<T> New(napi_env env, size_t length);
|
|
970
1026
|
static Buffer<T> New(napi_env env, T* data, size_t length);
|
|
971
1027
|
|
|
972
|
-
// Finalizer must implement operator()
|
|
1028
|
+
// Finalizer must implement `void operator()(Env env, T* data)`.
|
|
973
1029
|
template <typename Finalizer>
|
|
974
1030
|
static Buffer<T> New(napi_env env, T* data,
|
|
975
1031
|
size_t length,
|
|
976
1032
|
Finalizer finalizeCallback);
|
|
977
|
-
// Finalizer must implement operator()
|
|
1033
|
+
// Finalizer must implement `void operator()(Env env, T* data, Hint* hint)`.
|
|
978
1034
|
template <typename Finalizer, typename Hint>
|
|
979
1035
|
static Buffer<T> New(napi_env env, T* data,
|
|
980
1036
|
size_t length,
|
|
@@ -1722,6 +1778,7 @@ namespace Napi {
|
|
|
1722
1778
|
|
|
1723
1779
|
void Queue();
|
|
1724
1780
|
void Cancel();
|
|
1781
|
+
void SuppressDestruct();
|
|
1725
1782
|
|
|
1726
1783
|
ObjectReference& Receiver();
|
|
1727
1784
|
FunctionReference& Callback();
|
|
@@ -1760,6 +1817,7 @@ namespace Napi {
|
|
|
1760
1817
|
ObjectReference _receiver;
|
|
1761
1818
|
FunctionReference _callback;
|
|
1762
1819
|
std::string _error;
|
|
1820
|
+
bool _suppress_destruct;
|
|
1763
1821
|
};
|
|
1764
1822
|
|
|
1765
1823
|
// Memory management.
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/nodejs/node-addon-api/issues"
|
|
4
4
|
},
|
|
5
5
|
"contributors": [
|
|
6
|
+
"Abhishek Kumar Singh (https://github.com/abhi11210646)",
|
|
6
7
|
"Andrew Petersen (https://github.com/kirbysayshi)",
|
|
7
8
|
"Anisha Rohra (https://github.com/anisha-rohra)",
|
|
8
9
|
"Anna Henningsen (https://github.com/addaleax)",
|
|
@@ -10,6 +11,8 @@
|
|
|
10
11
|
"Arunesh Chandra (https://github.com/aruneshchandra)",
|
|
11
12
|
"Ben Berman (https://github.com/rivertam)",
|
|
12
13
|
"Benjamin Byholm (https://github.com/kkoopa)",
|
|
14
|
+
"Bill Gallafent (https://github.com/gallafent)",
|
|
15
|
+
"Bruce A. MacNaughton (https://github.com/bmacnaughton)",
|
|
13
16
|
"Cory Mickelson (https://github.com/corymickelson)",
|
|
14
17
|
"David Halls (https://github.com/davedoesdev)",
|
|
15
18
|
"Dongjin Na (https://github.com/nadongguri)",
|
|
@@ -17,6 +20,7 @@
|
|
|
17
20
|
"Gabriel Schulhof (https://github.com/gabrielschulhof)",
|
|
18
21
|
"Gus Caplan (https://github.com/devsnek)",
|
|
19
22
|
"Hitesh Kanwathirtha (https://github.com/digitalinfinity)",
|
|
23
|
+
"Jake Barnes (https://github.com/DuBistKomisch)",
|
|
20
24
|
"Jake Yoon (https://github.com/yjaeseok)",
|
|
21
25
|
"Jason Ginchereau (https://github.com/jasongin)",
|
|
22
26
|
"Jim Schlight (https://github.com/jschlight)",
|
|
@@ -24,6 +28,7 @@
|
|
|
24
28
|
"joshgarde (https://github.com/joshgarde)",
|
|
25
29
|
"Konstantin Tarkus (https://github.com/koistya)",
|
|
26
30
|
"Kyle Farnung (https://github.com/kfarnung)",
|
|
31
|
+
"Luciano Martorella (https://github.com/lmartorella)",
|
|
27
32
|
"Matteo Collina (https://github.com/mcollina)",
|
|
28
33
|
"Michael Dawson (https://github.com/mhdawson)",
|
|
29
34
|
"Michele Campus (https://github.com/kYroL01)",
|
|
@@ -32,7 +37,9 @@
|
|
|
32
37
|
"Nick Soggin (https://github.com/iSkore)",
|
|
33
38
|
"Philipp Renoth (https://github.com/DaAitch)",
|
|
34
39
|
"Rolf Timmermans (https://github.com/rolftimmermans)",
|
|
40
|
+
"Ryuichi Okumura (https://github.com/okuryu)",
|
|
35
41
|
"Sampson Gao (https://github.com/sampsongao)",
|
|
42
|
+
"Sam Roberts (https://github.com/sam-github)",
|
|
36
43
|
"Taylor Woll (https://github.com/boingoing)",
|
|
37
44
|
"Thomas Gentilhomme (https://github.com/fraxken)"
|
|
38
45
|
],
|
|
@@ -43,6 +50,7 @@
|
|
|
43
50
|
},
|
|
44
51
|
"directories": {},
|
|
45
52
|
"homepage": "https://github.com/nodejs/node-addon-api",
|
|
53
|
+
"keywords": ["n-api", "napi", "addon", "native", "bindings", "c", "c++", "nan", "node-addon-api"],
|
|
46
54
|
"license": "MIT",
|
|
47
55
|
"main": "index.js",
|
|
48
56
|
"name": "node-addon-api",
|
|
@@ -55,7 +63,11 @@
|
|
|
55
63
|
"scripts": {
|
|
56
64
|
"pretest": "node-gyp rebuild -C test",
|
|
57
65
|
"test": "node test",
|
|
66
|
+
"predev": "node-gyp rebuild -C test --debug",
|
|
67
|
+
"dev": "node test",
|
|
68
|
+
"predev:incremental": "node-gyp configure build -C test --debug",
|
|
69
|
+
"dev:incremental": "node test",
|
|
58
70
|
"doc": "doxygen doc/Doxyfile"
|
|
59
71
|
},
|
|
60
|
-
"version": "1.6.
|
|
72
|
+
"version": "1.6.3"
|
|
61
73
|
}
|
package/tools/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Here is the list of things that can be fixed easily.
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
### Major Reconstructions
|
|
28
|
-
The implementation of `Napi::ObjectWrap` is significantly different from NAN's. `Napi::ObjectWrap` takes a pointer to the wrapped object and creates a reference to the wrapped object inside ObjectWrap constructor. `Napi::ObjectWrap` also
|
|
28
|
+
The implementation of `Napi::ObjectWrap` is significantly different from NAN's. `Napi::ObjectWrap` takes a pointer to the wrapped object and creates a reference to the wrapped object inside ObjectWrap constructor. `Napi::ObjectWrap` also associates wrapped object's instance methods to Javascript module instead of static methods like NAN.
|
|
29
29
|
|
|
30
30
|
So if you use Nan::ObjectWrap in your module, you will need to execute the following steps.
|
|
31
31
|
|
|
@@ -39,7 +39,7 @@ and define it as
|
|
|
39
39
|
...
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
|
-
This way, the `Napi::ObjectWrap` constructor will be invoked after the object has been
|
|
42
|
+
This way, the `Napi::ObjectWrap` constructor will be invoked after the object has been instantiated and `Napi::ObjectWrap` can use the `this` pointer to create a reference to the wrapped object.
|
|
43
43
|
|
|
44
44
|
2. Move your original constructor code into the new constructor. Delete your original constructor.
|
|
45
45
|
3. In your class initialization function, associate native methods in the following way. The `&` character before methods is required because they are not static methods but instance methods.
|