koffi 2.7.2 → 2.7.4-beta.1
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 +4 -0
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm32hf/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/misc.md +1 -1
- package/index.js +2 -2
- package/indirect.js +2 -2
- package/package.json +2 -2
- package/src/koffi/src/abi_arm32.cc +4 -4
- package/src/koffi/src/abi_arm64.cc +4 -4
- package/src/koffi/src/abi_riscv64.cc +4 -4
- package/src/koffi/src/abi_x64_sysv.cc +4 -4
- package/src/koffi/src/abi_x64_win.cc +4 -4
- package/src/koffi/src/abi_x86.cc +4 -4
- package/src/koffi/src/call.cc +6 -6
- package/src/koffi/src/call.hh +2 -2
- package/src/koffi/src/ffi.cc +0 -9
- package/src/koffi/src/ffi.hh +0 -1
- package/src/koffi/src/util.cc +7 -13
- package/src/koffi/src/util.hh +9 -1
- package/vendor/node-addon-api/CHANGELOG.md +76 -0
- package/vendor/node-addon-api/LICENSE.md +2 -6
- package/vendor/node-addon-api/README.md +10 -9
- package/vendor/node-addon-api/benchmark/binding.gyp +4 -4
- package/vendor/node-addon-api/common.gypi +1 -2
- package/vendor/node-addon-api/doc/array.md +1 -1
- package/vendor/node-addon-api/doc/async_worker_variants.md +16 -16
- package/vendor/node-addon-api/doc/cmake-js.md +1 -1
- package/vendor/node-addon-api/doc/env.md +11 -0
- package/vendor/node-addon-api/doc/hierarchy.md +2 -0
- package/vendor/node-addon-api/doc/setup.md +53 -71
- package/vendor/node-addon-api/doc/syntax_error.md +66 -0
- package/vendor/node-addon-api/doc/value.md +2 -0
- package/vendor/node-addon-api/index.js +2 -1
- package/vendor/node-addon-api/napi-inl.h +68 -65
- package/vendor/node-addon-api/napi.h +15 -5
- package/vendor/node-addon-api/node_addon_api.gyp +32 -0
- package/vendor/node-addon-api/package.json +14 -3
- package/vendor/node-addon-api/test/addon.cc +7 -1
- package/vendor/node-addon-api/test/addon.js +5 -9
- package/vendor/node-addon-api/test/addon_data.cc +3 -3
- package/vendor/node-addon-api/test/addon_data.js +16 -38
- package/vendor/node-addon-api/test/bigint.cc +0 -1
- package/vendor/node-addon-api/test/binding.cc +12 -1
- package/vendor/node-addon-api/test/binding.gyp +10 -8
- package/vendor/node-addon-api/test/child_processes/addon.js +11 -0
- package/vendor/node-addon-api/test/child_processes/addon_data.js +24 -0
- package/vendor/node-addon-api/test/child_processes/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/child_processes/threadsafe_function_exception.js +33 -0
- package/vendor/node-addon-api/test/child_processes/typed_threadsafe_function_exception.js +19 -0
- package/vendor/node-addon-api/test/common/index.js +57 -3
- package/vendor/node-addon-api/test/env_misc.cc +25 -0
- package/vendor/node-addon-api/test/env_misc.js +12 -0
- package/vendor/node-addon-api/test/error.cc +47 -0
- package/vendor/node-addon-api/test/error.js +16 -0
- package/vendor/node-addon-api/test/index.js +5 -0
- package/vendor/node-addon-api/test/objectwrap_function.cc +10 -12
- package/vendor/node-addon-api/test/objectwrap_function.js +4 -20
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.cc +50 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.js +20 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc +39 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js +13 -0
|
@@ -52,9 +52,9 @@ virtual void Napi::AsyncProgressWorker::OnOK();
|
|
|
52
52
|
### OnProgress
|
|
53
53
|
|
|
54
54
|
This method is invoked when the computation in the
|
|
55
|
-
`Napi::AsyncProgressWorker::
|
|
55
|
+
`Napi::AsyncProgressWorker::ExecutionProgress::Send` method was called during
|
|
56
56
|
worker thread execution. This method can also be triggered via a call to
|
|
57
|
-
`Napi::AsyncProgress[Queue]Worker::
|
|
57
|
+
`Napi::AsyncProgress[Queue]Worker::ExecutionProgress::Signal`, in which case the
|
|
58
58
|
`data` parameter will be `nullptr`.
|
|
59
59
|
|
|
60
60
|
```cpp
|
|
@@ -227,7 +227,7 @@ unexpected upcoming thread safe calls.
|
|
|
227
227
|
virtual Napi::AsyncProgressWorker::~AsyncProgressWorker();
|
|
228
228
|
```
|
|
229
229
|
|
|
230
|
-
# AsyncProgressWorker::
|
|
230
|
+
# AsyncProgressWorker::ExecutionProgress
|
|
231
231
|
|
|
232
232
|
A bridge class created before the worker thread execution of `Napi::AsyncProgressWorker::Execute`.
|
|
233
233
|
|
|
@@ -235,15 +235,15 @@ A bridge class created before the worker thread execution of `Napi::AsyncProgres
|
|
|
235
235
|
|
|
236
236
|
### Send
|
|
237
237
|
|
|
238
|
-
`Napi::AsyncProgressWorker::
|
|
238
|
+
`Napi::AsyncProgressWorker::ExecutionProgress::Send` takes two arguments, a pointer
|
|
239
239
|
to a generic type of data, and a `size_t` to indicate how many items the pointer is
|
|
240
240
|
pointing to.
|
|
241
241
|
|
|
242
242
|
The data pointed to will be copied to internal slots of `Napi::AsyncProgressWorker` so
|
|
243
|
-
after the call to `Napi::AsyncProgressWorker::
|
|
243
|
+
after the call to `Napi::AsyncProgressWorker::ExecutionProgress::Send` the data can
|
|
244
244
|
be safely released.
|
|
245
245
|
|
|
246
|
-
Note that `Napi::AsyncProgressWorker::
|
|
246
|
+
Note that `Napi::AsyncProgressWorker::ExecutionProgress::Send` merely guarantees
|
|
247
247
|
**eventual** invocation of `Napi::AsyncProgressWorker::OnProgress`, which means
|
|
248
248
|
multiple send might be coalesced into single invocation of `Napi::AsyncProgressWorker::OnProgress`
|
|
249
249
|
with latest data. If you would like to guarantee that there is one invocation of
|
|
@@ -251,16 +251,16 @@ with latest data. If you would like to guarantee that there is one invocation of
|
|
|
251
251
|
class instead which is documented further down this page.
|
|
252
252
|
|
|
253
253
|
```cpp
|
|
254
|
-
void Napi::AsyncProgressWorker::
|
|
254
|
+
void Napi::AsyncProgressWorker::ExecutionProgress::Send(const T* data, size_t count) const;
|
|
255
255
|
```
|
|
256
256
|
|
|
257
257
|
### Signal
|
|
258
258
|
|
|
259
|
-
`Napi::AsyncProgressWorker::
|
|
259
|
+
`Napi::AsyncProgressWorker::ExecutionProgress::Signal` triggers an invocation of
|
|
260
260
|
`Napi::AsyncProgressWorker::OnProgress` with `nullptr` as the `data` parameter.
|
|
261
261
|
|
|
262
262
|
```cpp
|
|
263
|
-
void Napi::AsyncProgressWorker::
|
|
263
|
+
void Napi::AsyncProgressWorker::ExecutionProgress::Signal();
|
|
264
264
|
```
|
|
265
265
|
|
|
266
266
|
## Example
|
|
@@ -402,7 +402,7 @@ thread in the order it was committed.
|
|
|
402
402
|
For the most basic use, only the `Napi::AsyncProgressQueueWorker::Execute` and
|
|
403
403
|
`Napi::AsyncProgressQueueWorker::OnProgress` method must be implemented in a subclass.
|
|
404
404
|
|
|
405
|
-
# AsyncProgressQueueWorker::
|
|
405
|
+
# AsyncProgressQueueWorker::ExecutionProgress
|
|
406
406
|
|
|
407
407
|
A bridge class created before the worker thread execution of `Napi::AsyncProgressQueueWorker::Execute`.
|
|
408
408
|
|
|
@@ -410,30 +410,30 @@ A bridge class created before the worker thread execution of `Napi::AsyncProgres
|
|
|
410
410
|
|
|
411
411
|
### Send
|
|
412
412
|
|
|
413
|
-
`Napi::AsyncProgressQueueWorker::
|
|
413
|
+
`Napi::AsyncProgressQueueWorker::ExecutionProgress::Send` takes two arguments, a pointer
|
|
414
414
|
to a generic type of data, and a `size_t` to indicate how many items the pointer is
|
|
415
415
|
pointing to.
|
|
416
416
|
|
|
417
417
|
The data pointed to will be copied to internal slots of `Napi::AsyncProgressQueueWorker` so
|
|
418
|
-
after the call to `Napi::AsyncProgressQueueWorker::
|
|
418
|
+
after the call to `Napi::AsyncProgressQueueWorker::ExecutionProgress::Send` the data can
|
|
419
419
|
be safely released.
|
|
420
420
|
|
|
421
|
-
`Napi::AsyncProgressQueueWorker::
|
|
421
|
+
`Napi::AsyncProgressQueueWorker::ExecutionProgress::Send` guarantees invocation
|
|
422
422
|
of `Napi::AsyncProgressQueueWorker::OnProgress`, which means multiple `Send`
|
|
423
423
|
call will result in the in-order invocation of `Napi::AsyncProgressQueueWorker::OnProgress`
|
|
424
424
|
with each data item.
|
|
425
425
|
|
|
426
426
|
```cpp
|
|
427
|
-
void Napi::AsyncProgressQueueWorker::
|
|
427
|
+
void Napi::AsyncProgressQueueWorker::ExecutionProgress::Send(const T* data, size_t count) const;
|
|
428
428
|
```
|
|
429
429
|
|
|
430
430
|
### Signal
|
|
431
431
|
|
|
432
|
-
`Napi::AsyncProgressQueueWorker::
|
|
432
|
+
`Napi::AsyncProgressQueueWorker::ExecutionProgress::Signal` triggers an invocation of
|
|
433
433
|
`Napi::AsyncProgressQueueWorker::OnProgress` with `nullptr` as the `data` parameter.
|
|
434
434
|
|
|
435
435
|
```cpp
|
|
436
|
-
void Napi::AsyncProgressQueueWorker::
|
|
436
|
+
void Napi::AsyncProgressQueueWorker::ExecutionProgress::Signal() const;
|
|
437
437
|
```
|
|
438
438
|
|
|
439
439
|
## Example
|
|
@@ -51,7 +51,7 @@ If your Node-API native add-on uses the optional [**node-addon-api**](https://gi
|
|
|
51
51
|
|
|
52
52
|
## Example
|
|
53
53
|
|
|
54
|
-
A working example of an Node-API native addon built using CMake.js can be found on the [node-addon-examples repository](https://github.com/nodejs/node-addon-examples/tree/
|
|
54
|
+
A working example of an Node-API native addon built using CMake.js can be found on the [node-addon-examples repository](https://github.com/nodejs/node-addon-examples/tree/main/src/8-tooling/build_with_cmake#building-node-api-addons-using-cmakejs).
|
|
55
55
|
|
|
56
56
|
## **CMake** Reference
|
|
57
57
|
|
|
@@ -131,6 +131,17 @@ addon. The item will be passed to the function `fini` which gets called when an
|
|
|
131
131
|
instance of the addon is unloaded. This overload accepts an additional hint to
|
|
132
132
|
be passed to `fini`.
|
|
133
133
|
|
|
134
|
+
### GetModuleFileName
|
|
135
|
+
|
|
136
|
+
```cpp
|
|
137
|
+
const char* Napi::Env::GetModuleFileName() const;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Returns a A URL containing the absolute path of the location from which the
|
|
141
|
+
add-on was loaded. For a file on the local file system it will start with
|
|
142
|
+
`file://`. The string is null-terminated and owned by env and must thus not be
|
|
143
|
+
modified or freed. It is only valid while the add-on is loaded.
|
|
144
|
+
|
|
134
145
|
### AddCleanupHook
|
|
135
146
|
|
|
136
147
|
```cpp
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
| [`Napi::Reference`] | |
|
|
38
38
|
| [`Napi::String`][] | [`Napi::Name`][] |
|
|
39
39
|
| [`Napi::Symbol`][] | [`Napi::Name`][] |
|
|
40
|
+
| [`Napi::SyntaxError`][] | [`Napi::Error`][] |
|
|
40
41
|
| [`Napi::ThreadSafeFunction`][] | |
|
|
41
42
|
| [`Napi::TypeTaggable`][] | [`Napi::Value][] |
|
|
42
43
|
| [`Napi::TypeError`][] | [`Napi::Error`][] |
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
[`Napi::Reference<Napi::Object>`]: ./reference.md
|
|
83
84
|
[`Napi::String`]: ./string.md
|
|
84
85
|
[`Napi::Symbol`]: ./symbol.md
|
|
86
|
+
[`Napi::SyntaxError`]: ./syntax_error.md
|
|
85
87
|
[`Napi::ThreadSafeFunction`]: ./threadsafe_function.md
|
|
86
88
|
[`Napi::TypeError`]: ./type_error.md
|
|
87
89
|
[`Napi::TypeTaggable`]: ./type_taggable.md
|
|
@@ -17,84 +17,66 @@ To use **Node-API** in a native module:
|
|
|
17
17
|
|
|
18
18
|
1. Add a dependency on this package to `package.json`:
|
|
19
19
|
|
|
20
|
-
```json
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
2.
|
|
27
|
-
|
|
28
|
-
```gyp
|
|
29
|
-
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
3. Decide whether the package will enable C++ exceptions in the Node-API wrapper.
|
|
20
|
+
```json
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"node-addon-api": "*",
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. Decide whether the package will enable C++ exceptions in the Node-API
|
|
27
|
+
wrapper, and reference this package as a dependency in `binding.gyp`.
|
|
33
28
|
The base ABI-stable C APIs do not throw or handle C++ exceptions, but the
|
|
34
29
|
Node-API C++ wrapper classes may _optionally_
|
|
35
30
|
[integrate C++ and JavaScript exception-handling
|
|
36
31
|
](https://github.com/nodejs/node-addon-api/blob/HEAD/doc/error_handling.md).
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```gyp
|
|
81
|
-
'conditions': [
|
|
82
|
-
['OS=="mac"', {
|
|
83
|
-
'cflags+': ['-fvisibility=hidden'],
|
|
84
|
-
'xcode_settings': {
|
|
85
|
-
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
|
|
86
|
-
}
|
|
87
|
-
}]
|
|
88
|
-
]
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
5. Include `napi.h` in the native module code.
|
|
32
|
+
|
|
33
|
+
To use without C++ exceptions, add the following to `binding.gyp`:
|
|
34
|
+
|
|
35
|
+
```gyp
|
|
36
|
+
'dependencies': [
|
|
37
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api",
|
|
38
|
+
],
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
To enable that capability, add an alternative dependency in `binding.gyp`:
|
|
42
|
+
|
|
43
|
+
```gyp
|
|
44
|
+
'dependencies': [
|
|
45
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
46
|
+
],
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If you decide to use node-addon-api without C++ exceptions enabled, please
|
|
50
|
+
consider enabling node-addon-api safe API type guards to ensure the proper
|
|
51
|
+
exception handling pattern:
|
|
52
|
+
|
|
53
|
+
```gyp
|
|
54
|
+
'dependencies': [
|
|
55
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_maybe",
|
|
56
|
+
],
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
3. If you would like your native addon to support OSX, please also add the
|
|
60
|
+
following settings in the `binding.gyp` file:
|
|
61
|
+
|
|
62
|
+
```gyp
|
|
63
|
+
'conditions': [
|
|
64
|
+
['OS=="mac"', {
|
|
65
|
+
'cflags+': ['-fvisibility=hidden'],
|
|
66
|
+
'xcode_settings': {
|
|
67
|
+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
|
|
68
|
+
}
|
|
69
|
+
}]
|
|
70
|
+
]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
4. Include `napi.h` in the native module code.
|
|
92
74
|
To ensure only ABI-stable APIs are used, DO NOT include
|
|
93
75
|
`node.h`, `nan.h`, or `v8.h`.
|
|
94
76
|
|
|
95
|
-
```C++
|
|
96
|
-
#include "napi.h"
|
|
97
|
-
```
|
|
77
|
+
```C++
|
|
78
|
+
#include "napi.h"
|
|
79
|
+
```
|
|
98
80
|
|
|
99
81
|
At build time, the Node-API back-compat library code will be used only when the
|
|
100
82
|
targeted node version *does not* have Node-API built-in.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# SyntaxError
|
|
2
|
+
|
|
3
|
+
The `Napi::SyntaxError` class is a representation of the JavaScript
|
|
4
|
+
`SyntaxError` that is thrown when the engine encounters tokens or token order
|
|
5
|
+
that does not conform to the syntax of the language when parsing code.
|
|
6
|
+
|
|
7
|
+
The `Napi::SyntaxError` class inherits its behaviors from the `Napi::Error`
|
|
8
|
+
class (for more info see: [`Napi::Error`](error.md)).
|
|
9
|
+
|
|
10
|
+
For more details about error handling refer to the section titled [Error
|
|
11
|
+
handling](error_handling.md).
|
|
12
|
+
|
|
13
|
+
## Methods
|
|
14
|
+
|
|
15
|
+
### New
|
|
16
|
+
|
|
17
|
+
Creates a new instance of a `Napi::SyntaxError` object.
|
|
18
|
+
|
|
19
|
+
```cpp
|
|
20
|
+
Napi::SyntaxError::New(Napi::Env env, const char* message);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
|
|
24
|
+
object.
|
|
25
|
+
- `[in] message`: Null-terminated string to be used as the message for the
|
|
26
|
+
`Napi::SyntaxError`.
|
|
27
|
+
|
|
28
|
+
Returns an instance of a `Napi::SyntaxError` object.
|
|
29
|
+
|
|
30
|
+
### New
|
|
31
|
+
|
|
32
|
+
Creates a new instance of a `Napi::SyntaxError` object.
|
|
33
|
+
|
|
34
|
+
```cpp
|
|
35
|
+
Napi::SyntaxError::New(Napi::Env env, const std::string& message);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
|
|
39
|
+
object.
|
|
40
|
+
- `[in] message`: Reference string to be used as the message for the
|
|
41
|
+
`Napi::SyntaxError`.
|
|
42
|
+
|
|
43
|
+
Returns an instance of a `Napi::SyntaxError` object.
|
|
44
|
+
|
|
45
|
+
### Constructor
|
|
46
|
+
|
|
47
|
+
Creates a new empty instance of a `Napi::SyntaxError`.
|
|
48
|
+
|
|
49
|
+
```cpp
|
|
50
|
+
Napi::SyntaxError::SyntaxError();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Constructor
|
|
54
|
+
|
|
55
|
+
Initializes a `Napi::SyntaxError` instance from an existing Javascript error
|
|
56
|
+
object.
|
|
57
|
+
|
|
58
|
+
```cpp
|
|
59
|
+
Napi::SyntaxError::SyntaxError(napi_env env, napi_value value);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
|
|
63
|
+
object.
|
|
64
|
+
- `[in] value`: The `Napi::Error` reference to wrap.
|
|
65
|
+
|
|
66
|
+
Returns an instance of a `Napi::SyntaxError` object.
|
|
@@ -5,7 +5,8 @@ const includeDir = path.relative('.', __dirname);
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
|
|
7
7
|
include_dir: includeDir,
|
|
8
|
-
gyp: path.join(includeDir, 'node_api.gyp:nothing'),
|
|
8
|
+
gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
|
|
9
|
+
targets: path.join(includeDir, 'node_addon_api.gyp'),
|
|
9
10
|
isNodeApiBuiltin: true,
|
|
10
11
|
needsFlag: false
|
|
11
12
|
};
|
|
@@ -31,22 +31,22 @@ namespace details {
|
|
|
31
31
|
// Node.js releases. Only necessary when they are used in napi.h and napi-inl.h.
|
|
32
32
|
constexpr int napi_no_external_buffers_allowed = 22;
|
|
33
33
|
|
|
34
|
+
template <typename FreeType>
|
|
35
|
+
inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
|
|
36
|
+
delete static_cast<FreeType*>(data);
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
// Attach a data item to an object and delete it when the object gets
|
|
35
40
|
// garbage-collected.
|
|
36
41
|
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
|
|
37
42
|
// available on all supported versions of Node.js.
|
|
38
|
-
template <typename FreeType
|
|
43
|
+
template <typename FreeType,
|
|
44
|
+
napi_finalize finalizer = default_finalizer<FreeType>>
|
|
39
45
|
inline napi_status AttachData(napi_env env,
|
|
40
46
|
napi_value obj,
|
|
41
47
|
FreeType* data,
|
|
42
|
-
napi_finalize finalizer = nullptr,
|
|
43
48
|
void* hint = nullptr) {
|
|
44
49
|
napi_status status;
|
|
45
|
-
if (finalizer == nullptr) {
|
|
46
|
-
finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
|
|
47
|
-
delete static_cast<FreeType*>(data);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
50
|
#if (NAPI_VERSION < 5)
|
|
51
51
|
napi_value symbol, external;
|
|
52
52
|
status = napi_create_symbol(env, nullptr, &symbol);
|
|
@@ -263,10 +263,12 @@ struct ThreadSafeFinalize {
|
|
|
263
263
|
template <typename ContextType, typename DataType, typename CallJs, CallJs call>
|
|
264
264
|
inline typename std::enable_if<call != static_cast<CallJs>(nullptr)>::type
|
|
265
265
|
CallJsWrapper(napi_env env, napi_value jsCallback, void* context, void* data) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
266
|
+
details::WrapVoidCallback([&]() {
|
|
267
|
+
call(env,
|
|
268
|
+
Function(env, jsCallback),
|
|
269
|
+
static_cast<ContextType*>(context),
|
|
270
|
+
static_cast<DataType*>(data));
|
|
271
|
+
});
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
template <typename ContextType, typename DataType, typename CallJs, CallJs call>
|
|
@@ -275,9 +277,11 @@ CallJsWrapper(napi_env env,
|
|
|
275
277
|
napi_value jsCallback,
|
|
276
278
|
void* /*context*/,
|
|
277
279
|
void* /*data*/) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
details::WrapVoidCallback([&]() {
|
|
281
|
+
if (jsCallback != nullptr) {
|
|
282
|
+
Function(env, jsCallback).Call(0, nullptr);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
#if NAPI_VERSION > 4
|
|
@@ -572,6 +576,14 @@ void Env::DefaultFiniWithHint(Env, DataType* data, HintType*) {
|
|
|
572
576
|
}
|
|
573
577
|
#endif // NAPI_VERSION > 5
|
|
574
578
|
|
|
579
|
+
#if NAPI_VERSION > 8
|
|
580
|
+
inline const char* Env::GetModuleFileName() const {
|
|
581
|
+
const char* result;
|
|
582
|
+
napi_status status = node_api_get_module_file_name(_env, &result);
|
|
583
|
+
NAPI_THROW_IF_FAILED(*this, status, nullptr);
|
|
584
|
+
return result;
|
|
585
|
+
}
|
|
586
|
+
#endif // NAPI_VERSION > 8
|
|
575
587
|
////////////////////////////////////////////////////////////////////////////////
|
|
576
588
|
// Value class
|
|
577
589
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -1624,11 +1636,8 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) const {
|
|
|
1624
1636
|
new details::FinalizeData<T, Finalizer>(
|
|
1625
1637
|
{std::move(finalizeCallback), nullptr});
|
|
1626
1638
|
napi_status status =
|
|
1627
|
-
details::AttachData(
|
|
1628
|
-
|
|
1629
|
-
data,
|
|
1630
|
-
details::FinalizeData<T, Finalizer>::Wrapper,
|
|
1631
|
-
finalizeData);
|
|
1639
|
+
details::AttachData<T, details::FinalizeData<T, Finalizer>::Wrapper>(
|
|
1640
|
+
_env, *this, data, finalizeData);
|
|
1632
1641
|
if (status != napi_ok) {
|
|
1633
1642
|
delete finalizeData;
|
|
1634
1643
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
@@ -1642,12 +1651,9 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
|
|
|
1642
1651
|
details::FinalizeData<T, Finalizer, Hint>* finalizeData =
|
|
1643
1652
|
new details::FinalizeData<T, Finalizer, Hint>(
|
|
1644
1653
|
{std::move(finalizeCallback), finalizeHint});
|
|
1645
|
-
napi_status status = details::
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
data,
|
|
1649
|
-
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
|
|
1650
|
-
finalizeData);
|
|
1654
|
+
napi_status status = details::
|
|
1655
|
+
AttachData<T, details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>(
|
|
1656
|
+
_env, *this, data, finalizeData);
|
|
1651
1657
|
if (status != napi_ok) {
|
|
1652
1658
|
delete finalizeData;
|
|
1653
1659
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
@@ -2623,7 +2629,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env, size_t length) {
|
|
|
2623
2629
|
napi_status status =
|
|
2624
2630
|
napi_create_buffer(env, length * sizeof(T), &data, &value);
|
|
2625
2631
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2626
|
-
return Buffer(env, value
|
|
2632
|
+
return Buffer(env, value);
|
|
2627
2633
|
}
|
|
2628
2634
|
|
|
2629
2635
|
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
@@ -2633,7 +2639,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env, T* data, size_t length) {
|
|
|
2633
2639
|
napi_status status = napi_create_external_buffer(
|
|
2634
2640
|
env, length * sizeof(T), data, nullptr, nullptr, &value);
|
|
2635
2641
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2636
|
-
return Buffer(env, value
|
|
2642
|
+
return Buffer(env, value);
|
|
2637
2643
|
}
|
|
2638
2644
|
|
|
2639
2645
|
template <typename T>
|
|
@@ -2657,7 +2663,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2657
2663
|
delete finalizeData;
|
|
2658
2664
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
2659
2665
|
}
|
|
2660
|
-
return Buffer(env, value
|
|
2666
|
+
return Buffer(env, value);
|
|
2661
2667
|
}
|
|
2662
2668
|
|
|
2663
2669
|
template <typename T>
|
|
@@ -2682,7 +2688,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2682
2688
|
delete finalizeData;
|
|
2683
2689
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
2684
2690
|
}
|
|
2685
|
-
return Buffer(env, value
|
|
2691
|
+
return Buffer(env, value);
|
|
2686
2692
|
}
|
|
2687
2693
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2688
2694
|
|
|
@@ -2699,7 +2705,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env, T* data, size_t length) {
|
|
|
2699
2705
|
#ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2700
2706
|
}
|
|
2701
2707
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2702
|
-
return Buffer(env, value
|
|
2708
|
+
return Buffer(env, value);
|
|
2703
2709
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2704
2710
|
}
|
|
2705
2711
|
|
|
@@ -2733,7 +2739,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2733
2739
|
delete finalizeData;
|
|
2734
2740
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
2735
2741
|
}
|
|
2736
|
-
return Buffer(env, value
|
|
2742
|
+
return Buffer(env, value);
|
|
2737
2743
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
2738
2744
|
}
|
|
2739
2745
|
|
|
@@ -2769,7 +2775,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
|
|
|
2769
2775
|
delete finalizeData;
|
|
2770
2776
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
2771
2777
|
}
|
|
2772
|
-
return Buffer(env, value
|
|
2778
|
+
return Buffer(env, value);
|
|
2773
2779
|
#endif
|
|
2774
2780
|
}
|
|
2775
2781
|
|
|
@@ -2793,42 +2799,20 @@ inline void Buffer<T>::CheckCast(napi_env env, napi_value value) {
|
|
|
2793
2799
|
}
|
|
2794
2800
|
|
|
2795
2801
|
template <typename T>
|
|
2796
|
-
inline Buffer<T>::Buffer() : Uint8Array()
|
|
2802
|
+
inline Buffer<T>::Buffer() : Uint8Array() {}
|
|
2797
2803
|
|
|
2798
2804
|
template <typename T>
|
|
2799
2805
|
inline Buffer<T>::Buffer(napi_env env, napi_value value)
|
|
2800
|
-
: Uint8Array(env, value)
|
|
2801
|
-
|
|
2802
|
-
template <typename T>
|
|
2803
|
-
inline Buffer<T>::Buffer(napi_env env, napi_value value, size_t length, T* data)
|
|
2804
|
-
: Uint8Array(env, value), _length(length), _data(data) {}
|
|
2806
|
+
: Uint8Array(env, value) {}
|
|
2805
2807
|
|
|
2806
2808
|
template <typename T>
|
|
2807
2809
|
inline size_t Buffer<T>::Length() const {
|
|
2808
|
-
|
|
2809
|
-
return _length;
|
|
2810
|
+
return ByteLength() / sizeof(T);
|
|
2810
2811
|
}
|
|
2811
2812
|
|
|
2812
2813
|
template <typename T>
|
|
2813
2814
|
inline T* Buffer<T>::Data() const {
|
|
2814
|
-
|
|
2815
|
-
return _data;
|
|
2816
|
-
}
|
|
2817
|
-
|
|
2818
|
-
template <typename T>
|
|
2819
|
-
inline void Buffer<T>::EnsureInfo() const {
|
|
2820
|
-
// The Buffer instance may have been constructed from a napi_value whose
|
|
2821
|
-
// length/data are not yet known. Fetch and cache these values just once,
|
|
2822
|
-
// since they can never change during the lifetime of the Buffer.
|
|
2823
|
-
if (_data == nullptr) {
|
|
2824
|
-
size_t byteLength;
|
|
2825
|
-
void* voidData;
|
|
2826
|
-
napi_status status =
|
|
2827
|
-
napi_get_buffer_info(_env, _value, &voidData, &byteLength);
|
|
2828
|
-
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
2829
|
-
_length = byteLength / sizeof(T);
|
|
2830
|
-
_data = static_cast<T*>(voidData);
|
|
2831
|
-
}
|
|
2815
|
+
return reinterpret_cast<T*>(const_cast<uint8_t*>(Uint8Array::Data()));
|
|
2832
2816
|
}
|
|
2833
2817
|
|
|
2834
2818
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -3157,6 +3141,23 @@ inline RangeError::RangeError() : Error() {}
|
|
|
3157
3141
|
inline RangeError::RangeError(napi_env env, napi_value value)
|
|
3158
3142
|
: Error(env, value) {}
|
|
3159
3143
|
|
|
3144
|
+
#if NAPI_VERSION > 8
|
|
3145
|
+
inline SyntaxError SyntaxError::New(napi_env env, const char* message) {
|
|
3146
|
+
return Error::New<SyntaxError>(
|
|
3147
|
+
env, message, std::strlen(message), node_api_create_syntax_error);
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
inline SyntaxError SyntaxError::New(napi_env env, const std::string& message) {
|
|
3151
|
+
return Error::New<SyntaxError>(
|
|
3152
|
+
env, message.c_str(), message.size(), node_api_create_syntax_error);
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
inline SyntaxError::SyntaxError() : Error() {}
|
|
3156
|
+
|
|
3157
|
+
inline SyntaxError::SyntaxError(napi_env env, napi_value value)
|
|
3158
|
+
: Error(env, value) {}
|
|
3159
|
+
#endif // NAPI_VERSION > 8
|
|
3160
|
+
|
|
3160
3161
|
////////////////////////////////////////////////////////////////////////////////
|
|
3161
3162
|
// Reference<T> class
|
|
3162
3163
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -6110,13 +6111,15 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
|
|
|
6110
6111
|
return;
|
|
6111
6112
|
}
|
|
6112
6113
|
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6114
|
+
details::WrapVoidCallback([&]() {
|
|
6115
|
+
if (data != nullptr) {
|
|
6116
|
+
auto* callbackWrapper = static_cast<CallbackWrapper*>(data);
|
|
6117
|
+
(*callbackWrapper)(env, Function(env, jsCallback));
|
|
6118
|
+
delete callbackWrapper;
|
|
6119
|
+
} else if (jsCallback != nullptr) {
|
|
6120
|
+
Function(env, jsCallback).Call({});
|
|
6121
|
+
}
|
|
6122
|
+
});
|
|
6120
6123
|
}
|
|
6121
6124
|
|
|
6122
6125
|
////////////////////////////////////////////////////////////////////////////////
|