node-addon-api 7.1.0 → 8.1.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/README.md +24 -248
- package/common.gypi +1 -0
- package/index.js +2 -0
- package/napi-inl.h +144 -87
- package/napi.h +26 -6
- package/package.json +7 -4
- package/tools/conversion.js +1 -1
package/README.md
CHANGED
|
@@ -1,266 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
master is now named main
|
|
1
|
+
# **node-addon-api module**
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
[](https://app.codecov.io/gh/nodejs/node-addon-api/tree/main)
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
git branch -m master main
|
|
8
|
-
git fetch origin
|
|
9
|
-
git branch -u origin/main main
|
|
10
|
-
```
|
|
5
|
+
[](https://nodei.co/npm/node-addon-api/) [](https://nodei.co/npm/node-addon-api/)
|
|
11
6
|
|
|
12
|
-
# **node-addon-api module**
|
|
13
7
|
This module contains **header-only C++ wrapper classes** which simplify
|
|
14
8
|
the use of the C based [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
|
|
15
9
|
provided by Node.js when using C++. It provides a C++ object model
|
|
16
10
|
and exception handling semantics with low overhead.
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
in Node.js core, use Node-API. Refer to
|
|
23
|
-
[C/C++ addons with Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
|
|
24
|
-
for more information on Node-API.
|
|
25
|
-
|
|
26
|
-
Node-API is an ABI stable C interface provided by Node.js for building native
|
|
27
|
-
addons. It is independent of the underlying JavaScript runtime (e.g. V8 or ChakraCore)
|
|
28
|
-
and is maintained as part of Node.js itself. It is intended to insulate
|
|
29
|
-
native addons from changes in the underlying JavaScript engine and allow
|
|
30
|
-
modules compiled for one version to run on later versions of Node.js without
|
|
31
|
-
recompilation.
|
|
32
|
-
|
|
33
|
-
The `node-addon-api` module, which is not part of Node.js, preserves the benefits
|
|
34
|
-
of the Node-API as it consists only of inline code that depends only on the stable API
|
|
35
|
-
provided by Node-API. As such, modules built against one version of Node.js
|
|
36
|
-
using node-addon-api should run without having to be rebuilt with newer versions
|
|
37
|
-
of Node.js.
|
|
38
|
-
|
|
39
|
-
It is important to remember that *other* Node.js interfaces such as
|
|
40
|
-
`libuv` (included in a project via `#include <uv.h>`) are not ABI-stable across
|
|
41
|
-
Node.js major versions. Thus, an addon must use Node-API and/or `node-addon-api`
|
|
42
|
-
exclusively and build against a version of Node.js that includes an
|
|
43
|
-
implementation of Node-API (meaning an active LTS version of Node.js) in
|
|
44
|
-
order to benefit from ABI stability across Node.js major versions. Node.js
|
|
45
|
-
provides an [ABI stability guide][] containing a detailed explanation of ABI
|
|
46
|
-
stability in general, and the Node-API ABI stability guarantee in particular.
|
|
47
|
-
|
|
48
|
-
As new APIs are added to Node-API, node-addon-api must be updated to provide
|
|
49
|
-
wrappers for those new APIs. For this reason, node-addon-api provides
|
|
50
|
-
methods that allow callers to obtain the underlying Node-API handles so
|
|
51
|
-
direct calls to Node-API and the use of the objects/methods provided by
|
|
52
|
-
node-addon-api can be used together. For example, in order to be able
|
|
53
|
-
to use an API for which the node-addon-api does not yet provide a wrapper.
|
|
54
|
-
|
|
55
|
-
APIs exposed by node-addon-api are generally used to create and
|
|
56
|
-
manipulate JavaScript values. Concepts and operations generally map
|
|
57
|
-
to ideas specified in the **ECMA262 Language Specification**.
|
|
12
|
+
- [API References](doc/README.md)
|
|
13
|
+
- [Badges](#badges)
|
|
14
|
+
- [Contributing](#contributing)
|
|
15
|
+
- [License](#license)
|
|
58
16
|
|
|
59
|
-
|
|
60
|
-
excellent orientation and tips for developers just getting started with Node-API
|
|
61
|
-
and node-addon-api.
|
|
17
|
+
## API References
|
|
62
18
|
|
|
63
|
-
|
|
64
|
-
- **[API Documentation](#api)**
|
|
65
|
-
- **[Examples](#examples)**
|
|
66
|
-
- **[Tests](#tests)**
|
|
67
|
-
- **[More resource and info about native Addons](#resources)**
|
|
68
|
-
- **[Badges](#badges)**
|
|
69
|
-
- **[Code of Conduct](CODE_OF_CONDUCT.md)**
|
|
70
|
-
- **[Contributors](#contributors)**
|
|
71
|
-
- **[License](#license)**
|
|
19
|
+
API references are available in the [doc](doc/README.md) directory.
|
|
72
20
|
|
|
73
|
-
|
|
21
|
+
<!-- x-release-please-start-version -->
|
|
22
|
+
## Current version: 8.1.0
|
|
23
|
+
<!-- x-release-please-end -->
|
|
74
24
|
|
|
75
25
|
(See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
|
|
76
26
|
|
|
77
|
-
[](https://nodei.co/npm/node-addon-api/) [](https://nodei.co/npm/node-addon-api/)
|
|
78
|
-
|
|
79
|
-
<a name="setup"></a>
|
|
80
|
-
|
|
81
27
|
node-addon-api is based on [Node-API](https://nodejs.org/api/n-api.html) and supports using different Node-API versions.
|
|
82
28
|
This allows addons built with it to run with Node.js versions which support the targeted Node-API version.
|
|
83
29
|
**However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
|
|
84
30
|
every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
|
|
85
31
|
|
|
86
|
-
The oldest Node.js version supported by the current version of node-addon-api is Node.js
|
|
87
|
-
|
|
88
|
-
## Setup
|
|
89
|
-
- [Installation and usage](doc/setup.md)
|
|
90
|
-
- [node-gyp](doc/node-gyp.md)
|
|
91
|
-
- [cmake-js](doc/cmake-js.md)
|
|
92
|
-
- [Conversion tool](doc/conversion-tool.md)
|
|
93
|
-
- [Checker tool](doc/checker-tool.md)
|
|
94
|
-
- [Generator](doc/generator.md)
|
|
95
|
-
- [Prebuild tools](doc/prebuild_tools.md)
|
|
96
|
-
|
|
97
|
-
<a name="api"></a>
|
|
98
|
-
|
|
99
|
-
### **API Documentation**
|
|
100
|
-
|
|
101
|
-
The following is the documentation for node-addon-api.
|
|
102
|
-
|
|
103
|
-
- [Full Class Hierarchy](doc/hierarchy.md)
|
|
104
|
-
- [Addon Structure](doc/addon.md)
|
|
105
|
-
- Data Types:
|
|
106
|
-
- [Env](doc/env.md)
|
|
107
|
-
- [CallbackInfo](doc/callbackinfo.md)
|
|
108
|
-
- [Reference](doc/reference.md)
|
|
109
|
-
- [Value](doc/value.md)
|
|
110
|
-
- [Name](doc/name.md)
|
|
111
|
-
- [Symbol](doc/symbol.md)
|
|
112
|
-
- [String](doc/string.md)
|
|
113
|
-
- [Number](doc/number.md)
|
|
114
|
-
- [Date](doc/date.md)
|
|
115
|
-
- [BigInt](doc/bigint.md)
|
|
116
|
-
- [Boolean](doc/boolean.md)
|
|
117
|
-
- [External](doc/external.md)
|
|
118
|
-
- [Object](doc/object.md)
|
|
119
|
-
- [Array](doc/array.md)
|
|
120
|
-
- [ObjectReference](doc/object_reference.md)
|
|
121
|
-
- [PropertyDescriptor](doc/property_descriptor.md)
|
|
122
|
-
- [Function](doc/function.md)
|
|
123
|
-
- [FunctionReference](doc/function_reference.md)
|
|
124
|
-
- [ObjectWrap](doc/object_wrap.md)
|
|
125
|
-
- [ClassPropertyDescriptor](doc/class_property_descriptor.md)
|
|
126
|
-
- [Buffer](doc/buffer.md)
|
|
127
|
-
- [ArrayBuffer](doc/array_buffer.md)
|
|
128
|
-
- [TypedArray](doc/typed_array.md)
|
|
129
|
-
- [TypedArrayOf](doc/typed_array_of.md)
|
|
130
|
-
- [DataView](doc/dataview.md)
|
|
131
|
-
- [Error Handling](doc/error_handling.md)
|
|
132
|
-
- [Error](doc/error.md)
|
|
133
|
-
- [TypeError](doc/type_error.md)
|
|
134
|
-
- [RangeError](doc/range_error.md)
|
|
135
|
-
- [SyntaxError](doc/syntax_error.md)
|
|
136
|
-
- [Object Lifetime Management](doc/object_lifetime_management.md)
|
|
137
|
-
- [HandleScope](doc/handle_scope.md)
|
|
138
|
-
- [EscapableHandleScope](doc/escapable_handle_scope.md)
|
|
139
|
-
- [Memory Management](doc/memory_management.md)
|
|
140
|
-
- [Async Operations](doc/async_operations.md)
|
|
141
|
-
- [AsyncWorker](doc/async_worker.md)
|
|
142
|
-
- [AsyncContext](doc/async_context.md)
|
|
143
|
-
- [AsyncWorker Variants](doc/async_worker_variants.md)
|
|
144
|
-
- [Thread-safe Functions](doc/threadsafe.md)
|
|
145
|
-
- [ThreadSafeFunction](doc/threadsafe_function.md)
|
|
146
|
-
- [TypedThreadSafeFunction](doc/typed_threadsafe_function.md)
|
|
147
|
-
- [Promises](doc/promises.md)
|
|
148
|
-
- [Version management](doc/version_management.md)
|
|
149
|
-
|
|
150
|
-
<a name="examples"></a>
|
|
151
|
-
|
|
152
|
-
### **Examples**
|
|
153
|
-
|
|
154
|
-
Are you new to **node-addon-api**? Take a look at our **[examples](https://github.com/nodejs/node-addon-examples)**
|
|
155
|
-
|
|
156
|
-
- **[Hello World](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/1_hello_world)**
|
|
157
|
-
- **[Pass arguments to a function](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/2_function_arguments/node-addon-api)**
|
|
158
|
-
- **[Callbacks](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/3_callbacks/node-addon-api)**
|
|
159
|
-
- **[Object factory](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/4_object_factory/node-addon-api)**
|
|
160
|
-
- **[Function factory](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/5_function_factory/node-addon-api)**
|
|
161
|
-
- **[Wrapping C++ Object](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/6_object_wrap/node-addon-api)**
|
|
162
|
-
- **[Factory of wrapped object](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/7_factory_wrap/node-addon-api)**
|
|
163
|
-
- **[Passing wrapped object around](https://github.com/nodejs/node-addon-examples/tree/main/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api)**
|
|
164
|
-
|
|
165
|
-
<a name="tests"></a>
|
|
166
|
-
|
|
167
|
-
### **Tests**
|
|
168
|
-
|
|
169
|
-
To run the **node-addon-api** tests do:
|
|
170
|
-
|
|
171
|
-
```
|
|
172
|
-
npm install
|
|
173
|
-
npm test
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
To avoid testing the deprecated portions of the API run
|
|
177
|
-
```
|
|
178
|
-
npm install
|
|
179
|
-
npm test --disable-deprecated
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
To run the tests targeting a specific version of Node-API run
|
|
183
|
-
```
|
|
184
|
-
npm install
|
|
185
|
-
export NAPI_VERSION=X
|
|
186
|
-
npm test --NAPI_VERSION=X
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
where X is the version of Node-API you want to target.
|
|
190
|
-
|
|
191
|
-
To run a specific unit test, filter conditions are available
|
|
192
|
-
|
|
193
|
-
**Example:**
|
|
194
|
-
compile and run only tests on objectwrap.cc and objectwrap.js
|
|
195
|
-
```
|
|
196
|
-
npm run unit --filter=objectwrap
|
|
197
|
-
```
|
|
32
|
+
The oldest Node.js version supported by the current version of node-addon-api is Node.js 18.x.
|
|
198
33
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
**Example:**
|
|
202
|
-
compile and run all test files ending with "reference" -> function_reference.cc, object_reference.cc, reference.cc
|
|
203
|
-
```
|
|
204
|
-
npm run unit --filter=*reference
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Multiple filter conditions can be joined to broaden the test selection
|
|
208
|
-
|
|
209
|
-
**Example:**
|
|
210
|
-
compile and run all tests under folders threadsafe_function and typed_threadsafe_function and also the objectwrap.cc file
|
|
211
|
-
npm run unit --filter='*function objectwrap'
|
|
212
|
-
|
|
213
|
-
### **Debug**
|
|
214
|
-
|
|
215
|
-
To run the **node-addon-api** tests with `--debug` option:
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
npm run-script dev
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
If you want a faster build, you might use the following option:
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
npm run-script dev:incremental
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
Take a look and get inspired by our **[test suite](https://github.com/nodejs/node-addon-api/tree/HEAD/test)**
|
|
228
|
-
|
|
229
|
-
### **Benchmarks**
|
|
230
|
-
|
|
231
|
-
You can run the available benchmarks using the following command:
|
|
232
|
-
|
|
233
|
-
```
|
|
234
|
-
npm run-script benchmark
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
See [benchmark/README.md](benchmark/README.md) for more details about running and adding benchmarks.
|
|
238
|
-
|
|
239
|
-
<a name="resources"></a>
|
|
240
|
-
|
|
241
|
-
### **More resource and info about native Addons**
|
|
242
|
-
- **[C++ Addons](https://nodejs.org/dist/latest/docs/api/addons.html)**
|
|
243
|
-
- **[Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)**
|
|
244
|
-
- **[Node-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)**
|
|
245
|
-
- **[How We Migrated Realm JavaScript From NAN to Node-API](https://developer.mongodb.com/article/realm-javascript-nan-to-n-api)**
|
|
246
|
-
|
|
247
|
-
As node-addon-api's core mission is to expose the plain C Node-API as C++
|
|
248
|
-
wrappers, tools that facilitate n-api/node-addon-api providing more
|
|
249
|
-
convenient patterns for developing a Node.js add-on with n-api/node-addon-api
|
|
250
|
-
can be published to NPM as standalone packages. It is also recommended to tag
|
|
251
|
-
such packages with `node-addon-api` to provide more visibility to the community.
|
|
252
|
-
|
|
253
|
-
Quick links to NPM searches: [keywords:node-addon-api](https://www.npmjs.com/search?q=keywords%3Anode-addon-api).
|
|
254
|
-
|
|
255
|
-
<a name="other-bindings"></a>
|
|
256
|
-
|
|
257
|
-
### **Other bindings**
|
|
258
|
-
|
|
259
|
-
- **[napi-rs](https://napi.rs)** - (`Rust`)
|
|
260
|
-
|
|
261
|
-
<a name="badges"></a>
|
|
262
|
-
|
|
263
|
-
### **Badges**
|
|
34
|
+
## Badges
|
|
264
35
|
|
|
265
36
|
The use of badges is recommended to indicate the minimum version of Node-API
|
|
266
37
|
required for the module. This helps to determine which Node.js major versions are
|
|
@@ -279,16 +50,15 @@ available:
|
|
|
279
50
|

|
|
280
51
|

|
|
281
52
|
|
|
282
|
-
##
|
|
53
|
+
## Contributing
|
|
283
54
|
|
|
284
55
|
We love contributions from the community to **node-addon-api**!
|
|
285
56
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around extending this module.
|
|
286
57
|
|
|
287
|
-
<a name="contributors"></a>
|
|
288
|
-
|
|
289
58
|
## Team members
|
|
290
59
|
|
|
291
60
|
### Active
|
|
61
|
+
|
|
292
62
|
| Name | GitHub Link |
|
|
293
63
|
| ------------------- | ----------------------------------------------------- |
|
|
294
64
|
| Anna Henningsen | [addaleax](https://github.com/addaleax) |
|
|
@@ -299,7 +69,12 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around
|
|
|
299
69
|
| Nicola Del Gobbo | [NickNaso](https://github.com/NickNaso) |
|
|
300
70
|
| Vladimir Morozov | [vmoroz](https://github.com/vmoroz) |
|
|
301
71
|
|
|
72
|
+
<details>
|
|
73
|
+
|
|
74
|
+
<summary>Emeritus</summary>
|
|
75
|
+
|
|
302
76
|
### Emeritus
|
|
77
|
+
|
|
303
78
|
| Name | GitHub Link |
|
|
304
79
|
| ------------------- | ----------------------------------------------------- |
|
|
305
80
|
| Arunesh Chandra | [aruneshchandra](https://github.com/aruneshchandra) |
|
|
@@ -311,9 +86,10 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around
|
|
|
311
86
|
| Sampson Gao | [sampsongao](https://github.com/sampsongao) |
|
|
312
87
|
| Taylor Woll | [boingoing](https://github.com/boingoing) |
|
|
313
88
|
|
|
314
|
-
|
|
89
|
+
</details>
|
|
90
|
+
|
|
91
|
+
## License
|
|
315
92
|
|
|
316
93
|
Licensed under [MIT](./LICENSE.md)
|
|
317
94
|
|
|
318
|
-
[ABI stability guide]: https://nodejs.org/en/docs/guides/abi-stability/
|
|
319
95
|
[Node-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api_version_matrix
|
package/common.gypi
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const { version } = require('./package.json');
|
|
2
3
|
|
|
3
4
|
const includeDir = path.relative('.', __dirname);
|
|
4
5
|
|
|
@@ -7,6 +8,7 @@ module.exports = {
|
|
|
7
8
|
include_dir: includeDir,
|
|
8
9
|
gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
|
|
9
10
|
targets: path.join(includeDir, 'node_addon_api.gyp'),
|
|
11
|
+
version,
|
|
10
12
|
isNodeApiBuiltin: true,
|
|
11
13
|
needsFlag: false
|
|
12
14
|
};
|
package/napi-inl.h
CHANGED
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
////////////////////////////////////////////////////////////////////////////////
|
|
10
10
|
|
|
11
11
|
// Note: Do not include this file directly! Include "napi.h" instead.
|
|
12
|
+
// This should be a no-op and is intended for better IDE integration.
|
|
13
|
+
#include "napi.h"
|
|
12
14
|
|
|
13
15
|
#include <algorithm>
|
|
16
|
+
#include <cstdarg>
|
|
14
17
|
#include <cstring>
|
|
15
18
|
#if NAPI_HAS_THREADS
|
|
16
19
|
#include <mutex>
|
|
@@ -31,6 +34,23 @@ namespace details {
|
|
|
31
34
|
// Node.js releases. Only necessary when they are used in napi.h and napi-inl.h.
|
|
32
35
|
constexpr int napi_no_external_buffers_allowed = 22;
|
|
33
36
|
|
|
37
|
+
#if (defined(NAPI_EXPERIMENTAL) && \
|
|
38
|
+
defined(NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER))
|
|
39
|
+
template <napi_finalize finalizer>
|
|
40
|
+
inline void PostFinalizerWrapper(node_api_nogc_env nogc_env,
|
|
41
|
+
void* data,
|
|
42
|
+
void* hint) {
|
|
43
|
+
napi_status status = node_api_post_finalizer(nogc_env, finalizer, data, hint);
|
|
44
|
+
NAPI_FATAL_IF_FAILED(
|
|
45
|
+
status, "PostFinalizerWrapper", "node_api_post_finalizer failed");
|
|
46
|
+
}
|
|
47
|
+
#else
|
|
48
|
+
template <napi_finalize finalizer>
|
|
49
|
+
inline void PostFinalizerWrapper(napi_env env, void* data, void* hint) {
|
|
50
|
+
finalizer(env, data, hint);
|
|
51
|
+
}
|
|
52
|
+
#endif
|
|
53
|
+
|
|
34
54
|
template <typename FreeType>
|
|
35
55
|
inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
|
|
36
56
|
delete static_cast<FreeType*>(data);
|
|
@@ -65,7 +85,8 @@ inline napi_status AttachData(napi_env env,
|
|
|
65
85
|
}
|
|
66
86
|
}
|
|
67
87
|
#else // NAPI_VERSION >= 5
|
|
68
|
-
status = napi_add_finalizer(
|
|
88
|
+
status = napi_add_finalizer(
|
|
89
|
+
env, obj, data, details::PostFinalizerWrapper<finalizer>, hint, nullptr);
|
|
69
90
|
#endif
|
|
70
91
|
return status;
|
|
71
92
|
}
|
|
@@ -154,7 +175,10 @@ napi_value TemplatedCallback(napi_env env,
|
|
|
154
175
|
napi_callback_info info) NAPI_NOEXCEPT {
|
|
155
176
|
return details::WrapCallback([&] {
|
|
156
177
|
CallbackInfo cbInfo(env, info);
|
|
157
|
-
|
|
178
|
+
// MSVC requires to copy 'Callback' function pointer to a local variable
|
|
179
|
+
// before invoking it.
|
|
180
|
+
auto callback = Callback;
|
|
181
|
+
return callback(cbInfo);
|
|
158
182
|
});
|
|
159
183
|
}
|
|
160
184
|
|
|
@@ -337,6 +361,18 @@ struct AccessorCallbackData {
|
|
|
337
361
|
void* data;
|
|
338
362
|
};
|
|
339
363
|
|
|
364
|
+
// Debugging-purpose C++-style variant of sprintf().
|
|
365
|
+
inline std::string StringFormat(const char* format, ...) {
|
|
366
|
+
std::string result;
|
|
367
|
+
va_list args;
|
|
368
|
+
va_start(args, format);
|
|
369
|
+
int len = vsnprintf(nullptr, 0, format, args);
|
|
370
|
+
result.resize(len);
|
|
371
|
+
vsnprintf(&result[0], len + 1, format, args);
|
|
372
|
+
va_end(args);
|
|
373
|
+
return result;
|
|
374
|
+
}
|
|
375
|
+
|
|
340
376
|
} // namespace details
|
|
341
377
|
|
|
342
378
|
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
|
|
@@ -805,8 +841,7 @@ inline void Boolean::CheckCast(napi_env env, napi_value value) {
|
|
|
805
841
|
napi_valuetype type;
|
|
806
842
|
napi_status status = napi_typeof(env, value, &type);
|
|
807
843
|
NAPI_CHECK(status == napi_ok, "Boolean::CheckCast", "napi_typeof failed");
|
|
808
|
-
|
|
809
|
-
type == napi_boolean, "Boolean::CheckCast", "value is not napi_boolean");
|
|
844
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_boolean, "%d", "Boolean::CheckCast");
|
|
810
845
|
}
|
|
811
846
|
|
|
812
847
|
inline Boolean::Boolean() : Napi::Value() {}
|
|
@@ -842,8 +877,7 @@ inline void Number::CheckCast(napi_env env, napi_value value) {
|
|
|
842
877
|
napi_valuetype type;
|
|
843
878
|
napi_status status = napi_typeof(env, value, &type);
|
|
844
879
|
NAPI_CHECK(status == napi_ok, "Number::CheckCast", "napi_typeof failed");
|
|
845
|
-
|
|
846
|
-
type == napi_number, "Number::CheckCast", "value is not napi_number");
|
|
880
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_number, "%d", "Number::CheckCast");
|
|
847
881
|
}
|
|
848
882
|
|
|
849
883
|
inline Number::Number() : Value() {}
|
|
@@ -938,8 +972,7 @@ inline void BigInt::CheckCast(napi_env env, napi_value value) {
|
|
|
938
972
|
napi_valuetype type;
|
|
939
973
|
napi_status status = napi_typeof(env, value, &type);
|
|
940
974
|
NAPI_CHECK(status == napi_ok, "BigInt::CheckCast", "napi_typeof failed");
|
|
941
|
-
|
|
942
|
-
type == napi_bigint, "BigInt::CheckCast", "value is not napi_bigint");
|
|
975
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_bigint, "%d", "BigInt::CheckCast");
|
|
943
976
|
}
|
|
944
977
|
|
|
945
978
|
inline BigInt::BigInt() : Value() {}
|
|
@@ -1025,9 +1058,10 @@ inline void Name::CheckCast(napi_env env, napi_value value) {
|
|
|
1025
1058
|
napi_valuetype type;
|
|
1026
1059
|
napi_status status = napi_typeof(env, value, &type);
|
|
1027
1060
|
NAPI_CHECK(status == napi_ok, "Name::CheckCast", "napi_typeof failed");
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1061
|
+
NAPI_INTERNAL_CHECK(type == napi_string || type == napi_symbol,
|
|
1062
|
+
"Name::CheckCast",
|
|
1063
|
+
"value is not napi_string or napi_symbol, got %d.",
|
|
1064
|
+
type);
|
|
1031
1065
|
}
|
|
1032
1066
|
|
|
1033
1067
|
inline Name::Name() : Value() {}
|
|
@@ -1094,8 +1128,7 @@ inline void String::CheckCast(napi_env env, napi_value value) {
|
|
|
1094
1128
|
napi_valuetype type;
|
|
1095
1129
|
napi_status status = napi_typeof(env, value, &type);
|
|
1096
1130
|
NAPI_CHECK(status == napi_ok, "String::CheckCast", "napi_typeof failed");
|
|
1097
|
-
|
|
1098
|
-
type == napi_string, "String::CheckCast", "value is not napi_string");
|
|
1131
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_string, "%d", "String::CheckCast");
|
|
1099
1132
|
}
|
|
1100
1133
|
|
|
1101
1134
|
inline String::String() : Name() {}
|
|
@@ -1231,8 +1264,7 @@ inline void Symbol::CheckCast(napi_env env, napi_value value) {
|
|
|
1231
1264
|
napi_valuetype type;
|
|
1232
1265
|
napi_status status = napi_typeof(env, value, &type);
|
|
1233
1266
|
NAPI_CHECK(status == napi_ok, "Symbol::CheckCast", "napi_typeof failed");
|
|
1234
|
-
|
|
1235
|
-
type == napi_symbol, "Symbol::CheckCast", "value is not napi_symbol");
|
|
1267
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_symbol, "%d", "Symbol::CheckCast");
|
|
1236
1268
|
}
|
|
1237
1269
|
|
|
1238
1270
|
inline Symbol::Symbol() : Name() {}
|
|
@@ -1403,8 +1435,7 @@ inline void Object::CheckCast(napi_env env, napi_value value) {
|
|
|
1403
1435
|
napi_valuetype type;
|
|
1404
1436
|
napi_status status = napi_typeof(env, value, &type);
|
|
1405
1437
|
NAPI_CHECK(status == napi_ok, "Object::CheckCast", "napi_typeof failed");
|
|
1406
|
-
|
|
1407
|
-
type == napi_object, "Object::CheckCast", "value is not napi_object");
|
|
1438
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_object, "%d", "Object::CheckCast");
|
|
1408
1439
|
}
|
|
1409
1440
|
|
|
1410
1441
|
inline Object::Object() : TypeTaggable() {}
|
|
@@ -1774,7 +1805,8 @@ inline External<T> External<T>::New(napi_env env,
|
|
|
1774
1805
|
napi_status status =
|
|
1775
1806
|
napi_create_external(env,
|
|
1776
1807
|
data,
|
|
1777
|
-
details::
|
|
1808
|
+
details::PostFinalizerWrapper<
|
|
1809
|
+
details::FinalizeData<T, Finalizer>::Wrapper>,
|
|
1778
1810
|
finalizeData,
|
|
1779
1811
|
&value);
|
|
1780
1812
|
if (status != napi_ok) {
|
|
@@ -1797,7 +1829,8 @@ inline External<T> External<T>::New(napi_env env,
|
|
|
1797
1829
|
napi_status status = napi_create_external(
|
|
1798
1830
|
env,
|
|
1799
1831
|
data,
|
|
1800
|
-
details::
|
|
1832
|
+
details::PostFinalizerWrapper<
|
|
1833
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>,
|
|
1801
1834
|
finalizeData,
|
|
1802
1835
|
&value);
|
|
1803
1836
|
if (status != napi_ok) {
|
|
@@ -1814,9 +1847,7 @@ inline void External<T>::CheckCast(napi_env env, napi_value value) {
|
|
|
1814
1847
|
napi_valuetype type;
|
|
1815
1848
|
napi_status status = napi_typeof(env, value, &type);
|
|
1816
1849
|
NAPI_CHECK(status == napi_ok, "External::CheckCast", "napi_typeof failed");
|
|
1817
|
-
|
|
1818
|
-
"External::CheckCast",
|
|
1819
|
-
"value is not napi_external");
|
|
1850
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_external, "%d", "External::CheckCast");
|
|
1820
1851
|
}
|
|
1821
1852
|
|
|
1822
1853
|
template <typename T>
|
|
@@ -1910,7 +1941,8 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1910
1941
|
env,
|
|
1911
1942
|
externalData,
|
|
1912
1943
|
byteLength,
|
|
1913
|
-
details::
|
|
1944
|
+
details::PostFinalizerWrapper<
|
|
1945
|
+
details::FinalizeData<void, Finalizer>::Wrapper>,
|
|
1914
1946
|
finalizeData,
|
|
1915
1947
|
&value);
|
|
1916
1948
|
if (status != napi_ok) {
|
|
@@ -1935,7 +1967,8 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1935
1967
|
env,
|
|
1936
1968
|
externalData,
|
|
1937
1969
|
byteLength,
|
|
1938
|
-
details::
|
|
1970
|
+
details::PostFinalizerWrapper<
|
|
1971
|
+
details::FinalizeData<void, Finalizer, Hint>::WrapperWithHint>,
|
|
1939
1972
|
finalizeData,
|
|
1940
1973
|
&value);
|
|
1941
1974
|
if (status != napi_ok) {
|
|
@@ -2270,12 +2303,13 @@ inline void TypedArrayOf<T>::CheckCast(napi_env env, napi_value value) {
|
|
|
2270
2303
|
"TypedArrayOf::CheckCast",
|
|
2271
2304
|
"napi_is_typedarray failed");
|
|
2272
2305
|
|
|
2273
|
-
|
|
2306
|
+
NAPI_INTERNAL_CHECK(
|
|
2274
2307
|
(type == TypedArrayTypeForPrimitiveType<T>() ||
|
|
2275
2308
|
(type == napi_uint8_clamped_array && std::is_same<T, uint8_t>::value)),
|
|
2276
2309
|
"TypedArrayOf::CheckCast",
|
|
2277
|
-
"Array type must match the template parameter
|
|
2278
|
-
"optionally have the \"clamped\" array type.)"
|
|
2310
|
+
"Array type must match the template parameter, (Uint8 arrays may "
|
|
2311
|
+
"optionally have the \"clamped\" array type.), got %d.",
|
|
2312
|
+
type);
|
|
2279
2313
|
}
|
|
2280
2314
|
|
|
2281
2315
|
template <typename T>
|
|
@@ -2456,9 +2490,7 @@ inline void Function::CheckCast(napi_env env, napi_value value) {
|
|
|
2456
2490
|
napi_valuetype type;
|
|
2457
2491
|
napi_status status = napi_typeof(env, value, &type);
|
|
2458
2492
|
NAPI_CHECK(status == napi_ok, "Function::CheckCast", "napi_typeof failed");
|
|
2459
|
-
|
|
2460
|
-
"Function::CheckCast",
|
|
2461
|
-
"value is not napi_function");
|
|
2493
|
+
NAPI_INTERNAL_CHECK_EQ(type, napi_function, "%d", "Function::CheckCast");
|
|
2462
2494
|
}
|
|
2463
2495
|
|
|
2464
2496
|
inline Function::Function() : Object() {}
|
|
@@ -2652,13 +2684,14 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2652
2684
|
details::FinalizeData<T, Finalizer>* finalizeData =
|
|
2653
2685
|
new details::FinalizeData<T, Finalizer>(
|
|
2654
2686
|
{std::move(finalizeCallback), nullptr});
|
|
2655
|
-
napi_status status =
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2687
|
+
napi_status status = napi_create_external_buffer(
|
|
2688
|
+
env,
|
|
2689
|
+
length * sizeof(T),
|
|
2690
|
+
data,
|
|
2691
|
+
details::PostFinalizerWrapper<
|
|
2692
|
+
details::FinalizeData<T, Finalizer>::Wrapper>,
|
|
2693
|
+
finalizeData,
|
|
2694
|
+
&value);
|
|
2662
2695
|
if (status != napi_ok) {
|
|
2663
2696
|
delete finalizeData;
|
|
2664
2697
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
@@ -2681,7 +2714,8 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2681
2714
|
env,
|
|
2682
2715
|
length * sizeof(T),
|
|
2683
2716
|
data,
|
|
2684
|
-
details::
|
|
2717
|
+
details::PostFinalizerWrapper<
|
|
2718
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>,
|
|
2685
2719
|
finalizeData,
|
|
2686
2720
|
&value);
|
|
2687
2721
|
if (status != napi_ok) {
|
|
@@ -2720,13 +2754,14 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2720
2754
|
{std::move(finalizeCallback), nullptr});
|
|
2721
2755
|
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2722
2756
|
napi_value value;
|
|
2723
|
-
napi_status status =
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2757
|
+
napi_status status = napi_create_external_buffer(
|
|
2758
|
+
env,
|
|
2759
|
+
length * sizeof(T),
|
|
2760
|
+
data,
|
|
2761
|
+
details::PostFinalizerWrapper<
|
|
2762
|
+
details::FinalizeData<T, Finalizer>::Wrapper>,
|
|
2763
|
+
finalizeData,
|
|
2764
|
+
&value);
|
|
2730
2765
|
if (status == details::napi_no_external_buffers_allowed) {
|
|
2731
2766
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2732
2767
|
// If we can't create an external buffer, we'll just copy the data.
|
|
@@ -2759,7 +2794,8 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2759
2794
|
env,
|
|
2760
2795
|
length * sizeof(T),
|
|
2761
2796
|
data,
|
|
2762
|
-
details::
|
|
2797
|
+
details::PostFinalizerWrapper<
|
|
2798
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>,
|
|
2763
2799
|
finalizeData,
|
|
2764
2800
|
&value);
|
|
2765
2801
|
if (status == details::napi_no_external_buffers_allowed) {
|
|
@@ -3054,7 +3090,12 @@ inline void Error::ThrowAsJavaScriptException() const {
|
|
|
3054
3090
|
|
|
3055
3091
|
status = napi_throw(_env, Value());
|
|
3056
3092
|
|
|
3057
|
-
|
|
3093
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
3094
|
+
napi_status expected_failure_mode = napi_cannot_run_js;
|
|
3095
|
+
#else
|
|
3096
|
+
napi_status expected_failure_mode = napi_pending_exception;
|
|
3097
|
+
#endif
|
|
3098
|
+
if (status == expected_failure_mode) {
|
|
3058
3099
|
// The environment must be terminating as we checked earlier and there
|
|
3059
3100
|
// was no pending exception. In this case continuing will result
|
|
3060
3101
|
// in a fatal error and there is nothing the author has done incorrectly
|
|
@@ -4428,7 +4469,12 @@ inline ObjectWrap<T>::ObjectWrap(const Napi::CallbackInfo& callbackInfo) {
|
|
|
4428
4469
|
napi_status status;
|
|
4429
4470
|
napi_ref ref;
|
|
4430
4471
|
T* instance = static_cast<T*>(this);
|
|
4431
|
-
status = napi_wrap(env,
|
|
4472
|
+
status = napi_wrap(env,
|
|
4473
|
+
wrapper,
|
|
4474
|
+
instance,
|
|
4475
|
+
details::PostFinalizerWrapper<FinalizeCallback>,
|
|
4476
|
+
nullptr,
|
|
4477
|
+
&ref);
|
|
4432
4478
|
NAPI_THROW_IF_FAILED_VOID(env, status);
|
|
4433
4479
|
|
|
4434
4480
|
Reference<Object>* instanceRef = instance;
|
|
@@ -4891,7 +4937,10 @@ inline napi_value ObjectWrap<T>::WrappedMethod(
|
|
|
4891
4937
|
napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
4892
4938
|
return details::WrapCallback([&] {
|
|
4893
4939
|
const CallbackInfo cbInfo(env, info);
|
|
4894
|
-
method
|
|
4940
|
+
// MSVC requires to copy 'method' function pointer to a local variable
|
|
4941
|
+
// before invoking it.
|
|
4942
|
+
auto m = method;
|
|
4943
|
+
m(cbInfo, cbInfo[0]);
|
|
4895
4944
|
return nullptr;
|
|
4896
4945
|
});
|
|
4897
4946
|
}
|
|
@@ -5321,19 +5370,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5321
5370
|
auto* finalizeData = new details::
|
|
5322
5371
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5323
5372
|
{data, finalizeCallback});
|
|
5324
|
-
|
|
5325
|
-
env,
|
|
5326
|
-
nullptr,
|
|
5327
|
-
nullptr,
|
|
5328
|
-
String::From(env, resourceName),
|
|
5329
|
-
maxQueueSize,
|
|
5330
|
-
initialThreadCount,
|
|
5331
|
-
finalizeData,
|
|
5373
|
+
auto fini =
|
|
5332
5374
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5333
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5375
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5376
|
+
napi_status status =
|
|
5377
|
+
napi_create_threadsafe_function(env,
|
|
5378
|
+
nullptr,
|
|
5379
|
+
nullptr,
|
|
5380
|
+
String::From(env, resourceName),
|
|
5381
|
+
maxQueueSize,
|
|
5382
|
+
initialThreadCount,
|
|
5383
|
+
finalizeData,
|
|
5384
|
+
fini,
|
|
5385
|
+
context,
|
|
5386
|
+
CallJsInternal,
|
|
5387
|
+
&tsfn._tsfn);
|
|
5337
5388
|
if (status != napi_ok) {
|
|
5338
5389
|
delete finalizeData;
|
|
5339
5390
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5365,19 +5416,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5365
5416
|
auto* finalizeData = new details::
|
|
5366
5417
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5367
5418
|
{data, finalizeCallback});
|
|
5368
|
-
|
|
5369
|
-
env,
|
|
5370
|
-
nullptr,
|
|
5371
|
-
resource,
|
|
5372
|
-
String::From(env, resourceName),
|
|
5373
|
-
maxQueueSize,
|
|
5374
|
-
initialThreadCount,
|
|
5375
|
-
finalizeData,
|
|
5419
|
+
auto fini =
|
|
5376
5420
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5377
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5421
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5422
|
+
napi_status status =
|
|
5423
|
+
napi_create_threadsafe_function(env,
|
|
5424
|
+
nullptr,
|
|
5425
|
+
resource,
|
|
5426
|
+
String::From(env, resourceName),
|
|
5427
|
+
maxQueueSize,
|
|
5428
|
+
initialThreadCount,
|
|
5429
|
+
finalizeData,
|
|
5430
|
+
fini,
|
|
5431
|
+
context,
|
|
5432
|
+
CallJsInternal,
|
|
5433
|
+
&tsfn._tsfn);
|
|
5381
5434
|
if (status != napi_ok) {
|
|
5382
5435
|
delete finalizeData;
|
|
5383
5436
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5481,19 +5534,21 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5481
5534
|
auto* finalizeData = new details::
|
|
5482
5535
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5483
5536
|
{data, finalizeCallback});
|
|
5484
|
-
|
|
5485
|
-
env,
|
|
5486
|
-
callback,
|
|
5487
|
-
nullptr,
|
|
5488
|
-
String::From(env, resourceName),
|
|
5489
|
-
maxQueueSize,
|
|
5490
|
-
initialThreadCount,
|
|
5491
|
-
finalizeData,
|
|
5537
|
+
auto fini =
|
|
5492
5538
|
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5493
|
-
FinalizeFinalizeWrapperWithDataAndContext
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5539
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5540
|
+
napi_status status =
|
|
5541
|
+
napi_create_threadsafe_function(env,
|
|
5542
|
+
callback,
|
|
5543
|
+
nullptr,
|
|
5544
|
+
String::From(env, resourceName),
|
|
5545
|
+
maxQueueSize,
|
|
5546
|
+
initialThreadCount,
|
|
5547
|
+
finalizeData,
|
|
5548
|
+
fini,
|
|
5549
|
+
context,
|
|
5550
|
+
CallJsInternal,
|
|
5551
|
+
&tsfn._tsfn);
|
|
5497
5552
|
if (status != napi_ok) {
|
|
5498
5553
|
delete finalizeData;
|
|
5499
5554
|
NAPI_THROW_IF_FAILED(
|
|
@@ -5527,6 +5582,9 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5527
5582
|
auto* finalizeData = new details::
|
|
5528
5583
|
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5529
5584
|
{data, finalizeCallback});
|
|
5585
|
+
auto fini =
|
|
5586
|
+
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5587
|
+
FinalizeFinalizeWrapperWithDataAndContext;
|
|
5530
5588
|
napi_status status = napi_create_threadsafe_function(
|
|
5531
5589
|
env,
|
|
5532
5590
|
details::DefaultCallbackWrapper<
|
|
@@ -5538,8 +5596,7 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::New(
|
|
|
5538
5596
|
maxQueueSize,
|
|
5539
5597
|
initialThreadCount,
|
|
5540
5598
|
finalizeData,
|
|
5541
|
-
|
|
5542
|
-
FinalizeFinalizeWrapperWithDataAndContext,
|
|
5599
|
+
fini,
|
|
5543
5600
|
context,
|
|
5544
5601
|
CallJsInternal,
|
|
5545
5602
|
&tsfn._tsfn);
|
package/napi.h
CHANGED
|
@@ -142,6 +142,26 @@ static_assert(sizeof(char16_t) == sizeof(wchar_t),
|
|
|
142
142
|
} \
|
|
143
143
|
} while (0)
|
|
144
144
|
|
|
145
|
+
// Internal check helper. Be careful that the formatted message length should be
|
|
146
|
+
// max 255 size and null terminated.
|
|
147
|
+
#define NAPI_INTERNAL_CHECK(expr, location, ...) \
|
|
148
|
+
do { \
|
|
149
|
+
if (!(expr)) { \
|
|
150
|
+
std::string msg = Napi::details::StringFormat(__VA_ARGS__); \
|
|
151
|
+
Napi::Error::Fatal(location, msg.c_str()); \
|
|
152
|
+
} \
|
|
153
|
+
} while (0)
|
|
154
|
+
|
|
155
|
+
#define NAPI_INTERNAL_CHECK_EQ(actual, expected, value_format, location) \
|
|
156
|
+
do { \
|
|
157
|
+
auto actual_value = (actual); \
|
|
158
|
+
NAPI_INTERNAL_CHECK(actual_value == (expected), \
|
|
159
|
+
location, \
|
|
160
|
+
"Expected " #actual " to be equal to " #expected \
|
|
161
|
+
", but got " value_format ".", \
|
|
162
|
+
actual_value); \
|
|
163
|
+
} while (0)
|
|
164
|
+
|
|
145
165
|
#define NAPI_FATAL_IF_FAILED(status, location, message) \
|
|
146
166
|
NAPI_CHECK((status) == napi_ok, location, message)
|
|
147
167
|
|
|
@@ -1268,7 +1288,7 @@ class TypedArrayOf : public TypedArray {
|
|
|
1268
1288
|
napi_typedarray_type type =
|
|
1269
1289
|
TypedArray::TypedArrayTypeForPrimitiveType<T>()
|
|
1270
1290
|
#else
|
|
1271
|
-
|
|
1291
|
+
napi_typedarray_type type
|
|
1272
1292
|
#endif
|
|
1273
1293
|
///< Type of array, if different from the default array type for the
|
|
1274
1294
|
///< template parameter T.
|
|
@@ -1291,7 +1311,7 @@ class TypedArrayOf : public TypedArray {
|
|
|
1291
1311
|
napi_typedarray_type type =
|
|
1292
1312
|
TypedArray::TypedArrayTypeForPrimitiveType<T>()
|
|
1293
1313
|
#else
|
|
1294
|
-
|
|
1314
|
+
napi_typedarray_type type
|
|
1295
1315
|
#endif
|
|
1296
1316
|
///< Type of array, if different from the default array type for the
|
|
1297
1317
|
///< template parameter T.
|
|
@@ -1381,8 +1401,8 @@ class DataView : public Object {
|
|
|
1381
1401
|
template <typename T>
|
|
1382
1402
|
void WriteData(size_t byteOffset, T value) const;
|
|
1383
1403
|
|
|
1384
|
-
void* _data;
|
|
1385
|
-
size_t _length;
|
|
1404
|
+
void* _data{};
|
|
1405
|
+
size_t _length{};
|
|
1386
1406
|
};
|
|
1387
1407
|
|
|
1388
1408
|
class Function : public Object {
|
|
@@ -1715,7 +1735,7 @@ FunctionReference Persistent(Function value);
|
|
|
1715
1735
|
///
|
|
1716
1736
|
/// Following C++ statements will not be executed. The exception will bubble
|
|
1717
1737
|
/// up as a C++ exception of type `Napi::Error`, until it is either caught
|
|
1718
|
-
/// while still in C++, or else automatically
|
|
1738
|
+
/// while still in C++, or else automatically propagated as a JavaScript
|
|
1719
1739
|
/// exception when the callback returns to JavaScript.
|
|
1720
1740
|
///
|
|
1721
1741
|
/// #### Example 2A - Propagating a Node-API C++ exception:
|
|
@@ -1888,7 +1908,7 @@ class CallbackInfo {
|
|
|
1888
1908
|
napi_value _this;
|
|
1889
1909
|
size_t _argc;
|
|
1890
1910
|
napi_value* _argv;
|
|
1891
|
-
napi_value _staticArgs[6];
|
|
1911
|
+
napi_value _staticArgs[6]{};
|
|
1892
1912
|
napi_value* _dynamicArgs;
|
|
1893
1913
|
void* _data;
|
|
1894
1914
|
};
|
package/package.json
CHANGED
|
@@ -374,7 +374,6 @@
|
|
|
374
374
|
{
|
|
375
375
|
"name": "Vladimir Morozov",
|
|
376
376
|
"url": "https://github.com/vmoroz"
|
|
377
|
-
|
|
378
377
|
},
|
|
379
378
|
{
|
|
380
379
|
"name": "WenheLI",
|
|
@@ -431,7 +430,8 @@
|
|
|
431
430
|
"fs-extra": "^11.1.1",
|
|
432
431
|
"path": "^0.12.7",
|
|
433
432
|
"pre-commit": "^1.2.2",
|
|
434
|
-
"safe-buffer": "^5.1.1"
|
|
433
|
+
"safe-buffer": "^5.1.1",
|
|
434
|
+
"semver": "^7.6.0"
|
|
435
435
|
},
|
|
436
436
|
"directories": {},
|
|
437
437
|
"gypfile": false,
|
|
@@ -463,6 +463,9 @@
|
|
|
463
463
|
"scripts": {
|
|
464
464
|
"prebenchmark": "node-gyp rebuild -C benchmark",
|
|
465
465
|
"benchmark": "node benchmark",
|
|
466
|
+
"create-coverage": "npm test --coverage",
|
|
467
|
+
"report-coverage-html": "rm -rf coverage-html && mkdir coverage-html && gcovr -e test --merge-mode-functions merge-use-line-max --html-nested ./coverage-html/index.html test",
|
|
468
|
+
"report-coverage-xml": "rm -rf coverage-xml && mkdir coverage-xml && gcovr -e test --merge-mode-functions merge-use-line-max --xml -o ./coverage-xml/coverage-cxx.xml test",
|
|
466
469
|
"pretest": "node-gyp rebuild -C test",
|
|
467
470
|
"test": "node test",
|
|
468
471
|
"test:debug": "node-gyp rebuild -C test --debug && NODE_API_BUILD_CONFIG=Debug node ./test/index.js",
|
|
@@ -475,9 +478,9 @@
|
|
|
475
478
|
"lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
|
|
476
479
|
},
|
|
477
480
|
"pre-commit": "lint",
|
|
478
|
-
"version": "
|
|
481
|
+
"version": "8.1.0",
|
|
479
482
|
"support": true,
|
|
480
483
|
"engines": {
|
|
481
|
-
"node": "^
|
|
484
|
+
"node": "^18 || ^20 || >= 21"
|
|
482
485
|
}
|
|
483
486
|
}
|