koffi 2.3.17 → 2.3.18
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 +6 -0
- package/build/2.3.18/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.18/koffi_darwin_x64/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_freebsd_arm64/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_freebsd_ia32/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_freebsd_x64/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_linux_arm32hf/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_linux_arm64/koffi.node +0 -0
- package/build/2.3.18/koffi_linux_ia32/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_linux_x64/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_openbsd_ia32/koffi.node +0 -0
- package/build/{2.3.17 → 2.3.18}/koffi_openbsd_x64/koffi.node +0 -0
- package/build/2.3.18/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.3.18/koffi_win32_ia32/koffi.node +0 -0
- package/build/2.3.18/koffi_win32_x64/koffi.node +0 -0
- package/package.json +2 -2
- package/src/koffi/src/call.cc +3 -0
- package/src/koffi/src/ffi.cc +3 -4
- package/src/koffi/src/ffi.hh +2 -0
- package/vendor/node-addon-api/CHANGELOG.md +41 -0
- package/vendor/node-addon-api/README.md +1 -1
- package/vendor/node-addon-api/doc/array_buffer.md +10 -0
- package/vendor/node-addon-api/doc/buffer.md +97 -0
- package/vendor/node-addon-api/doc/env.md +2 -2
- package/vendor/node-addon-api/doc/external.md +2 -2
- package/vendor/node-addon-api/doc/external_buffer.md +18 -0
- package/vendor/node-addon-api/doc/hierarchy.md +4 -2
- package/vendor/node-addon-api/doc/object.md +2 -29
- package/vendor/node-addon-api/doc/type_taggable.md +40 -0
- package/vendor/node-addon-api/doc/value.md +7 -1
- package/vendor/node-addon-api/napi-inl.h +317 -22
- package/vendor/node-addon-api/napi.h +84 -7
- package/vendor/node-addon-api/package.json +9 -1
- package/vendor/node-addon-api/test/async_progress_worker.cc +15 -3
- package/vendor/node-addon-api/test/binding.cc +4 -2
- package/vendor/node-addon-api/test/binding.gyp +11 -1
- package/vendor/node-addon-api/test/buffer.cc +13 -19
- package/vendor/node-addon-api/test/buffer.h +26 -0
- package/vendor/node-addon-api/test/buffer.js +82 -0
- package/vendor/node-addon-api/test/buffer_new_or_copy-inl.h +68 -0
- package/vendor/node-addon-api/test/buffer_no_external.cc +24 -0
- package/vendor/node-addon-api/test/error.cc +101 -0
- package/vendor/node-addon-api/test/error.js +15 -1
- package/vendor/node-addon-api/test/index.js +1 -1
- package/vendor/node-addon-api/test/object_reference.cc +220 -22
- package/vendor/node-addon-api/test/object_reference.js +83 -80
- package/vendor/node-addon-api/test/objectwrap.cc +23 -3
- package/vendor/node-addon-api/test/objectwrap.js +14 -2
- package/vendor/node-addon-api/test/reference.cc +55 -1
- package/vendor/node-addon-api/test/reference.js +7 -1
- package/vendor/node-addon-api/test/type_taggable.cc +66 -0
- package/vendor/node-addon-api/test/type_taggable.js +60 -0
- package/vendor/node-addon-api/test/value_type_cast.cc +60 -0
- package/vendor/node-addon-api/test/value_type_cast.js +106 -0
- package/vendor/node-addon-api/tools/eslint-format.js +2 -2
- package/build/2.3.17/koffi_darwin_arm64/koffi.node +0 -0
- package/build/2.3.17/koffi_darwin_x64/koffi.node +0 -0
- package/build/2.3.17/koffi_linux_ia32/koffi.node +0 -0
- package/build/2.3.17/koffi_win32_arm64/koffi.node +0 -0
- package/build/2.3.17/koffi_win32_ia32/koffi.node +0 -0
- package/build/2.3.17/koffi_win32_x64/koffi.node +0 -0
- package/vendor/node-addon-api/test/object/object_type_tag.cc +0 -39
- package/vendor/node-addon-api/test/object/object_type_tag.js +0 -55
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_arm64/koffi.exp +0 -0
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_arm64/koffi.lib +0 -0
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_ia32/koffi.exp +0 -0
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_ia32/koffi.lib +0 -0
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_x64/koffi.exp +0 -0
- /package/build/{2.3.17 → 2.3.18}/koffi_win32_x64/koffi.lib +0 -0
package/CHANGELOG.md
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/koffi/src/call.cc
CHANGED
|
@@ -77,8 +77,10 @@ void CallData::Dispose()
|
|
|
77
77
|
int16_t idx = used_trampolines[i];
|
|
78
78
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
79
79
|
|
|
80
|
+
RG_ASSERT(trampoline->instance == instance);
|
|
80
81
|
RG_ASSERT(!trampoline->func.IsEmpty());
|
|
81
82
|
|
|
83
|
+
trampoline->instance = nullptr;
|
|
82
84
|
trampoline->func.Reset();
|
|
83
85
|
trampoline->recv.Reset();
|
|
84
86
|
|
|
@@ -1225,6 +1227,7 @@ void *CallData::ReserveTrampoline(const FunctionInfo *proto, Napi::Function func
|
|
|
1225
1227
|
|
|
1226
1228
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
1227
1229
|
|
|
1230
|
+
trampoline->instance = instance;
|
|
1228
1231
|
trampoline->proto = proto;
|
|
1229
1232
|
trampoline->func.Reset(func, 1);
|
|
1230
1233
|
trampoline->recv.Reset();
|
package/src/koffi/src/ffi.cc
CHANGED
|
@@ -1654,6 +1654,7 @@ static Napi::Value RegisterCallback(const Napi::CallbackInfo &info)
|
|
|
1654
1654
|
|
|
1655
1655
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
1656
1656
|
|
|
1657
|
+
trampoline->instance = instance;
|
|
1657
1658
|
trampoline->proto = type->ref.proto;
|
|
1658
1659
|
trampoline->func.Reset(func, 1);
|
|
1659
1660
|
if (!IsNullOrUndefined(recv)) {
|
|
@@ -1954,10 +1955,8 @@ InstanceData::~InstanceData()
|
|
|
1954
1955
|
for (int16_t idx = 0; idx < MaxTrampolines; idx++) {
|
|
1955
1956
|
TrampolineInfo *trampoline = &shared.trampolines[idx];
|
|
1956
1957
|
|
|
1957
|
-
if (trampoline->
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
if (trampoline->func.Env().GetInstanceData<InstanceData>() == this) {
|
|
1958
|
+
if (trampoline->instance == this) {
|
|
1959
|
+
trampoline->instance = nullptr;
|
|
1961
1960
|
trampoline->func.Reset();
|
|
1962
1961
|
trampoline->recv.Reset();
|
|
1963
1962
|
}
|
package/src/koffi/src/ffi.hh
CHANGED
|
@@ -305,6 +305,8 @@ RG_STATIC_ASSERT(DefaultMaxAsyncCalls >= DefaultResidentAsyncPools);
|
|
|
305
305
|
RG_STATIC_ASSERT(MaxAsyncCalls >= DefaultMaxAsyncCalls);
|
|
306
306
|
|
|
307
307
|
struct TrampolineInfo {
|
|
308
|
+
InstanceData *instance;
|
|
309
|
+
|
|
308
310
|
const FunctionInfo *proto;
|
|
309
311
|
Napi::FunctionReference func;
|
|
310
312
|
Napi::Reference<Napi::Value> recv;
|
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# node-addon-api Changelog
|
|
2
2
|
|
|
3
|
+
## 2023-04-20 Version 6.1.0, @NickNaso
|
|
4
|
+
|
|
5
|
+
### Notable changes
|
|
6
|
+
|
|
7
|
+
#### API
|
|
8
|
+
|
|
9
|
+
- Enforce type checks on `Napi::Value::As()`.
|
|
10
|
+
- Added `Napi::TypeTaggable` class.
|
|
11
|
+
- Defined `NAPI_HAS_THREADS` to make TSFN available on Emscripten.
|
|
12
|
+
- Defined `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` and
|
|
13
|
+
`Napi::Buffer::NewOrCopy()` to handle the support for external buffers.
|
|
14
|
+
|
|
15
|
+
#### TEST
|
|
16
|
+
|
|
17
|
+
- Added tests for `Napi::Reference<T>` class.
|
|
18
|
+
- Added tests for copy/move semantics.
|
|
19
|
+
- Added tests for `Napi::RangeError` and `Napi::TypeError` class.
|
|
20
|
+
- Fixed inconsistent failure executing test suite.
|
|
21
|
+
- Added tests for `Napi::ObjectReference<T>` class.
|
|
22
|
+
- Added tests for `Napi::ObjectWrap<T>` class.
|
|
23
|
+
|
|
24
|
+
### Documentation
|
|
25
|
+
|
|
26
|
+
- Added documentation for `Napi::TypeTaggable`.
|
|
27
|
+
- Some minor fixes all over the documentation.
|
|
28
|
+
|
|
29
|
+
### Commits
|
|
30
|
+
|
|
31
|
+
- \[[`5adb896782`](https://github.com/nodejs/node-addon-api/commit/5adb896782)] - **src**: enforce type checks on Napi::Value::As() (#1281) (Chengzhong Wu)
|
|
32
|
+
- \[[`d9faac7ec2`](https://github.com/nodejs/node-addon-api/commit/d9faac7ec2)] - Fix exits/exists typo in docs for Env::AddCleanupHook() (#1306) (Mathias Stearn)
|
|
33
|
+
- \[[`164459ca03`](https://github.com/nodejs/node-addon-api/commit/164459ca03)] - **doc**: update class hierarchy for TypeTaggable (Gabriel Schulhof) [#1303](https://github.com/nodejs/node-addon-api/pull/1303)
|
|
34
|
+
- \[[`d01304437c`](https://github.com/nodejs/node-addon-api/commit/d01304437c)] - **src**: interject class TypeTaggable (Gabriel Schulhof) [#1298](https://github.com/nodejs/node-addon-api/pull/1298)
|
|
35
|
+
- \[[`d4942ccd4f`](https://github.com/nodejs/node-addon-api/commit/d4942ccd4f)] - **test**: Complete test coverage for Reference\<T> class (#1277) (Jack)
|
|
36
|
+
- \[[`a8ad7e7a7b`](https://github.com/nodejs/node-addon-api/commit/a8ad7e7a7b)] - **test**: Add tests for copy/move semantics (JckXia) [#1295](https://github.com/nodejs/node-addon-api/pull/1295)
|
|
37
|
+
- \[[`e484327344`](https://github.com/nodejs/node-addon-api/commit/e484327344)] - Add test coverage for typed and range err (#1280) (Jack)
|
|
38
|
+
- \[[`ebc7858593`](https://github.com/nodejs/node-addon-api/commit/ebc7858593)] - **test**: Update wait with a condition (#1297) (Jack)
|
|
39
|
+
- \[[`0b53d885f5`](https://github.com/nodejs/node-addon-api/commit/0b53d885f5)] - **src**: define `NAPI_HAS_THREADS` (toyobayashi) [#1283](https://github.com/nodejs/node-addon-api/pull/1283)
|
|
40
|
+
- \[[`464610babf`](https://github.com/nodejs/node-addon-api/commit/464610babf)] - **test**: complete objectRefs tests (JckXia) [#1274](https://github.com/nodejs/node-addon-api/pull/1274)
|
|
41
|
+
- \[[`b16c762a19`](https://github.com/nodejs/node-addon-api/commit/b16c762a19)] - **src**: handle no support for external buffers (legendecas) [#1273](https://github.com/nodejs/node-addon-api/pull/1273)
|
|
42
|
+
- \[[`61b8e28720`](https://github.com/nodejs/node-addon-api/commit/61b8e28720)] - **test**: Add test covg for obj wrap (#1269) (Jack)
|
|
43
|
+
|
|
3
44
|
## 2023-02-03 Version 6.0.0, @NickNaso
|
|
4
45
|
|
|
5
46
|
### Notable changes
|
|
@@ -23,6 +23,9 @@ Returns a new `Napi::ArrayBuffer` instance.
|
|
|
23
23
|
|
|
24
24
|
### New
|
|
25
25
|
|
|
26
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
27
|
+
> See [External Buffer][] for more information.
|
|
28
|
+
|
|
26
29
|
Wraps the provided external data into a new `Napi::ArrayBuffer` instance.
|
|
27
30
|
|
|
28
31
|
The `Napi::ArrayBuffer` instance does not assume ownership for the data and
|
|
@@ -48,6 +51,9 @@ Returns a new `Napi::ArrayBuffer` instance.
|
|
|
48
51
|
|
|
49
52
|
### New
|
|
50
53
|
|
|
54
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
55
|
+
> See [External Buffer][] for more information.
|
|
56
|
+
|
|
51
57
|
Wraps the provided external data into a new `Napi::ArrayBuffer` instance.
|
|
52
58
|
|
|
53
59
|
The `Napi::ArrayBuffer` instance does not assume ownership for the data and
|
|
@@ -74,6 +80,9 @@ Returns a new `Napi::ArrayBuffer` instance.
|
|
|
74
80
|
|
|
75
81
|
### New
|
|
76
82
|
|
|
83
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
84
|
+
> See [External Buffer][] for more information.
|
|
85
|
+
|
|
77
86
|
Wraps the provided external data into a new `Napi::ArrayBuffer` instance.
|
|
78
87
|
|
|
79
88
|
The `Napi::ArrayBuffer` instance does not assume ownership for the data and expects it
|
|
@@ -153,3 +162,4 @@ bool Napi::ArrayBuffer::IsDetached() const;
|
|
|
153
162
|
Returns `true` if this `ArrayBuffer` has been detached.
|
|
154
163
|
|
|
155
164
|
[`Napi::Object`]: ./object.md
|
|
165
|
+
[External Buffer]: ./external_buffer.md
|
|
@@ -22,6 +22,9 @@ Returns a new `Napi::Buffer` object.
|
|
|
22
22
|
|
|
23
23
|
### New
|
|
24
24
|
|
|
25
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
26
|
+
> See [External Buffer][] for more information.
|
|
27
|
+
|
|
25
28
|
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
26
29
|
|
|
27
30
|
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
@@ -47,6 +50,9 @@ Returns a new `Napi::Buffer` object.
|
|
|
47
50
|
|
|
48
51
|
### New
|
|
49
52
|
|
|
53
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
54
|
+
> See [External Buffer][] for more information.
|
|
55
|
+
|
|
50
56
|
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
51
57
|
|
|
52
58
|
The `Napi::Buffer` object does not assume ownership for the data and expects it
|
|
@@ -72,6 +78,9 @@ Returns a new `Napi::Buffer` object.
|
|
|
72
78
|
|
|
73
79
|
### New
|
|
74
80
|
|
|
81
|
+
> When `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` is defined, this method is not available.
|
|
82
|
+
> See [External Buffer][] for more information.
|
|
83
|
+
|
|
75
84
|
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
76
85
|
|
|
77
86
|
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
@@ -98,6 +107,93 @@ static Napi::Buffer<T> Napi::Buffer::New(napi_env env,
|
|
|
98
107
|
|
|
99
108
|
Returns a new `Napi::Buffer` object.
|
|
100
109
|
|
|
110
|
+
### NewOrCopy
|
|
111
|
+
|
|
112
|
+
Wraps the provided external data into a new `Napi::Buffer` object. When the
|
|
113
|
+
[external buffer][] is not supported, allocates a new `Napi::Buffer` object and
|
|
114
|
+
copies the provided external data into it.
|
|
115
|
+
|
|
116
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
117
|
+
valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
|
|
118
|
+
collection this overload is only suitable for data which is static and never
|
|
119
|
+
needs to be freed.
|
|
120
|
+
|
|
121
|
+
This factory method will not provide the caller with an opportunity to free the
|
|
122
|
+
data when the `Napi::Buffer` gets garbage-collected. If you need to free the
|
|
123
|
+
data retained by the `Napi::Buffer` object please use other variants of the
|
|
124
|
+
`Napi::Buffer::New` factory method that accept `Napi::Finalizer`, which is a
|
|
125
|
+
function that will be invoked when the `Napi::Buffer` object has been
|
|
126
|
+
destroyed.
|
|
127
|
+
|
|
128
|
+
```cpp
|
|
129
|
+
static Napi::Buffer<T> Napi::Buffer::NewOrCopy(napi_env env, T* data, size_t length);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
133
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
134
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
135
|
+
|
|
136
|
+
Returns a new `Napi::Buffer` object.
|
|
137
|
+
|
|
138
|
+
### NewOrCopy
|
|
139
|
+
|
|
140
|
+
Wraps the provided external data into a new `Napi::Buffer` object. When the
|
|
141
|
+
[external buffer][] is not supported, allocates a new `Napi::Buffer` object and
|
|
142
|
+
copies the provided external data into it and the `finalizeCallback` is invoked
|
|
143
|
+
immediately.
|
|
144
|
+
|
|
145
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it
|
|
146
|
+
to be valid for the lifetime of the object. The data can only be freed once the
|
|
147
|
+
`finalizeCallback` is invoked to indicate that the `Napi::Buffer` has been released.
|
|
148
|
+
|
|
149
|
+
```cpp
|
|
150
|
+
template <typename Finalizer>
|
|
151
|
+
static Napi::Buffer<T> Napi::Buffer::NewOrCopy(napi_env env,
|
|
152
|
+
T* data,
|
|
153
|
+
size_t length,
|
|
154
|
+
Finalizer finalizeCallback);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
158
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
159
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
160
|
+
- `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
|
|
161
|
+
destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
|
|
162
|
+
external data pointer), and return `void`.
|
|
163
|
+
|
|
164
|
+
Returns a new `Napi::Buffer` object.
|
|
165
|
+
|
|
166
|
+
### NewOrCopy
|
|
167
|
+
|
|
168
|
+
Wraps the provided external data into a new `Napi::Buffer` object. When the
|
|
169
|
+
[external buffer][] is not supported, allocates a new `Napi::Buffer` object and
|
|
170
|
+
copies the provided external data into it and the `finalizeCallback` is invoked
|
|
171
|
+
immediately.
|
|
172
|
+
|
|
173
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
174
|
+
valid for the lifetime of the object. The data can only be freed once the
|
|
175
|
+
`finalizeCallback` is invoked to indicate that the `Napi::Buffer` has been released.
|
|
176
|
+
|
|
177
|
+
```cpp
|
|
178
|
+
template <typename Finalizer, typename Hint>
|
|
179
|
+
static Napi::Buffer<T> Napi::Buffer::NewOrCopy(napi_env env,
|
|
180
|
+
T* data,
|
|
181
|
+
size_t length,
|
|
182
|
+
Finalizer finalizeCallback,
|
|
183
|
+
Hint* finalizeHint);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
187
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
188
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
189
|
+
- `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
|
|
190
|
+
destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
|
|
191
|
+
external data pointer) and `Hint*`, and return `void`.
|
|
192
|
+
- `[in] finalizeHint`: The hint to be passed as the second parameter of the
|
|
193
|
+
finalize callback.
|
|
194
|
+
|
|
195
|
+
Returns a new `Napi::Buffer` object.
|
|
196
|
+
|
|
101
197
|
### Copy
|
|
102
198
|
|
|
103
199
|
Allocates a new `Napi::Buffer` object and copies the provided external data into it.
|
|
@@ -148,3 +244,4 @@ size_t Napi::Buffer::Length() const;
|
|
|
148
244
|
Returns the number of `T` elements in the external data.
|
|
149
245
|
|
|
150
246
|
[`Napi::Uint8Array`]: ./typed_array_of.md
|
|
247
|
+
[External Buffer]: ./external_buffer.md
|
|
@@ -138,7 +138,7 @@ template <typename Hook>
|
|
|
138
138
|
CleanupHook<Hook> AddCleanupHook(Hook hook);
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
- `[in] hook`: A function to call when the environment
|
|
141
|
+
- `[in] hook`: A function to call when the environment exits. Accepts a
|
|
142
142
|
function of the form `void ()`.
|
|
143
143
|
|
|
144
144
|
Registers `hook` as a function to be run once the current Node.js environment
|
|
@@ -156,7 +156,7 @@ template <typename Hook, typename Arg>
|
|
|
156
156
|
CleanupHook<Hook, Arg> AddCleanupHook(Hook hook, Arg* arg);
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
- `[in] hook`: A function to call when the environment
|
|
159
|
+
- `[in] hook`: A function to call when the environment exits. Accepts a
|
|
160
160
|
function of the form `void (Arg* arg)`.
|
|
161
161
|
- `[in] arg`: A pointer to data that will be passed as the argument to `hook`.
|
|
162
162
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# External (template)
|
|
2
2
|
|
|
3
|
-
Class `Napi::External<T>` inherits from class [`Napi::
|
|
3
|
+
Class `Napi::External<T>` inherits from class [`Napi::TypeTaggable`][].
|
|
4
4
|
|
|
5
5
|
The `Napi::External` template class implements the ability to create a `Napi::Value` object with arbitrary C++ data. It is the user's responsibility to manage the memory for the arbitrary C++ data.
|
|
6
6
|
|
|
@@ -67,4 +67,4 @@ T* Napi::External::Data() const;
|
|
|
67
67
|
|
|
68
68
|
Returns a pointer to the arbitrary C++ data held by the `Napi::External` object.
|
|
69
69
|
|
|
70
|
-
[`Napi::
|
|
70
|
+
[`Napi::TypeTaggable`]: ./type_taggable.md
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# External Buffer
|
|
2
|
+
|
|
3
|
+
**Some runtimes other than Node.js have dropped support for external buffers**.
|
|
4
|
+
On runtimes other than Node.js, node-api methods may return
|
|
5
|
+
`napi_no_external_buffers_allowed` to indicate that external
|
|
6
|
+
buffers are not supported. One such runtime is Electron as
|
|
7
|
+
described in this issue
|
|
8
|
+
[electron/issues/35801](https://github.com/electron/electron/issues/35801).
|
|
9
|
+
|
|
10
|
+
In order to maintain broadest compatibility with all runtimes,
|
|
11
|
+
you may define `NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED` in your addon before
|
|
12
|
+
includes for the node-api and node-addon-api headers. Doing so will hide the
|
|
13
|
+
functions that create external buffers. This will ensure a compilation error
|
|
14
|
+
occurs if you accidentally use one of these methods.
|
|
15
|
+
|
|
16
|
+
In node-addon-api, the `Napi::Buffer::NewOrCopy` provides a convenient way to
|
|
17
|
+
create an external buffer, or allocate a new buffer and copy the data when the
|
|
18
|
+
external buffer is not supported.
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
| [`Napi::Env`][] | |
|
|
21
21
|
| [`Napi::Error`][] | [`Napi::ObjectReference`][], [`std::exception`][] |
|
|
22
22
|
| [`Napi::EscapableHandleScope`][] | |
|
|
23
|
-
| [`Napi::External`][] | [`Napi::
|
|
23
|
+
| [`Napi::External`][] | [`Napi::TypeTaggable`][] |
|
|
24
24
|
| [`Napi::Function`][] | [`Napi::Object`][] |
|
|
25
25
|
| [`Napi::FunctionReference`][] | [`Napi::Reference<Napi::Function>`][] |
|
|
26
26
|
| [`Napi::HandleScope`][] | |
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
| [`Napi::MemoryManagement`][] | |
|
|
29
29
|
| [`Napi::Name`][] | [`Napi::Value`][] |
|
|
30
30
|
| [`Napi::Number`][] | [`Napi::Value`][] |
|
|
31
|
-
| [`Napi::Object`][] | [`Napi::
|
|
31
|
+
| [`Napi::Object`][] | [`Napi::TypeTaggable`][] |
|
|
32
32
|
| [`Napi::ObjectReference`][] | [`Napi::Reference<Napi::Object>`][] |
|
|
33
33
|
| [`Napi::ObjectWrap`][] | [`Napi::InstanceWrap`][], [`Napi::Reference<Napi::Object>`][] |
|
|
34
34
|
| [`Napi::Promise`][] | [`Napi::Object`][] |
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
| [`Napi::String`][] | [`Napi::Name`][] |
|
|
39
39
|
| [`Napi::Symbol`][] | [`Napi::Name`][] |
|
|
40
40
|
| [`Napi::ThreadSafeFunction`][] | |
|
|
41
|
+
| [`Napi::TypeTaggable`][] | [`Napi::Value][] |
|
|
41
42
|
| [`Napi::TypeError`][] | [`Napi::Error`][] |
|
|
42
43
|
| [`Napi::TypedArray`][] | [`Napi::Object`][] |
|
|
43
44
|
| [`Napi::TypedArrayOf`][] | [`Napi::TypedArray`][] |
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
[`Napi::Symbol`]: ./symbol.md
|
|
84
85
|
[`Napi::ThreadSafeFunction`]: ./threadsafe_function.md
|
|
85
86
|
[`Napi::TypeError`]: ./type_error.md
|
|
87
|
+
[`Napi::TypeTaggable`]: ./type_taggable.md
|
|
86
88
|
[`Napi::TypedArray`]: ./typed_array.md
|
|
87
89
|
[`Napi::TypedArrayOf`]: ./typed_array_of.md
|
|
88
90
|
[`Napi::Uint8Array`]: ./typed_array_of.md
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Object
|
|
2
2
|
|
|
3
|
-
Class `Napi::Object` inherits from class [`Napi::
|
|
3
|
+
Class `Napi::Object` inherits from class [`Napi::TypeTaggable`][].
|
|
4
4
|
|
|
5
5
|
The `Napi::Object` class corresponds to a JavaScript object. It is extended by the following node-addon-api classes that you may use when working with more specific types:
|
|
6
6
|
|
|
@@ -241,33 +241,6 @@ from being added to it and marking all existing properties as non-configurable.
|
|
|
241
241
|
Values of present properties can still be changed as long as they are
|
|
242
242
|
writable.
|
|
243
243
|
|
|
244
|
-
### TypeTag()
|
|
245
|
-
|
|
246
|
-
```cpp
|
|
247
|
-
void Napi::Object::TypeTag(const napi_type_tag* type_tag) const;
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
- `[in] type_tag`: The tag with which this object is to be marked.
|
|
251
|
-
|
|
252
|
-
The `Napi::Object::TypeTag()` method associates the value of the `type_tag`
|
|
253
|
-
pointer with this JavaScript object. `Napi::Object::CheckTypeTag()` can then be
|
|
254
|
-
used to compare the tag that was attached to this object with one owned by the
|
|
255
|
-
addon to ensure that this object has the right type.
|
|
256
|
-
|
|
257
|
-
### CheckTypeTag()
|
|
258
|
-
|
|
259
|
-
```cpp
|
|
260
|
-
bool Napi::Object::CheckTypeTag(const napi_type_tag* type_tag) const;
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
- `[in] type_tag`: The tag with which to compare any tag found on this object.
|
|
264
|
-
|
|
265
|
-
The `Napi::Object::CheckTypeTag()` method compares the pointer given as
|
|
266
|
-
`type_tag` with any that can be found on this JavaScript object. If no tag is
|
|
267
|
-
found on this object or, if a tag is found but it does not match `type_tag`,
|
|
268
|
-
then the return value is `false`. If a tag is found and it matches `type_tag`,
|
|
269
|
-
then the return value is `true`.
|
|
270
|
-
|
|
271
244
|
### operator\[\]()
|
|
272
245
|
|
|
273
246
|
```cpp
|
|
@@ -434,5 +407,5 @@ void Increment(const CallbackInfo& info) {
|
|
|
434
407
|
}
|
|
435
408
|
```
|
|
436
409
|
|
|
437
|
-
[`Napi::
|
|
410
|
+
[`Napi::TypeTaggable`]: ./type_taggable.md
|
|
438
411
|
[`Napi::Value::From`]: ./value.md#from
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# TypeTaggable
|
|
2
|
+
|
|
3
|
+
Class `Napi::TypeTaggable` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
5
|
+
The `Napi::TypeTaggable` class is the base class for [`Napi::Object`][] and
|
|
6
|
+
[`Napi::External`][]. It adds type-tagging capabilities to both. It is an
|
|
7
|
+
abstract-only base class.
|
|
8
|
+
|
|
9
|
+
### TypeTag()
|
|
10
|
+
|
|
11
|
+
```cpp
|
|
12
|
+
void Napi::TypeTaggable::TypeTag(const napi_type_tag* type_tag) const;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- `[in] type_tag`: The tag with which this object or external is to be marked.
|
|
16
|
+
|
|
17
|
+
The `Napi::TypeTaggable::TypeTag()` method associates the value of the
|
|
18
|
+
`type_tag` pointer with this JavaScript object or external.
|
|
19
|
+
`Napi::TypeTaggable::CheckTypeTag()` can then be used to compare the tag that
|
|
20
|
+
was attached with one owned by the add-on to ensure that this object or external
|
|
21
|
+
has the right type.
|
|
22
|
+
|
|
23
|
+
### CheckTypeTag()
|
|
24
|
+
|
|
25
|
+
```cpp
|
|
26
|
+
bool Napi::TypeTaggable::CheckTypeTag(const napi_type_tag* type_tag) const;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `[in] type_tag`: The tag with which to compare any tag found on this object or
|
|
30
|
+
external.
|
|
31
|
+
|
|
32
|
+
The `Napi::TypeTaggable::CheckTypeTag()` method compares the pointer given as
|
|
33
|
+
`type_tag` with any that can be found on this JavaScript object or external. If
|
|
34
|
+
no tag is found or if a tag is found but it does not match `type_tag`, then the
|
|
35
|
+
return value is `false`. If a tag is found and it matches `type_tag`, then the
|
|
36
|
+
return value is `true`.
|
|
37
|
+
|
|
38
|
+
[`Napi::Value`]: ./value.md
|
|
39
|
+
[`Napi::Object`]: ./object.md
|
|
40
|
+
[`Napi::External`]: ./external.md
|
|
@@ -78,7 +78,13 @@ Casts to another type of `Napi::Value`, when the actual type is known or
|
|
|
78
78
|
assumed.
|
|
79
79
|
|
|
80
80
|
This conversion does not coerce the type. Calling any methods inappropriate for
|
|
81
|
-
the actual value type will throw `Napi::Error`.
|
|
81
|
+
the actual value type will throw `Napi::Error`. When C++ exceptions are
|
|
82
|
+
disabled, the thrown error will not be reflected before control returns to
|
|
83
|
+
JavaScript.
|
|
84
|
+
|
|
85
|
+
In order to enforce expected type, use `Napi::Value::Is*()` methods to check
|
|
86
|
+
the type before calling `Napi::Value::As()`, or compile with definition
|
|
87
|
+
`NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS` to enforce type checks.
|
|
82
88
|
|
|
83
89
|
### Env
|
|
84
90
|
|