@basemaps/lambda-tiler 6.38.0 → 6.39.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/CHANGELOG.md +22 -0
- package/build/routes/__tests__/tile.style.json.test.js +91 -43
- package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
- package/build/routes/tile.style.json.d.ts +2 -2
- package/build/routes/tile.style.json.d.ts.map +1 -1
- package/build/routes/tile.style.json.js +5 -3
- package/build/routes/tile.style.json.js.map +1 -1
- package/build/routes/tile.xyz.raster.js +4 -5
- package/build/routes/tile.xyz.raster.js.map +1 -1
- package/dist/index.js +35 -35
- package/dist/node_modules/.package-lock.json +7 -7
- package/dist/node_modules/node-abi/.circleci/config.yml +5 -23
- package/dist/node_modules/node-abi/CONTRIBUTING.md +1 -1
- package/dist/node_modules/node-abi/abi_registry.json +7 -0
- package/dist/node_modules/node-abi/package.json +2 -3
- package/dist/node_modules/node-addon-api/README.md +36 -12
- package/dist/node_modules/node-addon-api/index.js +3 -3
- package/dist/node_modules/node-addon-api/napi-inl.deprecated.h +121 -127
- package/dist/node_modules/node-addon-api/napi-inl.h +1166 -1122
- package/dist/node_modules/node-addon-api/napi.h +2786 -2675
- package/dist/node_modules/node-addon-api/package.json +42 -1
- package/dist/node_modules/node-addon-api/tools/check-napi.js +13 -14
- package/dist/node_modules/node-addon-api/tools/conversion.js +161 -169
- package/dist/node_modules/node-addon-api/tools/eslint-format.js +9 -1
- package/dist/package-lock.json +14 -14
- package/dist/package.json +1 -1
- package/package.json +4 -4
- package/src/routes/__tests__/tile.style.json.test.ts +100 -44
- package/src/routes/tile.style.json.ts +11 -4
- package/src/routes/tile.xyz.raster.ts +6 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -30,11 +30,11 @@ namespace details {
|
|
|
30
30
|
// TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
|
|
31
31
|
// available on all supported versions of Node.js.
|
|
32
32
|
template <typename FreeType>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
inline napi_status AttachData(napi_env env,
|
|
34
|
+
napi_value obj,
|
|
35
|
+
FreeType* data,
|
|
36
|
+
napi_finalize finalizer = nullptr,
|
|
37
|
+
void* hint = nullptr) {
|
|
38
38
|
napi_status status;
|
|
39
39
|
if (finalizer == nullptr) {
|
|
40
40
|
finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
|
|
@@ -45,22 +45,16 @@ static inline napi_status AttachData(napi_env env,
|
|
|
45
45
|
napi_value symbol, external;
|
|
46
46
|
status = napi_create_symbol(env, nullptr, &symbol);
|
|
47
47
|
if (status == napi_ok) {
|
|
48
|
-
status = napi_create_external(env,
|
|
49
|
-
data,
|
|
50
|
-
finalizer,
|
|
51
|
-
hint,
|
|
52
|
-
&external);
|
|
48
|
+
status = napi_create_external(env, data, finalizer, hint, &external);
|
|
53
49
|
if (status == napi_ok) {
|
|
54
|
-
napi_property_descriptor desc = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
nullptr
|
|
63
|
-
};
|
|
50
|
+
napi_property_descriptor desc = {nullptr,
|
|
51
|
+
symbol,
|
|
52
|
+
nullptr,
|
|
53
|
+
nullptr,
|
|
54
|
+
nullptr,
|
|
55
|
+
external,
|
|
56
|
+
napi_default,
|
|
57
|
+
nullptr};
|
|
64
58
|
status = napi_define_properties(env, obj, 1, &desc);
|
|
65
59
|
}
|
|
66
60
|
}
|
|
@@ -81,16 +75,16 @@ inline napi_value WrapCallback(Callable callback) {
|
|
|
81
75
|
e.ThrowAsJavaScriptException();
|
|
82
76
|
return nullptr;
|
|
83
77
|
}
|
|
84
|
-
#else
|
|
78
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
85
79
|
// When C++ exceptions are disabled, errors are immediately thrown as JS
|
|
86
80
|
// exceptions, so there is no need to catch and rethrow them here.
|
|
87
81
|
return callback();
|
|
88
|
-
#endif
|
|
82
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
89
83
|
}
|
|
90
84
|
|
|
91
85
|
// For use in JS to C++ void callback wrappers to catch any Napi::Error
|
|
92
|
-
// exceptions and rethrow them as JavaScript exceptions before returning from
|
|
93
|
-
// callback.
|
|
86
|
+
// exceptions and rethrow them as JavaScript exceptions before returning from
|
|
87
|
+
// the callback.
|
|
94
88
|
template <typename Callable>
|
|
95
89
|
inline void WrapVoidCallback(Callable callback) {
|
|
96
90
|
#ifdef NAPI_CPP_EXCEPTIONS
|
|
@@ -99,21 +93,20 @@ inline void WrapVoidCallback(Callable callback) {
|
|
|
99
93
|
} catch (const Error& e) {
|
|
100
94
|
e.ThrowAsJavaScriptException();
|
|
101
95
|
}
|
|
102
|
-
#else
|
|
96
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
103
97
|
// When C++ exceptions are disabled, errors are immediately thrown as JS
|
|
104
98
|
// exceptions, so there is no need to catch and rethrow them here.
|
|
105
99
|
callback();
|
|
106
|
-
#endif
|
|
100
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
107
101
|
}
|
|
108
102
|
|
|
109
103
|
template <typename Callable, typename Return>
|
|
110
104
|
struct CallbackData {
|
|
111
|
-
static inline
|
|
112
|
-
napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
105
|
+
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
113
106
|
return details::WrapCallback([&] {
|
|
114
107
|
CallbackInfo callbackInfo(env, info);
|
|
115
108
|
CallbackData* callbackData =
|
|
116
|
-
|
|
109
|
+
static_cast<CallbackData*>(callbackInfo.Data());
|
|
117
110
|
callbackInfo.SetData(callbackData->data);
|
|
118
111
|
return callbackData->callback(callbackInfo);
|
|
119
112
|
});
|
|
@@ -125,12 +118,11 @@ struct CallbackData {
|
|
|
125
118
|
|
|
126
119
|
template <typename Callable>
|
|
127
120
|
struct CallbackData<Callable, void> {
|
|
128
|
-
static inline
|
|
129
|
-
napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
121
|
+
static inline napi_value Wrapper(napi_env env, napi_callback_info info) {
|
|
130
122
|
return details::WrapCallback([&] {
|
|
131
123
|
CallbackInfo callbackInfo(env, info);
|
|
132
124
|
CallbackData* callbackData =
|
|
133
|
-
|
|
125
|
+
static_cast<CallbackData*>(callbackInfo.Data());
|
|
134
126
|
callbackInfo.SetData(callbackData->data);
|
|
135
127
|
callbackData->callback(callbackInfo);
|
|
136
128
|
return nullptr;
|
|
@@ -142,8 +134,8 @@ struct CallbackData<Callable, void> {
|
|
|
142
134
|
};
|
|
143
135
|
|
|
144
136
|
template <void (*Callback)(const CallbackInfo& info)>
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
napi_value TemplatedVoidCallback(napi_env env,
|
|
138
|
+
napi_callback_info info) NAPI_NOEXCEPT {
|
|
147
139
|
return details::WrapCallback([&] {
|
|
148
140
|
CallbackInfo cbInfo(env, info);
|
|
149
141
|
Callback(cbInfo);
|
|
@@ -152,8 +144,8 @@ TemplatedVoidCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
|
152
144
|
}
|
|
153
145
|
|
|
154
146
|
template <Napi::Value (*Callback)(const CallbackInfo& info)>
|
|
155
|
-
|
|
156
|
-
|
|
147
|
+
napi_value TemplatedCallback(napi_env env,
|
|
148
|
+
napi_callback_info info) NAPI_NOEXCEPT {
|
|
157
149
|
return details::WrapCallback([&] {
|
|
158
150
|
CallbackInfo cbInfo(env, info);
|
|
159
151
|
return Callback(cbInfo);
|
|
@@ -162,8 +154,8 @@ TemplatedCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
|
162
154
|
|
|
163
155
|
template <typename T,
|
|
164
156
|
Napi::Value (T::*UnwrapCallback)(const CallbackInfo& info)>
|
|
165
|
-
|
|
166
|
-
|
|
157
|
+
napi_value TemplatedInstanceCallback(napi_env env,
|
|
158
|
+
napi_callback_info info) NAPI_NOEXCEPT {
|
|
167
159
|
return details::WrapCallback([&] {
|
|
168
160
|
CallbackInfo cbInfo(env, info);
|
|
169
161
|
T* instance = T::Unwrap(cbInfo.This().As<Object>());
|
|
@@ -172,9 +164,8 @@ TemplatedInstanceCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
|
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
template <typename T, void (T::*UnwrapCallback)(const CallbackInfo& info)>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
napi_callback_info info) NAPI_NOEXCEPT {
|
|
167
|
+
napi_value TemplatedInstanceVoidCallback(napi_env env, napi_callback_info info)
|
|
168
|
+
NAPI_NOEXCEPT {
|
|
178
169
|
return details::WrapCallback([&] {
|
|
179
170
|
CallbackInfo cbInfo(env, info);
|
|
180
171
|
T* instance = T::Unwrap(cbInfo.This().As<Object>());
|
|
@@ -200,7 +191,8 @@ struct FinalizeData {
|
|
|
200
191
|
void* finalizeHint) NAPI_NOEXCEPT {
|
|
201
192
|
WrapVoidCallback([&] {
|
|
202
193
|
FinalizeData* finalizeData = static_cast<FinalizeData*>(finalizeHint);
|
|
203
|
-
finalizeData->callback(
|
|
194
|
+
finalizeData->callback(
|
|
195
|
+
Env(env), static_cast<T*>(data), finalizeData->hint);
|
|
204
196
|
delete finalizeData;
|
|
205
197
|
});
|
|
206
198
|
}
|
|
@@ -210,14 +202,14 @@ struct FinalizeData {
|
|
|
210
202
|
};
|
|
211
203
|
|
|
212
204
|
#if (NAPI_VERSION > 3 && !defined(__wasm32__))
|
|
213
|
-
template <typename ContextType=void,
|
|
214
|
-
typename Finalizer=std::function<void(Env, void*, ContextType*)>,
|
|
215
|
-
typename FinalizerDataType=void>
|
|
205
|
+
template <typename ContextType = void,
|
|
206
|
+
typename Finalizer = std::function<void(Env, void*, ContextType*)>,
|
|
207
|
+
typename FinalizerDataType = void>
|
|
216
208
|
struct ThreadSafeFinalize {
|
|
217
|
-
static inline
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
static inline void Wrapper(napi_env env,
|
|
210
|
+
void* rawFinalizeData,
|
|
211
|
+
void* /* rawContext */) {
|
|
212
|
+
if (rawFinalizeData == nullptr) return;
|
|
221
213
|
|
|
222
214
|
ThreadSafeFinalize* finalizeData =
|
|
223
215
|
static_cast<ThreadSafeFinalize*>(rawFinalizeData);
|
|
@@ -225,12 +217,10 @@ struct ThreadSafeFinalize {
|
|
|
225
217
|
delete finalizeData;
|
|
226
218
|
}
|
|
227
219
|
|
|
228
|
-
static inline
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (rawFinalizeData == nullptr)
|
|
233
|
-
return;
|
|
220
|
+
static inline void FinalizeWrapperWithData(napi_env env,
|
|
221
|
+
void* rawFinalizeData,
|
|
222
|
+
void* /* rawContext */) {
|
|
223
|
+
if (rawFinalizeData == nullptr) return;
|
|
234
224
|
|
|
235
225
|
ThreadSafeFinalize* finalizeData =
|
|
236
226
|
static_cast<ThreadSafeFinalize*>(rawFinalizeData);
|
|
@@ -238,12 +228,10 @@ struct ThreadSafeFinalize {
|
|
|
238
228
|
delete finalizeData;
|
|
239
229
|
}
|
|
240
230
|
|
|
241
|
-
static inline
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (rawFinalizeData == nullptr)
|
|
246
|
-
return;
|
|
231
|
+
static inline void FinalizeWrapperWithContext(napi_env env,
|
|
232
|
+
void* rawFinalizeData,
|
|
233
|
+
void* rawContext) {
|
|
234
|
+
if (rawFinalizeData == nullptr) return;
|
|
247
235
|
|
|
248
236
|
ThreadSafeFinalize* finalizeData =
|
|
249
237
|
static_cast<ThreadSafeFinalize*>(rawFinalizeData);
|
|
@@ -251,17 +239,14 @@ struct ThreadSafeFinalize {
|
|
|
251
239
|
delete finalizeData;
|
|
252
240
|
}
|
|
253
241
|
|
|
254
|
-
static inline
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
void* rawContext) {
|
|
258
|
-
if (rawFinalizeData == nullptr)
|
|
259
|
-
return;
|
|
242
|
+
static inline void FinalizeFinalizeWrapperWithDataAndContext(
|
|
243
|
+
napi_env env, void* rawFinalizeData, void* rawContext) {
|
|
244
|
+
if (rawFinalizeData == nullptr) return;
|
|
260
245
|
|
|
261
246
|
ThreadSafeFinalize* finalizeData =
|
|
262
247
|
static_cast<ThreadSafeFinalize*>(rawFinalizeData);
|
|
263
|
-
finalizeData->callback(
|
|
264
|
-
static_cast<ContextType*>(rawContext));
|
|
248
|
+
finalizeData->callback(
|
|
249
|
+
Env(env), finalizeData->data, static_cast<ContextType*>(rawContext));
|
|
265
250
|
delete finalizeData;
|
|
266
251
|
}
|
|
267
252
|
|
|
@@ -270,8 +255,8 @@ struct ThreadSafeFinalize {
|
|
|
270
255
|
};
|
|
271
256
|
|
|
272
257
|
template <typename ContextType, typename DataType, typename CallJs, CallJs call>
|
|
273
|
-
typename std::enable_if<call != nullptr>::type
|
|
274
|
-
|
|
258
|
+
inline typename std::enable_if<call != static_cast<CallJs>(nullptr)>::type
|
|
259
|
+
CallJsWrapper(napi_env env, napi_value jsCallback, void* context, void* data) {
|
|
275
260
|
call(env,
|
|
276
261
|
Function(env, jsCallback),
|
|
277
262
|
static_cast<ContextType*>(context),
|
|
@@ -279,8 +264,11 @@ typename std::enable_if<call != nullptr>::type static inline CallJsWrapper(
|
|
|
279
264
|
}
|
|
280
265
|
|
|
281
266
|
template <typename ContextType, typename DataType, typename CallJs, CallJs call>
|
|
282
|
-
typename std::enable_if<call == nullptr>::type
|
|
283
|
-
|
|
267
|
+
inline typename std::enable_if<call == static_cast<CallJs>(nullptr)>::type
|
|
268
|
+
CallJsWrapper(napi_env env,
|
|
269
|
+
napi_value jsCallback,
|
|
270
|
+
void* /*context*/,
|
|
271
|
+
void* /*data*/) {
|
|
284
272
|
if (jsCallback != nullptr) {
|
|
285
273
|
Function(env, jsCallback).Call(0, nullptr);
|
|
286
274
|
}
|
|
@@ -311,23 +299,23 @@ napi_value DefaultCallbackWrapper(napi_env env, Napi::Function cb) {
|
|
|
311
299
|
|
|
312
300
|
template <typename Getter, typename Setter>
|
|
313
301
|
struct AccessorCallbackData {
|
|
314
|
-
static inline
|
|
315
|
-
|
|
302
|
+
static inline napi_value GetterWrapper(napi_env env,
|
|
303
|
+
napi_callback_info info) {
|
|
316
304
|
return details::WrapCallback([&] {
|
|
317
305
|
CallbackInfo callbackInfo(env, info);
|
|
318
306
|
AccessorCallbackData* callbackData =
|
|
319
|
-
|
|
307
|
+
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
320
308
|
callbackInfo.SetData(callbackData->data);
|
|
321
309
|
return callbackData->getterCallback(callbackInfo);
|
|
322
310
|
});
|
|
323
311
|
}
|
|
324
312
|
|
|
325
|
-
static inline
|
|
326
|
-
|
|
313
|
+
static inline napi_value SetterWrapper(napi_env env,
|
|
314
|
+
napi_callback_info info) {
|
|
327
315
|
return details::WrapCallback([&] {
|
|
328
316
|
CallbackInfo callbackInfo(env, info);
|
|
329
317
|
AccessorCallbackData* callbackData =
|
|
330
|
-
|
|
318
|
+
static_cast<AccessorCallbackData*>(callbackInfo.Data());
|
|
331
319
|
callbackInfo.SetData(callbackData->data);
|
|
332
320
|
callbackData->setterCallback(callbackInfo);
|
|
333
321
|
return nullptr;
|
|
@@ -342,8 +330,8 @@ struct AccessorCallbackData {
|
|
|
342
330
|
} // namespace details
|
|
343
331
|
|
|
344
332
|
#ifndef NODE_ADDON_API_DISABLE_DEPRECATED
|
|
345
|
-
#
|
|
346
|
-
#endif
|
|
333
|
+
#include "napi-inl.deprecated.h"
|
|
334
|
+
#endif // !NODE_ADDON_API_DISABLE_DEPRECATED
|
|
347
335
|
|
|
348
336
|
////////////////////////////////////////////////////////////////////////////////
|
|
349
337
|
// Module registration
|
|
@@ -358,16 +346,15 @@ struct AccessorCallbackData {
|
|
|
358
346
|
|
|
359
347
|
// Register an add-on based on a subclass of `Addon<T>` with a custom Node.js
|
|
360
348
|
// module name.
|
|
361
|
-
#define NODE_API_NAMED_ADDON(modname, classname)
|
|
362
|
-
static napi_value __napi_
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
NAPI_MODULE(modname, __napi_ ## classname)
|
|
349
|
+
#define NODE_API_NAMED_ADDON(modname, classname) \
|
|
350
|
+
static napi_value __napi_##classname(napi_env env, napi_value exports) { \
|
|
351
|
+
return Napi::RegisterModule(env, exports, &classname::Init); \
|
|
352
|
+
} \
|
|
353
|
+
NAPI_MODULE(modname, __napi_##classname)
|
|
367
354
|
|
|
368
355
|
// Register an add-on based on a subclass of `Addon<T>` with the Node.js module
|
|
369
356
|
// name given by node-gyp from the `target_name` in binding.gyp.
|
|
370
|
-
#define NODE_API_ADDON(classname)
|
|
357
|
+
#define NODE_API_ADDON(classname) \
|
|
371
358
|
NODE_API_NAMED_ADDON(NODE_GYP_MODULE_NAME, classname)
|
|
372
359
|
|
|
373
360
|
// Adapt the NAPI_MODULE registration function:
|
|
@@ -377,8 +364,8 @@ inline napi_value RegisterModule(napi_env env,
|
|
|
377
364
|
napi_value exports,
|
|
378
365
|
ModuleRegisterCallback registerCallback) {
|
|
379
366
|
return details::WrapCallback([&] {
|
|
380
|
-
return napi_value(
|
|
381
|
-
|
|
367
|
+
return napi_value(
|
|
368
|
+
registerCallback(Napi::Env(env), Napi::Object(env, exports)));
|
|
382
369
|
});
|
|
383
370
|
}
|
|
384
371
|
|
|
@@ -452,8 +439,7 @@ inline Maybe<T> Just(const T& t) {
|
|
|
452
439
|
// Env class
|
|
453
440
|
////////////////////////////////////////////////////////////////////////////////
|
|
454
441
|
|
|
455
|
-
inline Env::Env(napi_env env) : _env(env) {
|
|
456
|
-
}
|
|
442
|
+
inline Env::Env(napi_env env) : _env(env) {}
|
|
457
443
|
|
|
458
444
|
inline Env::operator napi_env() const {
|
|
459
445
|
return _env;
|
|
@@ -483,7 +469,8 @@ inline Value Env::Null() const {
|
|
|
483
469
|
inline bool Env::IsExceptionPending() const {
|
|
484
470
|
bool result;
|
|
485
471
|
napi_status status = napi_is_exception_pending(_env, &result);
|
|
486
|
-
if (status != napi_ok)
|
|
472
|
+
if (status != napi_ok)
|
|
473
|
+
result = false; // Checking for a pending exception shouldn't throw.
|
|
487
474
|
return result;
|
|
488
475
|
}
|
|
489
476
|
|
|
@@ -536,10 +523,11 @@ void Env::CleanupHook<Hook, Arg>::WrapperWithArg(void* data) NAPI_NOEXCEPT {
|
|
|
536
523
|
#if NAPI_VERSION > 5
|
|
537
524
|
template <typename T, Env::Finalizer<T> fini>
|
|
538
525
|
inline void Env::SetInstanceData(T* data) const {
|
|
539
|
-
napi_status status =
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
526
|
+
napi_status status = napi_set_instance_data(
|
|
527
|
+
_env,
|
|
528
|
+
data,
|
|
529
|
+
[](napi_env env, void* data, void*) { fini(env, static_cast<T*>(data)); },
|
|
530
|
+
nullptr);
|
|
543
531
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
544
532
|
}
|
|
545
533
|
|
|
@@ -547,11 +535,13 @@ template <typename DataType,
|
|
|
547
535
|
typename HintType,
|
|
548
536
|
Napi::Env::FinalizerWithHint<DataType, HintType> fini>
|
|
549
537
|
inline void Env::SetInstanceData(DataType* data, HintType* hint) const {
|
|
550
|
-
napi_status status =
|
|
551
|
-
|
|
538
|
+
napi_status status = napi_set_instance_data(
|
|
539
|
+
_env,
|
|
540
|
+
data,
|
|
552
541
|
[](napi_env env, void* data, void* hint) {
|
|
553
542
|
fini(env, static_cast<DataType*>(data), static_cast<HintType*>(hint));
|
|
554
|
-
},
|
|
543
|
+
},
|
|
544
|
+
hint);
|
|
555
545
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
556
546
|
}
|
|
557
547
|
|
|
@@ -565,7 +555,8 @@ inline T* Env::GetInstanceData() const {
|
|
|
565
555
|
return static_cast<T*>(data);
|
|
566
556
|
}
|
|
567
557
|
|
|
568
|
-
template <typename T>
|
|
558
|
+
template <typename T>
|
|
559
|
+
void Env::DefaultFini(Env, T* data) {
|
|
569
560
|
delete data;
|
|
570
561
|
}
|
|
571
562
|
|
|
@@ -579,22 +570,21 @@ void Env::DefaultFiniWithHint(Env, DataType* data, HintType*) {
|
|
|
579
570
|
// Value class
|
|
580
571
|
////////////////////////////////////////////////////////////////////////////////
|
|
581
572
|
|
|
582
|
-
inline Value::Value() : _env(nullptr), _value(nullptr) {
|
|
583
|
-
}
|
|
573
|
+
inline Value::Value() : _env(nullptr), _value(nullptr) {}
|
|
584
574
|
|
|
585
|
-
inline Value::Value(napi_env env, napi_value value)
|
|
586
|
-
}
|
|
575
|
+
inline Value::Value(napi_env env, napi_value value)
|
|
576
|
+
: _env(env), _value(value) {}
|
|
587
577
|
|
|
588
578
|
inline Value::operator napi_value() const {
|
|
589
579
|
return _value;
|
|
590
580
|
}
|
|
591
581
|
|
|
592
|
-
inline bool Value::operator
|
|
582
|
+
inline bool Value::operator==(const Value& other) const {
|
|
593
583
|
return StrictEquals(other);
|
|
594
584
|
}
|
|
595
585
|
|
|
596
|
-
inline bool Value::operator
|
|
597
|
-
return !this->operator
|
|
586
|
+
inline bool Value::operator!=(const Value& other) const {
|
|
587
|
+
return !this->operator==(other);
|
|
598
588
|
}
|
|
599
589
|
|
|
600
590
|
inline bool Value::StrictEquals(const Value& other) const {
|
|
@@ -788,11 +778,10 @@ inline Boolean Boolean::New(napi_env env, bool val) {
|
|
|
788
778
|
return Boolean(env, value);
|
|
789
779
|
}
|
|
790
780
|
|
|
791
|
-
inline Boolean::Boolean() : Napi::Value() {
|
|
792
|
-
}
|
|
781
|
+
inline Boolean::Boolean() : Napi::Value() {}
|
|
793
782
|
|
|
794
|
-
inline Boolean::Boolean(napi_env env, napi_value value)
|
|
795
|
-
}
|
|
783
|
+
inline Boolean::Boolean(napi_env env, napi_value value)
|
|
784
|
+
: Napi::Value(env, value) {}
|
|
796
785
|
|
|
797
786
|
inline Boolean::operator bool() const {
|
|
798
787
|
return Value();
|
|
@@ -816,11 +805,9 @@ inline Number Number::New(napi_env env, double val) {
|
|
|
816
805
|
return Number(env, value);
|
|
817
806
|
}
|
|
818
807
|
|
|
819
|
-
inline Number::Number() : Value() {
|
|
820
|
-
}
|
|
808
|
+
inline Number::Number() : Value() {}
|
|
821
809
|
|
|
822
|
-
inline Number::Number(napi_env env, napi_value value) : Value(env, value) {
|
|
823
|
-
}
|
|
810
|
+
inline Number::Number(napi_env env, napi_value value) : Value(env, value) {}
|
|
824
811
|
|
|
825
812
|
inline Number::operator int32_t() const {
|
|
826
813
|
return Int32Value();
|
|
@@ -893,46 +880,50 @@ inline BigInt BigInt::New(napi_env env, uint64_t val) {
|
|
|
893
880
|
return BigInt(env, value);
|
|
894
881
|
}
|
|
895
882
|
|
|
896
|
-
inline BigInt BigInt::New(napi_env env,
|
|
883
|
+
inline BigInt BigInt::New(napi_env env,
|
|
884
|
+
int sign_bit,
|
|
885
|
+
size_t word_count,
|
|
886
|
+
const uint64_t* words) {
|
|
897
887
|
napi_value value;
|
|
898
|
-
napi_status status =
|
|
888
|
+
napi_status status =
|
|
889
|
+
napi_create_bigint_words(env, sign_bit, word_count, words, &value);
|
|
899
890
|
NAPI_THROW_IF_FAILED(env, status, BigInt());
|
|
900
891
|
return BigInt(env, value);
|
|
901
892
|
}
|
|
902
893
|
|
|
903
|
-
inline BigInt::BigInt() : Value() {
|
|
904
|
-
}
|
|
894
|
+
inline BigInt::BigInt() : Value() {}
|
|
905
895
|
|
|
906
|
-
inline BigInt::BigInt(napi_env env, napi_value value) : Value(env, value) {
|
|
907
|
-
}
|
|
896
|
+
inline BigInt::BigInt(napi_env env, napi_value value) : Value(env, value) {}
|
|
908
897
|
|
|
909
898
|
inline int64_t BigInt::Int64Value(bool* lossless) const {
|
|
910
899
|
int64_t result;
|
|
911
|
-
napi_status status =
|
|
912
|
-
_env, _value, &result, lossless);
|
|
900
|
+
napi_status status =
|
|
901
|
+
napi_get_value_bigint_int64(_env, _value, &result, lossless);
|
|
913
902
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
914
903
|
return result;
|
|
915
904
|
}
|
|
916
905
|
|
|
917
906
|
inline uint64_t BigInt::Uint64Value(bool* lossless) const {
|
|
918
907
|
uint64_t result;
|
|
919
|
-
napi_status status =
|
|
920
|
-
_env, _value, &result, lossless);
|
|
908
|
+
napi_status status =
|
|
909
|
+
napi_get_value_bigint_uint64(_env, _value, &result, lossless);
|
|
921
910
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
922
911
|
return result;
|
|
923
912
|
}
|
|
924
913
|
|
|
925
914
|
inline size_t BigInt::WordCount() const {
|
|
926
915
|
size_t word_count;
|
|
927
|
-
napi_status status =
|
|
928
|
-
_env, _value, nullptr, &word_count, nullptr);
|
|
916
|
+
napi_status status =
|
|
917
|
+
napi_get_value_bigint_words(_env, _value, nullptr, &word_count, nullptr);
|
|
929
918
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
930
919
|
return word_count;
|
|
931
920
|
}
|
|
932
921
|
|
|
933
|
-
inline void BigInt::ToWords(int* sign_bit,
|
|
934
|
-
|
|
935
|
-
|
|
922
|
+
inline void BigInt::ToWords(int* sign_bit,
|
|
923
|
+
size_t* word_count,
|
|
924
|
+
uint64_t* words) {
|
|
925
|
+
napi_status status =
|
|
926
|
+
napi_get_value_bigint_words(_env, _value, sign_bit, word_count, words);
|
|
936
927
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
937
928
|
}
|
|
938
929
|
#endif // NAPI_VERSION > 5
|
|
@@ -949,11 +940,9 @@ inline Date Date::New(napi_env env, double val) {
|
|
|
949
940
|
return Date(env, value);
|
|
950
941
|
}
|
|
951
942
|
|
|
952
|
-
inline Date::Date() : Value() {
|
|
953
|
-
}
|
|
943
|
+
inline Date::Date() : Value() {}
|
|
954
944
|
|
|
955
|
-
inline Date::Date(napi_env env, napi_value value) : Value(env, value) {
|
|
956
|
-
}
|
|
945
|
+
inline Date::Date(napi_env env, napi_value value) : Value(env, value) {}
|
|
957
946
|
|
|
958
947
|
inline Date::operator double() const {
|
|
959
948
|
return ValueOf();
|
|
@@ -961,8 +950,7 @@ inline Date::operator double() const {
|
|
|
961
950
|
|
|
962
951
|
inline double Date::ValueOf() const {
|
|
963
952
|
double result;
|
|
964
|
-
napi_status status = napi_get_date_value(
|
|
965
|
-
_env, _value, &result);
|
|
953
|
+
napi_status status = napi_get_date_value(_env, _value, &result);
|
|
966
954
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
967
955
|
return result;
|
|
968
956
|
}
|
|
@@ -972,11 +960,9 @@ inline double Date::ValueOf() const {
|
|
|
972
960
|
// Name class
|
|
973
961
|
////////////////////////////////////////////////////////////////////////////////
|
|
974
962
|
|
|
975
|
-
inline Name::Name() : Value() {
|
|
976
|
-
}
|
|
963
|
+
inline Name::Name() : Value() {}
|
|
977
964
|
|
|
978
|
-
inline Name::Name(napi_env env, napi_value value) : Value(env, value) {
|
|
979
|
-
}
|
|
965
|
+
inline Name::Name(napi_env env, napi_value value) : Value(env, value) {}
|
|
980
966
|
|
|
981
967
|
////////////////////////////////////////////////////////////////////////////////
|
|
982
968
|
// String class
|
|
@@ -998,7 +984,8 @@ inline String String::New(napi_env env, const char* val) {
|
|
|
998
984
|
NAPI_THROW_IF_FAILED(env, napi_invalid_arg, String());
|
|
999
985
|
}
|
|
1000
986
|
napi_value value;
|
|
1001
|
-
napi_status status =
|
|
987
|
+
napi_status status =
|
|
988
|
+
napi_create_string_utf8(env, val, std::strlen(val), &value);
|
|
1002
989
|
NAPI_THROW_IF_FAILED(env, status, String());
|
|
1003
990
|
return String(env, value);
|
|
1004
991
|
}
|
|
@@ -1011,7 +998,8 @@ inline String String::New(napi_env env, const char16_t* val) {
|
|
|
1011
998
|
// Throw an error that looks like it came from core.
|
|
1012
999
|
NAPI_THROW_IF_FAILED(env, napi_invalid_arg, String());
|
|
1013
1000
|
}
|
|
1014
|
-
napi_status status =
|
|
1001
|
+
napi_status status =
|
|
1002
|
+
napi_create_string_utf16(env, val, std::u16string(val).size(), &value);
|
|
1015
1003
|
NAPI_THROW_IF_FAILED(env, status, String());
|
|
1016
1004
|
return String(env, value);
|
|
1017
1005
|
}
|
|
@@ -1030,11 +1018,9 @@ inline String String::New(napi_env env, const char16_t* val, size_t length) {
|
|
|
1030
1018
|
return String(env, value);
|
|
1031
1019
|
}
|
|
1032
1020
|
|
|
1033
|
-
inline String::String() : Name() {
|
|
1034
|
-
}
|
|
1021
|
+
inline String::String() : Name() {}
|
|
1035
1022
|
|
|
1036
|
-
inline String::String(napi_env env, napi_value value) : Name(env, value) {
|
|
1037
|
-
}
|
|
1023
|
+
inline String::String(napi_env env, napi_value value) : Name(env, value) {}
|
|
1038
1024
|
|
|
1039
1025
|
inline String::operator std::string() const {
|
|
1040
1026
|
return Utf8Value();
|
|
@@ -1046,26 +1032,30 @@ inline String::operator std::u16string() const {
|
|
|
1046
1032
|
|
|
1047
1033
|
inline std::string String::Utf8Value() const {
|
|
1048
1034
|
size_t length;
|
|
1049
|
-
napi_status status =
|
|
1035
|
+
napi_status status =
|
|
1036
|
+
napi_get_value_string_utf8(_env, _value, nullptr, 0, &length);
|
|
1050
1037
|
NAPI_THROW_IF_FAILED(_env, status, "");
|
|
1051
1038
|
|
|
1052
1039
|
std::string value;
|
|
1053
1040
|
value.reserve(length + 1);
|
|
1054
1041
|
value.resize(length);
|
|
1055
|
-
status = napi_get_value_string_utf8(
|
|
1042
|
+
status = napi_get_value_string_utf8(
|
|
1043
|
+
_env, _value, &value[0], value.capacity(), nullptr);
|
|
1056
1044
|
NAPI_THROW_IF_FAILED(_env, status, "");
|
|
1057
1045
|
return value;
|
|
1058
1046
|
}
|
|
1059
1047
|
|
|
1060
1048
|
inline std::u16string String::Utf16Value() const {
|
|
1061
1049
|
size_t length;
|
|
1062
|
-
napi_status status =
|
|
1050
|
+
napi_status status =
|
|
1051
|
+
napi_get_value_string_utf16(_env, _value, nullptr, 0, &length);
|
|
1063
1052
|
NAPI_THROW_IF_FAILED(_env, status, NAPI_WIDE_TEXT(""));
|
|
1064
1053
|
|
|
1065
1054
|
std::u16string value;
|
|
1066
1055
|
value.reserve(length + 1);
|
|
1067
1056
|
value.resize(length);
|
|
1068
|
-
status = napi_get_value_string_utf16(
|
|
1057
|
+
status = napi_get_value_string_utf16(
|
|
1058
|
+
_env, _value, &value[0], value.capacity(), nullptr);
|
|
1069
1059
|
NAPI_THROW_IF_FAILED(_env, status, NAPI_WIDE_TEXT(""));
|
|
1070
1060
|
return value;
|
|
1071
1061
|
}
|
|
@@ -1075,8 +1065,9 @@ inline std::u16string String::Utf16Value() const {
|
|
|
1075
1065
|
////////////////////////////////////////////////////////////////////////////////
|
|
1076
1066
|
|
|
1077
1067
|
inline Symbol Symbol::New(napi_env env, const char* description) {
|
|
1078
|
-
napi_value descriptionValue = description != nullptr
|
|
1079
|
-
|
|
1068
|
+
napi_value descriptionValue = description != nullptr
|
|
1069
|
+
? String::New(env, description)
|
|
1070
|
+
: static_cast<napi_value>(nullptr);
|
|
1080
1071
|
return Symbol::New(env, descriptionValue);
|
|
1081
1072
|
}
|
|
1082
1073
|
|
|
@@ -1108,7 +1099,12 @@ inline MaybeOrValue<Symbol> Symbol::WellKnown(napi_env env,
|
|
|
1108
1099
|
}
|
|
1109
1100
|
return Nothing<Symbol>();
|
|
1110
1101
|
#else
|
|
1111
|
-
return Napi::Env(env)
|
|
1102
|
+
return Napi::Env(env)
|
|
1103
|
+
.Global()
|
|
1104
|
+
.Get("Symbol")
|
|
1105
|
+
.As<Object>()
|
|
1106
|
+
.Get(name)
|
|
1107
|
+
.As<Symbol>();
|
|
1112
1108
|
#endif
|
|
1113
1109
|
}
|
|
1114
1110
|
|
|
@@ -1149,11 +1145,9 @@ inline MaybeOrValue<Symbol> Symbol::For(napi_env env, napi_value description) {
|
|
|
1149
1145
|
#endif
|
|
1150
1146
|
}
|
|
1151
1147
|
|
|
1152
|
-
inline Symbol::Symbol() : Name() {
|
|
1153
|
-
}
|
|
1148
|
+
inline Symbol::Symbol() : Name() {}
|
|
1154
1149
|
|
|
1155
|
-
inline Symbol::Symbol(napi_env env, napi_value value) : Name(env, value) {
|
|
1156
|
-
}
|
|
1150
|
+
inline Symbol::Symbol(napi_env env, napi_value value) : Name(env, value) {}
|
|
1157
1151
|
|
|
1158
1152
|
////////////////////////////////////////////////////////////////////////////////
|
|
1159
1153
|
// Automagic value creation
|
|
@@ -1167,7 +1161,7 @@ struct vf_number {
|
|
|
1167
1161
|
}
|
|
1168
1162
|
};
|
|
1169
1163
|
|
|
1170
|
-
template<>
|
|
1164
|
+
template <>
|
|
1171
1165
|
struct vf_number<bool> {
|
|
1172
1166
|
static Boolean From(napi_env env, bool value) {
|
|
1173
1167
|
return Boolean::New(env, value);
|
|
@@ -1199,36 +1193,33 @@ struct vf_utf16_string {
|
|
|
1199
1193
|
|
|
1200
1194
|
template <typename T>
|
|
1201
1195
|
struct vf_fallback {
|
|
1202
|
-
static Value From(napi_env env, const T& value) {
|
|
1203
|
-
return Value(env, value);
|
|
1204
|
-
}
|
|
1196
|
+
static Value From(napi_env env, const T& value) { return Value(env, value); }
|
|
1205
1197
|
};
|
|
1206
1198
|
|
|
1207
|
-
template <typename...>
|
|
1208
|
-
|
|
1199
|
+
template <typename...>
|
|
1200
|
+
struct disjunction : std::false_type {};
|
|
1201
|
+
template <typename B>
|
|
1202
|
+
struct disjunction<B> : B {};
|
|
1209
1203
|
template <typename B, typename... Bs>
|
|
1210
1204
|
struct disjunction<B, Bs...>
|
|
1211
1205
|
: std::conditional<bool(B::value), B, disjunction<Bs...>>::type {};
|
|
1212
1206
|
|
|
1213
1207
|
template <typename T>
|
|
1214
1208
|
struct can_make_string
|
|
1215
|
-
: disjunction<typename std::is_convertible<T, const char
|
|
1216
|
-
typename std::is_convertible<T, const char16_t
|
|
1209
|
+
: disjunction<typename std::is_convertible<T, const char*>::type,
|
|
1210
|
+
typename std::is_convertible<T, const char16_t*>::type,
|
|
1217
1211
|
typename std::is_convertible<T, std::string>::type,
|
|
1218
1212
|
typename std::is_convertible<T, std::u16string>::type> {};
|
|
1219
|
-
}
|
|
1213
|
+
} // namespace details
|
|
1220
1214
|
|
|
1221
1215
|
template <typename T>
|
|
1222
1216
|
Value Value::From(napi_env env, const T& value) {
|
|
1223
1217
|
using Helper = typename std::conditional<
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
details::vf_fallback<T>
|
|
1230
|
-
>::type
|
|
1231
|
-
>::type;
|
|
1218
|
+
std::is_integral<T>::value || std::is_floating_point<T>::value,
|
|
1219
|
+
details::vf_number<T>,
|
|
1220
|
+
typename std::conditional<details::can_make_string<T>::value,
|
|
1221
|
+
String,
|
|
1222
|
+
details::vf_fallback<T>>::type>::type;
|
|
1232
1223
|
return Helper::From(env, value);
|
|
1233
1224
|
}
|
|
1234
1225
|
|
|
@@ -1236,22 +1227,18 @@ template <typename T>
|
|
|
1236
1227
|
String String::From(napi_env env, const T& value) {
|
|
1237
1228
|
struct Dummy {};
|
|
1238
1229
|
using Helper = typename std::conditional<
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
typename std::conditional<
|
|
1242
|
-
std::is_convertible<T, const char16_t*>::value,
|
|
1243
|
-
details::vf_utf16_charp,
|
|
1230
|
+
std::is_convertible<T, const char*>::value,
|
|
1231
|
+
details::vf_utf8_charp,
|
|
1244
1232
|
typename std::conditional<
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
>::type;
|
|
1233
|
+
std::is_convertible<T, const char16_t*>::value,
|
|
1234
|
+
details::vf_utf16_charp,
|
|
1235
|
+
typename std::conditional<
|
|
1236
|
+
std::is_convertible<T, std::string>::value,
|
|
1237
|
+
details::vf_utf8_string,
|
|
1238
|
+
typename std::conditional<
|
|
1239
|
+
std::is_convertible<T, std::u16string>::value,
|
|
1240
|
+
details::vf_utf16_string,
|
|
1241
|
+
Dummy>::type>::type>::type>::type;
|
|
1255
1242
|
return Helper::From(env, value);
|
|
1256
1243
|
}
|
|
1257
1244
|
|
|
@@ -1269,8 +1256,10 @@ inline Object::PropertyLValue<Key>::operator Value() const {
|
|
|
1269
1256
|
#endif
|
|
1270
1257
|
}
|
|
1271
1258
|
|
|
1272
|
-
template <typename Key>
|
|
1273
|
-
|
|
1259
|
+
template <typename Key>
|
|
1260
|
+
template <typename ValueType>
|
|
1261
|
+
inline Object::PropertyLValue<Key>& Object::PropertyLValue<Key>::operator=(
|
|
1262
|
+
ValueType value) {
|
|
1274
1263
|
#ifdef NODE_ADDON_API_ENABLE_MAYBE
|
|
1275
1264
|
MaybeOrValue<bool> result =
|
|
1276
1265
|
#endif
|
|
@@ -1283,7 +1272,7 @@ inline Object::PropertyLValue<Key>& Object::PropertyLValue<Key>::operator =(Valu
|
|
|
1283
1272
|
|
|
1284
1273
|
template <typename Key>
|
|
1285
1274
|
inline Object::PropertyLValue<Key>::PropertyLValue(Object object, Key key)
|
|
1286
|
-
|
|
1275
|
+
: _env(object.Env()), _object(object), _key(key) {}
|
|
1287
1276
|
|
|
1288
1277
|
inline Object Object::New(napi_env env) {
|
|
1289
1278
|
napi_value value;
|
|
@@ -1292,11 +1281,9 @@ inline Object Object::New(napi_env env) {
|
|
|
1292
1281
|
return Object(env, value);
|
|
1293
1282
|
}
|
|
1294
1283
|
|
|
1295
|
-
inline Object::Object() : Value() {
|
|
1296
|
-
}
|
|
1284
|
+
inline Object::Object() : Value() {}
|
|
1297
1285
|
|
|
1298
|
-
inline Object::Object(napi_env env, napi_value value) : Value(env, value) {
|
|
1299
|
-
}
|
|
1286
|
+
inline Object::Object(napi_env env, napi_value value) : Value(env, value) {}
|
|
1300
1287
|
|
|
1301
1288
|
inline Object::PropertyLValue<std::string> Object::operator[](
|
|
1302
1289
|
const char* utf8name) {
|
|
@@ -1365,7 +1352,8 @@ inline MaybeOrValue<bool> Object::HasOwnProperty(Value key) const {
|
|
|
1365
1352
|
|
|
1366
1353
|
inline MaybeOrValue<bool> Object::HasOwnProperty(const char* utf8name) const {
|
|
1367
1354
|
napi_value key;
|
|
1368
|
-
napi_status status =
|
|
1355
|
+
napi_status status =
|
|
1356
|
+
napi_create_string_utf8(_env, utf8name, std::strlen(utf8name), &key);
|
|
1369
1357
|
NAPI_MAYBE_THROW_IF_FAILED(_env, status, bool);
|
|
1370
1358
|
return HasOwnProperty(key);
|
|
1371
1359
|
}
|
|
@@ -1480,22 +1468,31 @@ inline MaybeOrValue<Array> Object::GetPropertyNames() const {
|
|
|
1480
1468
|
|
|
1481
1469
|
inline MaybeOrValue<bool> Object::DefineProperty(
|
|
1482
1470
|
const PropertyDescriptor& property) const {
|
|
1483
|
-
napi_status status = napi_define_properties(
|
|
1484
|
-
|
|
1471
|
+
napi_status status = napi_define_properties(
|
|
1472
|
+
_env,
|
|
1473
|
+
_value,
|
|
1474
|
+
1,
|
|
1475
|
+
reinterpret_cast<const napi_property_descriptor*>(&property));
|
|
1485
1476
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1486
1477
|
}
|
|
1487
1478
|
|
|
1488
1479
|
inline MaybeOrValue<bool> Object::DefineProperties(
|
|
1489
1480
|
const std::initializer_list<PropertyDescriptor>& properties) const {
|
|
1490
|
-
napi_status status = napi_define_properties(
|
|
1491
|
-
|
|
1481
|
+
napi_status status = napi_define_properties(
|
|
1482
|
+
_env,
|
|
1483
|
+
_value,
|
|
1484
|
+
properties.size(),
|
|
1485
|
+
reinterpret_cast<const napi_property_descriptor*>(properties.begin()));
|
|
1492
1486
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1493
1487
|
}
|
|
1494
1488
|
|
|
1495
1489
|
inline MaybeOrValue<bool> Object::DefineProperties(
|
|
1496
1490
|
const std::vector<PropertyDescriptor>& properties) const {
|
|
1497
|
-
napi_status status = napi_define_properties(
|
|
1498
|
-
|
|
1491
|
+
napi_status status = napi_define_properties(
|
|
1492
|
+
_env,
|
|
1493
|
+
_value,
|
|
1494
|
+
properties.size(),
|
|
1495
|
+
reinterpret_cast<const napi_property_descriptor*>(properties.data()));
|
|
1499
1496
|
NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
|
|
1500
1497
|
}
|
|
1501
1498
|
|
|
@@ -1530,12 +1527,12 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
|
|
|
1530
1527
|
details::FinalizeData<T, Finalizer, Hint>* finalizeData =
|
|
1531
1528
|
new details::FinalizeData<T, Finalizer, Hint>(
|
|
1532
1529
|
{std::move(finalizeCallback), finalizeHint});
|
|
1533
|
-
napi_status status =
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1530
|
+
napi_status status = details::AttachData(
|
|
1531
|
+
_env,
|
|
1532
|
+
*this,
|
|
1533
|
+
data,
|
|
1534
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
|
|
1535
|
+
finalizeData);
|
|
1539
1536
|
if (status != napi_ok) {
|
|
1540
1537
|
delete finalizeData;
|
|
1541
1538
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
@@ -1638,7 +1635,8 @@ inline MaybeOrValue<bool> Object::Seal() const {
|
|
|
1638
1635
|
template <typename T>
|
|
1639
1636
|
inline External<T> External<T>::New(napi_env env, T* data) {
|
|
1640
1637
|
napi_value value;
|
|
1641
|
-
napi_status status =
|
|
1638
|
+
napi_status status =
|
|
1639
|
+
napi_create_external(env, data, nullptr, nullptr, &value);
|
|
1642
1640
|
NAPI_THROW_IF_FAILED(env, status, External());
|
|
1643
1641
|
return External(env, value);
|
|
1644
1642
|
}
|
|
@@ -1652,12 +1650,12 @@ inline External<T> External<T>::New(napi_env env,
|
|
|
1652
1650
|
details::FinalizeData<T, Finalizer>* finalizeData =
|
|
1653
1651
|
new details::FinalizeData<T, Finalizer>(
|
|
1654
1652
|
{std::move(finalizeCallback), nullptr});
|
|
1655
|
-
napi_status status =
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1653
|
+
napi_status status =
|
|
1654
|
+
napi_create_external(env,
|
|
1655
|
+
data,
|
|
1656
|
+
details::FinalizeData<T, Finalizer>::Wrapper,
|
|
1657
|
+
finalizeData,
|
|
1658
|
+
&value);
|
|
1661
1659
|
if (status != napi_ok) {
|
|
1662
1660
|
delete finalizeData;
|
|
1663
1661
|
NAPI_THROW_IF_FAILED(env, status, External());
|
|
@@ -1676,11 +1674,11 @@ inline External<T> External<T>::New(napi_env env,
|
|
|
1676
1674
|
new details::FinalizeData<T, Finalizer, Hint>(
|
|
1677
1675
|
{std::move(finalizeCallback), finalizeHint});
|
|
1678
1676
|
napi_status status = napi_create_external(
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1677
|
+
env,
|
|
1678
|
+
data,
|
|
1679
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
|
|
1680
|
+
finalizeData,
|
|
1681
|
+
&value);
|
|
1684
1682
|
if (status != napi_ok) {
|
|
1685
1683
|
delete finalizeData;
|
|
1686
1684
|
NAPI_THROW_IF_FAILED(env, status, External());
|
|
@@ -1689,12 +1687,11 @@ inline External<T> External<T>::New(napi_env env,
|
|
|
1689
1687
|
}
|
|
1690
1688
|
|
|
1691
1689
|
template <typename T>
|
|
1692
|
-
inline External<T>::External() : Value() {
|
|
1693
|
-
}
|
|
1690
|
+
inline External<T>::External() : Value() {}
|
|
1694
1691
|
|
|
1695
1692
|
template <typename T>
|
|
1696
|
-
inline External<T>::External(napi_env env, napi_value value)
|
|
1697
|
-
}
|
|
1693
|
+
inline External<T>::External(napi_env env, napi_value value)
|
|
1694
|
+
: Value(env, value) {}
|
|
1698
1695
|
|
|
1699
1696
|
template <typename T>
|
|
1700
1697
|
inline T* External<T>::Data() const {
|
|
@@ -1722,11 +1719,9 @@ inline Array Array::New(napi_env env, size_t length) {
|
|
|
1722
1719
|
return Array(env, value);
|
|
1723
1720
|
}
|
|
1724
1721
|
|
|
1725
|
-
inline Array::Array() : Object() {
|
|
1726
|
-
}
|
|
1722
|
+
inline Array::Array() : Object() {}
|
|
1727
1723
|
|
|
1728
|
-
inline Array::Array(napi_env env, napi_value value) : Object(env, value) {
|
|
1729
|
-
}
|
|
1724
|
+
inline Array::Array(napi_env env, napi_value value) : Object(env, value) {}
|
|
1730
1725
|
|
|
1731
1726
|
inline uint32_t Array::Length() const {
|
|
1732
1727
|
uint32_t result;
|
|
@@ -1753,7 +1748,7 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1753
1748
|
size_t byteLength) {
|
|
1754
1749
|
napi_value value;
|
|
1755
1750
|
napi_status status = napi_create_external_arraybuffer(
|
|
1756
|
-
|
|
1751
|
+
env, externalData, byteLength, nullptr, nullptr, &value);
|
|
1757
1752
|
NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
|
|
1758
1753
|
|
|
1759
1754
|
return ArrayBuffer(env, value);
|
|
@@ -1769,12 +1764,12 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1769
1764
|
new details::FinalizeData<void, Finalizer>(
|
|
1770
1765
|
{std::move(finalizeCallback), nullptr});
|
|
1771
1766
|
napi_status status = napi_create_external_arraybuffer(
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1767
|
+
env,
|
|
1768
|
+
externalData,
|
|
1769
|
+
byteLength,
|
|
1770
|
+
details::FinalizeData<void, Finalizer>::Wrapper,
|
|
1771
|
+
finalizeData,
|
|
1772
|
+
&value);
|
|
1778
1773
|
if (status != napi_ok) {
|
|
1779
1774
|
delete finalizeData;
|
|
1780
1775
|
NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
|
|
@@ -1794,12 +1789,12 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1794
1789
|
new details::FinalizeData<void, Finalizer, Hint>(
|
|
1795
1790
|
{std::move(finalizeCallback), finalizeHint});
|
|
1796
1791
|
napi_status status = napi_create_external_arraybuffer(
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1792
|
+
env,
|
|
1793
|
+
externalData,
|
|
1794
|
+
byteLength,
|
|
1795
|
+
details::FinalizeData<void, Finalizer, Hint>::WrapperWithHint,
|
|
1796
|
+
finalizeData,
|
|
1797
|
+
&value);
|
|
1803
1798
|
if (status != napi_ok) {
|
|
1804
1799
|
delete finalizeData;
|
|
1805
1800
|
NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
|
|
@@ -1808,12 +1803,10 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
|
|
|
1808
1803
|
return ArrayBuffer(env, value);
|
|
1809
1804
|
}
|
|
1810
1805
|
|
|
1811
|
-
inline ArrayBuffer::ArrayBuffer() : Object() {
|
|
1812
|
-
}
|
|
1806
|
+
inline ArrayBuffer::ArrayBuffer() : Object() {}
|
|
1813
1807
|
|
|
1814
1808
|
inline ArrayBuffer::ArrayBuffer(napi_env env, napi_value value)
|
|
1815
|
-
|
|
1816
|
-
}
|
|
1809
|
+
: Object(env, value) {}
|
|
1817
1810
|
|
|
1818
1811
|
inline void* ArrayBuffer::Data() {
|
|
1819
1812
|
void* data;
|
|
@@ -1824,7 +1817,8 @@ inline void* ArrayBuffer::Data() {
|
|
|
1824
1817
|
|
|
1825
1818
|
inline size_t ArrayBuffer::ByteLength() {
|
|
1826
1819
|
size_t length;
|
|
1827
|
-
napi_status status =
|
|
1820
|
+
napi_status status =
|
|
1821
|
+
napi_get_arraybuffer_info(_env, _value, nullptr, &length);
|
|
1828
1822
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
1829
1823
|
return length;
|
|
1830
1824
|
}
|
|
@@ -1846,8 +1840,7 @@ inline void ArrayBuffer::Detach() {
|
|
|
1846
1840
|
////////////////////////////////////////////////////////////////////////////////
|
|
1847
1841
|
// DataView class
|
|
1848
1842
|
////////////////////////////////////////////////////////////////////////////////
|
|
1849
|
-
inline DataView DataView::New(napi_env env,
|
|
1850
|
-
Napi::ArrayBuffer arrayBuffer) {
|
|
1843
|
+
inline DataView DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer) {
|
|
1851
1844
|
return New(env, arrayBuffer, 0, arrayBuffer.ByteLength());
|
|
1852
1845
|
}
|
|
1853
1846
|
|
|
@@ -1855,12 +1848,12 @@ inline DataView DataView::New(napi_env env,
|
|
|
1855
1848
|
Napi::ArrayBuffer arrayBuffer,
|
|
1856
1849
|
size_t byteOffset) {
|
|
1857
1850
|
if (byteOffset > arrayBuffer.ByteLength()) {
|
|
1858
|
-
NAPI_THROW(RangeError::New(
|
|
1859
|
-
|
|
1860
|
-
|
|
1851
|
+
NAPI_THROW(RangeError::New(
|
|
1852
|
+
env, "Start offset is outside the bounds of the buffer"),
|
|
1853
|
+
DataView());
|
|
1861
1854
|
}
|
|
1862
|
-
return New(
|
|
1863
|
-
arrayBuffer.ByteLength() - byteOffset);
|
|
1855
|
+
return New(
|
|
1856
|
+
env, arrayBuffer, byteOffset, arrayBuffer.ByteLength() - byteOffset);
|
|
1864
1857
|
}
|
|
1865
1858
|
|
|
1866
1859
|
inline DataView DataView::New(napi_env env,
|
|
@@ -1868,52 +1861,47 @@ inline DataView DataView::New(napi_env env,
|
|
|
1868
1861
|
size_t byteOffset,
|
|
1869
1862
|
size_t byteLength) {
|
|
1870
1863
|
if (byteOffset + byteLength > arrayBuffer.ByteLength()) {
|
|
1871
|
-
NAPI_THROW(RangeError::New(env, "Invalid DataView length"),
|
|
1872
|
-
DataView());
|
|
1864
|
+
NAPI_THROW(RangeError::New(env, "Invalid DataView length"), DataView());
|
|
1873
1865
|
}
|
|
1874
1866
|
napi_value value;
|
|
1875
|
-
napi_status status =
|
|
1876
|
-
|
|
1867
|
+
napi_status status =
|
|
1868
|
+
napi_create_dataview(env, byteLength, arrayBuffer, byteOffset, &value);
|
|
1877
1869
|
NAPI_THROW_IF_FAILED(env, status, DataView());
|
|
1878
1870
|
return DataView(env, value);
|
|
1879
1871
|
}
|
|
1880
1872
|
|
|
1881
|
-
inline DataView::DataView() : Object() {
|
|
1882
|
-
}
|
|
1873
|
+
inline DataView::DataView() : Object() {}
|
|
1883
1874
|
|
|
1884
1875
|
inline DataView::DataView(napi_env env, napi_value value) : Object(env, value) {
|
|
1885
|
-
napi_status status = napi_get_dataview_info(
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
nullptr /* byteOffset */);
|
|
1876
|
+
napi_status status = napi_get_dataview_info(_env,
|
|
1877
|
+
_value /* dataView */,
|
|
1878
|
+
&_length /* byteLength */,
|
|
1879
|
+
&_data /* data */,
|
|
1880
|
+
nullptr /* arrayBuffer */,
|
|
1881
|
+
nullptr /* byteOffset */);
|
|
1892
1882
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
1893
1883
|
}
|
|
1894
1884
|
|
|
1895
1885
|
inline Napi::ArrayBuffer DataView::ArrayBuffer() const {
|
|
1896
1886
|
napi_value arrayBuffer;
|
|
1897
|
-
napi_status status = napi_get_dataview_info(
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
nullptr /* byteOffset */);
|
|
1887
|
+
napi_status status = napi_get_dataview_info(_env,
|
|
1888
|
+
_value /* dataView */,
|
|
1889
|
+
nullptr /* byteLength */,
|
|
1890
|
+
nullptr /* data */,
|
|
1891
|
+
&arrayBuffer /* arrayBuffer */,
|
|
1892
|
+
nullptr /* byteOffset */);
|
|
1904
1893
|
NAPI_THROW_IF_FAILED(_env, status, Napi::ArrayBuffer());
|
|
1905
1894
|
return Napi::ArrayBuffer(_env, arrayBuffer);
|
|
1906
1895
|
}
|
|
1907
1896
|
|
|
1908
1897
|
inline size_t DataView::ByteOffset() const {
|
|
1909
1898
|
size_t byteOffset;
|
|
1910
|
-
napi_status status = napi_get_dataview_info(
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
&byteOffset /* byteOffset */);
|
|
1899
|
+
napi_status status = napi_get_dataview_info(_env,
|
|
1900
|
+
_value /* dataView */,
|
|
1901
|
+
nullptr /* byteLength */,
|
|
1902
|
+
nullptr /* data */,
|
|
1903
|
+
nullptr /* arrayBuffer */,
|
|
1904
|
+
&byteOffset /* byteOffset */);
|
|
1917
1905
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
1918
1906
|
return byteOffset;
|
|
1919
1907
|
}
|
|
@@ -1994,8 +1982,9 @@ template <typename T>
|
|
|
1994
1982
|
inline T DataView::ReadData(size_t byteOffset) const {
|
|
1995
1983
|
if (byteOffset + sizeof(T) > _length ||
|
|
1996
1984
|
byteOffset + sizeof(T) < byteOffset) { // overflow
|
|
1997
|
-
NAPI_THROW(
|
|
1998
|
-
"Offset is outside the bounds of the DataView"),
|
|
1985
|
+
NAPI_THROW(
|
|
1986
|
+
RangeError::New(_env, "Offset is outside the bounds of the DataView"),
|
|
1987
|
+
0);
|
|
1999
1988
|
}
|
|
2000
1989
|
|
|
2001
1990
|
return *reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset);
|
|
@@ -2005,8 +1994,8 @@ template <typename T>
|
|
|
2005
1994
|
inline void DataView::WriteData(size_t byteOffset, T value) const {
|
|
2006
1995
|
if (byteOffset + sizeof(T) > _length ||
|
|
2007
1996
|
byteOffset + sizeof(T) < byteOffset) { // overflow
|
|
2008
|
-
NAPI_THROW_VOID(
|
|
2009
|
-
"Offset is outside the bounds of the DataView"));
|
|
1997
|
+
NAPI_THROW_VOID(
|
|
1998
|
+
RangeError::New(_env, "Offset is outside the bounds of the DataView"));
|
|
2010
1999
|
}
|
|
2011
2000
|
|
|
2012
2001
|
*reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset) = value;
|
|
@@ -2017,33 +2006,37 @@ inline void DataView::WriteData(size_t byteOffset, T value) const {
|
|
|
2017
2006
|
////////////////////////////////////////////////////////////////////////////////
|
|
2018
2007
|
|
|
2019
2008
|
inline TypedArray::TypedArray()
|
|
2020
|
-
|
|
2021
|
-
}
|
|
2009
|
+
: Object(), _type(napi_typedarray_type::napi_int8_array), _length(0) {}
|
|
2022
2010
|
|
|
2023
2011
|
inline TypedArray::TypedArray(napi_env env, napi_value value)
|
|
2024
|
-
|
|
2012
|
+
: Object(env, value),
|
|
2013
|
+
_type(napi_typedarray_type::napi_int8_array),
|
|
2014
|
+
_length(0) {
|
|
2015
|
+
if (value != nullptr) {
|
|
2016
|
+
napi_status status =
|
|
2017
|
+
napi_get_typedarray_info(_env,
|
|
2018
|
+
_value,
|
|
2019
|
+
&const_cast<TypedArray*>(this)->_type,
|
|
2020
|
+
&const_cast<TypedArray*>(this)->_length,
|
|
2021
|
+
nullptr,
|
|
2022
|
+
nullptr,
|
|
2023
|
+
nullptr);
|
|
2024
|
+
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
2025
|
+
}
|
|
2025
2026
|
}
|
|
2026
2027
|
|
|
2027
2028
|
inline TypedArray::TypedArray(napi_env env,
|
|
2028
2029
|
napi_value value,
|
|
2029
2030
|
napi_typedarray_type type,
|
|
2030
2031
|
size_t length)
|
|
2031
|
-
|
|
2032
|
-
}
|
|
2032
|
+
: Object(env, value), _type(type), _length(length) {}
|
|
2033
2033
|
|
|
2034
2034
|
inline napi_typedarray_type TypedArray::TypedArrayType() const {
|
|
2035
|
-
if (_type == TypedArray::unknown_array_type) {
|
|
2036
|
-
napi_status status = napi_get_typedarray_info(_env, _value,
|
|
2037
|
-
&const_cast<TypedArray*>(this)->_type, &const_cast<TypedArray*>(this)->_length,
|
|
2038
|
-
nullptr, nullptr, nullptr);
|
|
2039
|
-
NAPI_THROW_IF_FAILED(_env, status, napi_int8_array);
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
2035
|
return _type;
|
|
2043
2036
|
}
|
|
2044
2037
|
|
|
2045
2038
|
inline uint8_t TypedArray::ElementSize() const {
|
|
2046
|
-
switch (
|
|
2039
|
+
switch (_type) {
|
|
2047
2040
|
case napi_int8_array:
|
|
2048
2041
|
case napi_uint8_array:
|
|
2049
2042
|
case napi_uint8_clamped_array:
|
|
@@ -2067,20 +2060,13 @@ inline uint8_t TypedArray::ElementSize() const {
|
|
|
2067
2060
|
}
|
|
2068
2061
|
|
|
2069
2062
|
inline size_t TypedArray::ElementLength() const {
|
|
2070
|
-
if (_type == TypedArray::unknown_array_type) {
|
|
2071
|
-
napi_status status = napi_get_typedarray_info(_env, _value,
|
|
2072
|
-
&const_cast<TypedArray*>(this)->_type, &const_cast<TypedArray*>(this)->_length,
|
|
2073
|
-
nullptr, nullptr, nullptr);
|
|
2074
|
-
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
2063
|
return _length;
|
|
2078
2064
|
}
|
|
2079
2065
|
|
|
2080
2066
|
inline size_t TypedArray::ByteOffset() const {
|
|
2081
2067
|
size_t byteOffset;
|
|
2082
2068
|
napi_status status = napi_get_typedarray_info(
|
|
2083
|
-
|
|
2069
|
+
_env, _value, nullptr, nullptr, nullptr, nullptr, &byteOffset);
|
|
2084
2070
|
NAPI_THROW_IF_FAILED(_env, status, 0);
|
|
2085
2071
|
return byteOffset;
|
|
2086
2072
|
}
|
|
@@ -2092,7 +2078,7 @@ inline size_t TypedArray::ByteLength() const {
|
|
|
2092
2078
|
inline Napi::ArrayBuffer TypedArray::ArrayBuffer() const {
|
|
2093
2079
|
napi_value arrayBuffer;
|
|
2094
2080
|
napi_status status = napi_get_typedarray_info(
|
|
2095
|
-
|
|
2081
|
+
_env, _value, nullptr, nullptr, nullptr, &arrayBuffer, nullptr);
|
|
2096
2082
|
NAPI_THROW_IF_FAILED(_env, status, Napi::ArrayBuffer());
|
|
2097
2083
|
return Napi::ArrayBuffer(_env, arrayBuffer);
|
|
2098
2084
|
}
|
|
@@ -2105,7 +2091,8 @@ template <typename T>
|
|
|
2105
2091
|
inline TypedArrayOf<T> TypedArrayOf<T>::New(napi_env env,
|
|
2106
2092
|
size_t elementLength,
|
|
2107
2093
|
napi_typedarray_type type) {
|
|
2108
|
-
Napi::ArrayBuffer arrayBuffer =
|
|
2094
|
+
Napi::ArrayBuffer arrayBuffer =
|
|
2095
|
+
Napi::ArrayBuffer::New(env, elementLength * sizeof(T));
|
|
2109
2096
|
return New(env, elementLength, arrayBuffer, 0, type);
|
|
2110
2097
|
}
|
|
2111
2098
|
|
|
@@ -2117,21 +2104,24 @@ inline TypedArrayOf<T> TypedArrayOf<T>::New(napi_env env,
|
|
|
2117
2104
|
napi_typedarray_type type) {
|
|
2118
2105
|
napi_value value;
|
|
2119
2106
|
napi_status status = napi_create_typedarray(
|
|
2120
|
-
|
|
2107
|
+
env, type, elementLength, arrayBuffer, bufferOffset, &value);
|
|
2121
2108
|
NAPI_THROW_IF_FAILED(env, status, TypedArrayOf<T>());
|
|
2122
2109
|
|
|
2123
2110
|
return TypedArrayOf<T>(
|
|
2124
|
-
|
|
2125
|
-
|
|
2111
|
+
env,
|
|
2112
|
+
value,
|
|
2113
|
+
type,
|
|
2114
|
+
elementLength,
|
|
2115
|
+
reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(arrayBuffer.Data()) +
|
|
2116
|
+
bufferOffset));
|
|
2126
2117
|
}
|
|
2127
2118
|
|
|
2128
2119
|
template <typename T>
|
|
2129
|
-
inline TypedArrayOf<T>::TypedArrayOf() : TypedArray(), _data(nullptr) {
|
|
2130
|
-
}
|
|
2120
|
+
inline TypedArrayOf<T>::TypedArrayOf() : TypedArray(), _data(nullptr) {}
|
|
2131
2121
|
|
|
2132
2122
|
template <typename T>
|
|
2133
2123
|
inline TypedArrayOf<T>::TypedArrayOf(napi_env env, napi_value value)
|
|
2134
|
-
|
|
2124
|
+
: TypedArray(env, value), _data(nullptr) {
|
|
2135
2125
|
napi_status status = napi_ok;
|
|
2136
2126
|
if (value != nullptr) {
|
|
2137
2127
|
void* data = nullptr;
|
|
@@ -2151,21 +2141,24 @@ inline TypedArrayOf<T>::TypedArrayOf(napi_env env,
|
|
|
2151
2141
|
napi_typedarray_type type,
|
|
2152
2142
|
size_t length,
|
|
2153
2143
|
T* data)
|
|
2154
|
-
|
|
2144
|
+
: TypedArray(env, value, type, length), _data(data) {
|
|
2155
2145
|
if (!(type == TypedArrayTypeForPrimitiveType<T>() ||
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2146
|
+
(type == napi_uint8_clamped_array &&
|
|
2147
|
+
std::is_same<T, uint8_t>::value))) {
|
|
2148
|
+
NAPI_THROW_VOID(TypeError::New(
|
|
2149
|
+
env,
|
|
2150
|
+
"Array type must match the template parameter. "
|
|
2151
|
+
"(Uint8 arrays may optionally have the \"clamped\" array type.)"));
|
|
2159
2152
|
}
|
|
2160
2153
|
}
|
|
2161
2154
|
|
|
2162
2155
|
template <typename T>
|
|
2163
|
-
inline T& TypedArrayOf<T>::operator
|
|
2156
|
+
inline T& TypedArrayOf<T>::operator[](size_t index) {
|
|
2164
2157
|
return _data[index];
|
|
2165
2158
|
}
|
|
2166
2159
|
|
|
2167
2160
|
template <typename T>
|
|
2168
|
-
inline const T& TypedArrayOf<T>::operator
|
|
2161
|
+
inline const T& TypedArrayOf<T>::operator[](size_t index) const {
|
|
2169
2162
|
return _data[index];
|
|
2170
2163
|
}
|
|
2171
2164
|
|
|
@@ -2184,12 +2177,11 @@ inline const T* TypedArrayOf<T>::Data() const {
|
|
|
2184
2177
|
////////////////////////////////////////////////////////////////////////////////
|
|
2185
2178
|
|
|
2186
2179
|
template <typename CbData>
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
napi_value* result) {
|
|
2180
|
+
inline napi_status CreateFunction(napi_env env,
|
|
2181
|
+
const char* utf8name,
|
|
2182
|
+
napi_callback cb,
|
|
2183
|
+
CbData* data,
|
|
2184
|
+
napi_value* result) {
|
|
2193
2185
|
napi_status status =
|
|
2194
2186
|
napi_create_function(env, utf8name, NAPI_AUTO_LENGTH, cb, data, result);
|
|
2195
2187
|
if (status == napi_ok) {
|
|
@@ -2249,11 +2241,8 @@ inline Function Function::New(napi_env env,
|
|
|
2249
2241
|
auto callbackData = new CbData{std::move(cb), data};
|
|
2250
2242
|
|
|
2251
2243
|
napi_value value;
|
|
2252
|
-
napi_status status =
|
|
2253
|
-
|
|
2254
|
-
CbData::Wrapper,
|
|
2255
|
-
callbackData,
|
|
2256
|
-
&value);
|
|
2244
|
+
napi_status status =
|
|
2245
|
+
CreateFunction(env, utf8name, CbData::Wrapper, callbackData, &value);
|
|
2257
2246
|
if (status != napi_ok) {
|
|
2258
2247
|
delete callbackData;
|
|
2259
2248
|
NAPI_THROW_IF_FAILED(env, status, Function());
|
|
@@ -2270,11 +2259,10 @@ inline Function Function::New(napi_env env,
|
|
|
2270
2259
|
return New(env, cb, utf8name.c_str(), data);
|
|
2271
2260
|
}
|
|
2272
2261
|
|
|
2273
|
-
inline Function::Function() : Object() {
|
|
2274
|
-
}
|
|
2262
|
+
inline Function::Function() : Object() {}
|
|
2275
2263
|
|
|
2276
|
-
inline Function::Function(napi_env env, napi_value value)
|
|
2277
|
-
}
|
|
2264
|
+
inline Function::Function(napi_env env, napi_value value)
|
|
2265
|
+
: Object(env, value) {}
|
|
2278
2266
|
|
|
2279
2267
|
inline MaybeOrValue<Value> Function::operator()(
|
|
2280
2268
|
const std::initializer_list<napi_value>& args) const {
|
|
@@ -2336,8 +2324,8 @@ inline MaybeOrValue<Value> Function::Call(napi_value recv,
|
|
|
2336
2324
|
size_t argc,
|
|
2337
2325
|
const napi_value* args) const {
|
|
2338
2326
|
napi_value result;
|
|
2339
|
-
napi_status status =
|
|
2340
|
-
|
|
2327
|
+
napi_status status =
|
|
2328
|
+
napi_call_function(_env, recv, _value, argc, args, &result);
|
|
2341
2329
|
NAPI_RETURN_OR_THROW_IF_FAILED(
|
|
2342
2330
|
_env, status, Napi::Value(_env, result), Napi::Value);
|
|
2343
2331
|
}
|
|
@@ -2362,8 +2350,8 @@ inline MaybeOrValue<Value> Function::MakeCallback(
|
|
|
2362
2350
|
const napi_value* args,
|
|
2363
2351
|
napi_async_context context) const {
|
|
2364
2352
|
napi_value result;
|
|
2365
|
-
napi_status status =
|
|
2366
|
-
|
|
2353
|
+
napi_status status =
|
|
2354
|
+
napi_make_callback(_env, context, recv, _value, argc, args, &result);
|
|
2367
2355
|
NAPI_RETURN_OR_THROW_IF_FAILED(
|
|
2368
2356
|
_env, status, Napi::Value(_env, result), Napi::Value);
|
|
2369
2357
|
}
|
|
@@ -2381,8 +2369,7 @@ inline MaybeOrValue<Object> Function::New(
|
|
|
2381
2369
|
inline MaybeOrValue<Object> Function::New(size_t argc,
|
|
2382
2370
|
const napi_value* args) const {
|
|
2383
2371
|
napi_value result;
|
|
2384
|
-
napi_status status = napi_new_instance(
|
|
2385
|
-
_env, _value, argc, args, &result);
|
|
2372
|
+
napi_status status = napi_new_instance(_env, _value, argc, args, &result);
|
|
2386
2373
|
NAPI_RETURN_OR_THROW_IF_FAILED(
|
|
2387
2374
|
_env, status, Napi::Object(_env, result), Napi::Object);
|
|
2388
2375
|
}
|
|
@@ -2418,8 +2405,7 @@ inline void Promise::Deferred::Reject(napi_value value) const {
|
|
|
2418
2405
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
2419
2406
|
}
|
|
2420
2407
|
|
|
2421
|
-
inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {
|
|
2422
|
-
}
|
|
2408
|
+
inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
|
|
2423
2409
|
|
|
2424
2410
|
////////////////////////////////////////////////////////////////////////////////
|
|
2425
2411
|
// Buffer<T> class
|
|
@@ -2429,7 +2415,8 @@ template <typename T>
|
|
|
2429
2415
|
inline Buffer<T> Buffer<T>::New(napi_env env, size_t length) {
|
|
2430
2416
|
napi_value value;
|
|
2431
2417
|
void* data;
|
|
2432
|
-
napi_status status =
|
|
2418
|
+
napi_status status =
|
|
2419
|
+
napi_create_buffer(env, length * sizeof(T), &data, &value);
|
|
2433
2420
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2434
2421
|
return Buffer(env, value, length, static_cast<T*>(data));
|
|
2435
2422
|
}
|
|
@@ -2438,7 +2425,7 @@ template <typename T>
|
|
|
2438
2425
|
inline Buffer<T> Buffer<T>::New(napi_env env, T* data, size_t length) {
|
|
2439
2426
|
napi_value value;
|
|
2440
2427
|
napi_status status = napi_create_external_buffer(
|
|
2441
|
-
|
|
2428
|
+
env, length * sizeof(T), data, nullptr, nullptr, &value);
|
|
2442
2429
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2443
2430
|
return Buffer(env, value, length, data);
|
|
2444
2431
|
}
|
|
@@ -2453,13 +2440,13 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2453
2440
|
details::FinalizeData<T, Finalizer>* finalizeData =
|
|
2454
2441
|
new details::FinalizeData<T, Finalizer>(
|
|
2455
2442
|
{std::move(finalizeCallback), nullptr});
|
|
2456
|
-
napi_status status =
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2443
|
+
napi_status status =
|
|
2444
|
+
napi_create_external_buffer(env,
|
|
2445
|
+
length * sizeof(T),
|
|
2446
|
+
data,
|
|
2447
|
+
details::FinalizeData<T, Finalizer>::Wrapper,
|
|
2448
|
+
finalizeData,
|
|
2449
|
+
&value);
|
|
2463
2450
|
if (status != napi_ok) {
|
|
2464
2451
|
delete finalizeData;
|
|
2465
2452
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
@@ -2479,12 +2466,12 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2479
2466
|
new details::FinalizeData<T, Finalizer, Hint>(
|
|
2480
2467
|
{std::move(finalizeCallback), finalizeHint});
|
|
2481
2468
|
napi_status status = napi_create_external_buffer(
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2469
|
+
env,
|
|
2470
|
+
length * sizeof(T),
|
|
2471
|
+
data,
|
|
2472
|
+
details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
|
|
2473
|
+
finalizeData,
|
|
2474
|
+
&value);
|
|
2488
2475
|
if (status != napi_ok) {
|
|
2489
2476
|
delete finalizeData;
|
|
2490
2477
|
NAPI_THROW_IF_FAILED(env, status, Buffer());
|
|
@@ -2495,25 +2482,22 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
|
|
|
2495
2482
|
template <typename T>
|
|
2496
2483
|
inline Buffer<T> Buffer<T>::Copy(napi_env env, const T* data, size_t length) {
|
|
2497
2484
|
napi_value value;
|
|
2498
|
-
napi_status status =
|
|
2499
|
-
|
|
2485
|
+
napi_status status =
|
|
2486
|
+
napi_create_buffer_copy(env, length * sizeof(T), data, nullptr, &value);
|
|
2500
2487
|
NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
|
|
2501
2488
|
return Buffer<T>(env, value);
|
|
2502
2489
|
}
|
|
2503
2490
|
|
|
2504
2491
|
template <typename T>
|
|
2505
|
-
inline Buffer<T>::Buffer() : Uint8Array(), _length(0), _data(nullptr) {
|
|
2506
|
-
}
|
|
2492
|
+
inline Buffer<T>::Buffer() : Uint8Array(), _length(0), _data(nullptr) {}
|
|
2507
2493
|
|
|
2508
2494
|
template <typename T>
|
|
2509
2495
|
inline Buffer<T>::Buffer(napi_env env, napi_value value)
|
|
2510
|
-
|
|
2511
|
-
}
|
|
2496
|
+
: Uint8Array(env, value), _length(0), _data(nullptr) {}
|
|
2512
2497
|
|
|
2513
2498
|
template <typename T>
|
|
2514
2499
|
inline Buffer<T>::Buffer(napi_env env, napi_value value, size_t length, T* data)
|
|
2515
|
-
|
|
2516
|
-
}
|
|
2500
|
+
: Uint8Array(env, value), _length(length), _data(data) {}
|
|
2517
2501
|
|
|
2518
2502
|
template <typename T>
|
|
2519
2503
|
inline size_t Buffer<T>::Length() const {
|
|
@@ -2535,9 +2519,10 @@ inline void Buffer<T>::EnsureInfo() const {
|
|
|
2535
2519
|
if (_data == nullptr) {
|
|
2536
2520
|
size_t byteLength;
|
|
2537
2521
|
void* voidData;
|
|
2538
|
-
napi_status status =
|
|
2522
|
+
napi_status status =
|
|
2523
|
+
napi_get_buffer_info(_env, _value, &voidData, &byteLength);
|
|
2539
2524
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
2540
|
-
_length = byteLength / sizeof
|
|
2525
|
+
_length = byteLength / sizeof(T);
|
|
2541
2526
|
_data = static_cast<T*>(voidData);
|
|
2542
2527
|
}
|
|
2543
2528
|
}
|
|
@@ -2574,19 +2559,16 @@ inline Error Error::New(napi_env env) {
|
|
|
2574
2559
|
// A pending exception takes precedence over any internal error status.
|
|
2575
2560
|
if (is_exception_pending) {
|
|
2576
2561
|
status = napi_get_and_clear_last_exception(env, &error);
|
|
2577
|
-
NAPI_FATAL_IF_FAILED(
|
|
2578
|
-
|
|
2579
|
-
else {
|
|
2562
|
+
NAPI_FATAL_IF_FAILED(
|
|
2563
|
+
status, "Error::New", "napi_get_and_clear_last_exception");
|
|
2564
|
+
} else {
|
|
2580
2565
|
const char* error_message = last_error_info_copy.error_message != nullptr
|
|
2581
2566
|
? last_error_info_copy.error_message
|
|
2582
2567
|
: "Error in native callback";
|
|
2583
2568
|
|
|
2584
2569
|
napi_value message;
|
|
2585
2570
|
status = napi_create_string_utf8(
|
|
2586
|
-
|
|
2587
|
-
error_message,
|
|
2588
|
-
std::strlen(error_message),
|
|
2589
|
-
&message);
|
|
2571
|
+
env, error_message, std::strlen(error_message), &message);
|
|
2590
2572
|
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_create_string_utf8");
|
|
2591
2573
|
|
|
2592
2574
|
switch (last_error_info_copy.error_code) {
|
|
@@ -2607,21 +2589,24 @@ inline Error Error::New(napi_env env) {
|
|
|
2607
2589
|
}
|
|
2608
2590
|
|
|
2609
2591
|
inline Error Error::New(napi_env env, const char* message) {
|
|
2610
|
-
return Error::New<Error>(
|
|
2592
|
+
return Error::New<Error>(
|
|
2593
|
+
env, message, std::strlen(message), napi_create_error);
|
|
2611
2594
|
}
|
|
2612
2595
|
|
|
2613
2596
|
inline Error Error::New(napi_env env, const std::string& message) {
|
|
2614
|
-
return Error::New<Error>(
|
|
2597
|
+
return Error::New<Error>(
|
|
2598
|
+
env, message.c_str(), message.size(), napi_create_error);
|
|
2615
2599
|
}
|
|
2616
2600
|
|
|
2617
|
-
inline NAPI_NO_RETURN void Error::Fatal(const char* location,
|
|
2601
|
+
inline NAPI_NO_RETURN void Error::Fatal(const char* location,
|
|
2602
|
+
const char* message) {
|
|
2618
2603
|
napi_fatal_error(location, NAPI_AUTO_LENGTH, message, NAPI_AUTO_LENGTH);
|
|
2619
2604
|
}
|
|
2620
2605
|
|
|
2621
|
-
inline Error::Error() : ObjectReference() {
|
|
2622
|
-
}
|
|
2606
|
+
inline Error::Error() : ObjectReference() {}
|
|
2623
2607
|
|
|
2624
|
-
inline Error::Error(napi_env env, napi_value value)
|
|
2608
|
+
inline Error::Error(napi_env env, napi_value value)
|
|
2609
|
+
: ObjectReference(env, nullptr) {
|
|
2625
2610
|
if (value != nullptr) {
|
|
2626
2611
|
// Attempting to create a reference on the error object.
|
|
2627
2612
|
// If it's not a Object/Function/Symbol, this call will return an error
|
|
@@ -2699,18 +2684,16 @@ inline Object Error::Value() const {
|
|
|
2699
2684
|
return Object(_env, refValue);
|
|
2700
2685
|
}
|
|
2701
2686
|
|
|
2702
|
-
inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {
|
|
2703
|
-
}
|
|
2687
|
+
inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {}
|
|
2704
2688
|
|
|
2705
|
-
inline Error& Error::operator
|
|
2689
|
+
inline Error& Error::operator=(Error&& other) {
|
|
2706
2690
|
static_cast<Reference<Object>*>(this)->operator=(std::move(other));
|
|
2707
2691
|
return *this;
|
|
2708
2692
|
}
|
|
2709
2693
|
|
|
2710
|
-
inline Error::Error(const Error& other) : ObjectReference(other) {
|
|
2711
|
-
}
|
|
2694
|
+
inline Error::Error(const Error& other) : ObjectReference(other) {}
|
|
2712
2695
|
|
|
2713
|
-
inline Error& Error::operator
|
|
2696
|
+
inline Error& Error::operator=(const Error& other) {
|
|
2714
2697
|
Reset();
|
|
2715
2698
|
|
|
2716
2699
|
_env = other.Env();
|
|
@@ -2730,12 +2713,11 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
|
|
|
2730
2713
|
#ifdef NAPI_CPP_EXCEPTIONS
|
|
2731
2714
|
try {
|
|
2732
2715
|
_message = Get("message").As<String>();
|
|
2733
|
-
}
|
|
2734
|
-
catch (...) {
|
|
2716
|
+
} catch (...) {
|
|
2735
2717
|
// Catch all errors here, to include e.g. a std::bad_alloc from
|
|
2736
2718
|
// the std::string::operator=, because this method may not throw.
|
|
2737
2719
|
}
|
|
2738
|
-
#else
|
|
2720
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
2739
2721
|
#if defined(NODE_ADDON_API_ENABLE_MAYBE)
|
|
2740
2722
|
Napi::Value message_val;
|
|
2741
2723
|
if (Get("message").UnwrapTo(&message_val)) {
|
|
@@ -2744,7 +2726,7 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
|
|
|
2744
2726
|
#else
|
|
2745
2727
|
_message = Get("message").As<String>();
|
|
2746
2728
|
#endif
|
|
2747
|
-
#endif
|
|
2729
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
2748
2730
|
}
|
|
2749
2731
|
return _message;
|
|
2750
2732
|
}
|
|
@@ -2790,9 +2772,10 @@ inline void Error::ThrowAsJavaScriptException() const {
|
|
|
2790
2772
|
if (status != napi_ok) {
|
|
2791
2773
|
throw Error::New(_env);
|
|
2792
2774
|
}
|
|
2793
|
-
#else
|
|
2794
|
-
NAPI_FATAL_IF_FAILED(
|
|
2795
|
-
|
|
2775
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
2776
|
+
NAPI_FATAL_IF_FAILED(
|
|
2777
|
+
status, "Error::ThrowAsJavaScriptException", "napi_throw");
|
|
2778
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
2796
2779
|
}
|
|
2797
2780
|
}
|
|
2798
2781
|
|
|
@@ -2802,7 +2785,7 @@ inline const char* Error::what() const NAPI_NOEXCEPT {
|
|
|
2802
2785
|
return Message().c_str();
|
|
2803
2786
|
}
|
|
2804
2787
|
|
|
2805
|
-
#endif
|
|
2788
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
2806
2789
|
|
|
2807
2790
|
inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT {
|
|
2808
2791
|
return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
|
|
@@ -2825,39 +2808,42 @@ inline TError Error::New(napi_env env,
|
|
|
2825
2808
|
}
|
|
2826
2809
|
|
|
2827
2810
|
inline TypeError TypeError::New(napi_env env, const char* message) {
|
|
2828
|
-
return Error::New<TypeError>(
|
|
2811
|
+
return Error::New<TypeError>(
|
|
2812
|
+
env, message, std::strlen(message), napi_create_type_error);
|
|
2829
2813
|
}
|
|
2830
2814
|
|
|
2831
2815
|
inline TypeError TypeError::New(napi_env env, const std::string& message) {
|
|
2832
|
-
return Error::New<TypeError>(
|
|
2816
|
+
return Error::New<TypeError>(
|
|
2817
|
+
env, message.c_str(), message.size(), napi_create_type_error);
|
|
2833
2818
|
}
|
|
2834
2819
|
|
|
2835
|
-
inline TypeError::TypeError() : Error() {
|
|
2836
|
-
}
|
|
2820
|
+
inline TypeError::TypeError() : Error() {}
|
|
2837
2821
|
|
|
2838
|
-
inline TypeError::TypeError(napi_env env, napi_value value)
|
|
2839
|
-
}
|
|
2822
|
+
inline TypeError::TypeError(napi_env env, napi_value value)
|
|
2823
|
+
: Error(env, value) {}
|
|
2840
2824
|
|
|
2841
2825
|
inline RangeError RangeError::New(napi_env env, const char* message) {
|
|
2842
|
-
return Error::New<RangeError>(
|
|
2826
|
+
return Error::New<RangeError>(
|
|
2827
|
+
env, message, std::strlen(message), napi_create_range_error);
|
|
2843
2828
|
}
|
|
2844
2829
|
|
|
2845
2830
|
inline RangeError RangeError::New(napi_env env, const std::string& message) {
|
|
2846
|
-
return Error::New<RangeError>(
|
|
2831
|
+
return Error::New<RangeError>(
|
|
2832
|
+
env, message.c_str(), message.size(), napi_create_range_error);
|
|
2847
2833
|
}
|
|
2848
2834
|
|
|
2849
|
-
inline RangeError::RangeError() : Error() {
|
|
2850
|
-
}
|
|
2835
|
+
inline RangeError::RangeError() : Error() {}
|
|
2851
2836
|
|
|
2852
|
-
inline RangeError::RangeError(napi_env env, napi_value value)
|
|
2853
|
-
}
|
|
2837
|
+
inline RangeError::RangeError(napi_env env, napi_value value)
|
|
2838
|
+
: Error(env, value) {}
|
|
2854
2839
|
|
|
2855
2840
|
////////////////////////////////////////////////////////////////////////////////
|
|
2856
2841
|
// Reference<T> class
|
|
2857
2842
|
////////////////////////////////////////////////////////////////////////////////
|
|
2858
2843
|
|
|
2859
2844
|
template <typename T>
|
|
2860
|
-
inline Reference<T> Reference<T>::New(const T& value,
|
|
2845
|
+
inline Reference<T> Reference<T>::New(const T& value,
|
|
2846
|
+
uint32_t initialRefcount) {
|
|
2861
2847
|
napi_env env = value.Env();
|
|
2862
2848
|
napi_value val = value;
|
|
2863
2849
|
|
|
@@ -2872,15 +2858,13 @@ inline Reference<T> Reference<T>::New(const T& value, uint32_t initialRefcount)
|
|
|
2872
2858
|
return Reference<T>(env, ref);
|
|
2873
2859
|
}
|
|
2874
2860
|
|
|
2875
|
-
|
|
2876
2861
|
template <typename T>
|
|
2877
|
-
inline Reference<T>::Reference()
|
|
2878
|
-
}
|
|
2862
|
+
inline Reference<T>::Reference()
|
|
2863
|
+
: _env(nullptr), _ref(nullptr), _suppressDestruct(false) {}
|
|
2879
2864
|
|
|
2880
2865
|
template <typename T>
|
|
2881
2866
|
inline Reference<T>::Reference(napi_env env, napi_ref ref)
|
|
2882
|
-
|
|
2883
|
-
}
|
|
2867
|
+
: _env(env), _ref(ref), _suppressDestruct(false) {}
|
|
2884
2868
|
|
|
2885
2869
|
template <typename T>
|
|
2886
2870
|
inline Reference<T>::~Reference() {
|
|
@@ -2895,14 +2879,16 @@ inline Reference<T>::~Reference() {
|
|
|
2895
2879
|
|
|
2896
2880
|
template <typename T>
|
|
2897
2881
|
inline Reference<T>::Reference(Reference<T>&& other)
|
|
2898
|
-
|
|
2882
|
+
: _env(other._env),
|
|
2883
|
+
_ref(other._ref),
|
|
2884
|
+
_suppressDestruct(other._suppressDestruct) {
|
|
2899
2885
|
other._env = nullptr;
|
|
2900
2886
|
other._ref = nullptr;
|
|
2901
2887
|
other._suppressDestruct = false;
|
|
2902
2888
|
}
|
|
2903
2889
|
|
|
2904
2890
|
template <typename T>
|
|
2905
|
-
inline Reference<T>& Reference<T>::operator
|
|
2891
|
+
inline Reference<T>& Reference<T>::operator=(Reference<T>&& other) {
|
|
2906
2892
|
Reset();
|
|
2907
2893
|
_env = other._env;
|
|
2908
2894
|
_ref = other._ref;
|
|
@@ -2915,15 +2901,17 @@ inline Reference<T>& Reference<T>::operator =(Reference<T>&& other) {
|
|
|
2915
2901
|
|
|
2916
2902
|
template <typename T>
|
|
2917
2903
|
inline Reference<T>::Reference(const Reference<T>& other)
|
|
2918
|
-
|
|
2904
|
+
: _env(other._env), _ref(nullptr), _suppressDestruct(false) {
|
|
2919
2905
|
HandleScope scope(_env);
|
|
2920
2906
|
|
|
2921
2907
|
napi_value value = other.Value();
|
|
2922
2908
|
if (value != nullptr) {
|
|
2923
|
-
// Copying is a limited scenario (currently only used for Error object) and
|
|
2924
|
-
// strong reference to the given value even if the incoming
|
|
2909
|
+
// Copying is a limited scenario (currently only used for Error object) and
|
|
2910
|
+
// always creates a strong reference to the given value even if the incoming
|
|
2911
|
+
// reference is weak.
|
|
2925
2912
|
napi_status status = napi_create_reference(_env, value, 1, &_ref);
|
|
2926
|
-
NAPI_FATAL_IF_FAILED(
|
|
2913
|
+
NAPI_FATAL_IF_FAILED(
|
|
2914
|
+
status, "Reference<T>::Reference", "napi_create_reference");
|
|
2927
2915
|
}
|
|
2928
2916
|
}
|
|
2929
2917
|
|
|
@@ -2933,14 +2921,14 @@ inline Reference<T>::operator napi_ref() const {
|
|
|
2933
2921
|
}
|
|
2934
2922
|
|
|
2935
2923
|
template <typename T>
|
|
2936
|
-
inline bool Reference<T>::operator
|
|
2924
|
+
inline bool Reference<T>::operator==(const Reference<T>& other) const {
|
|
2937
2925
|
HandleScope scope(_env);
|
|
2938
2926
|
return this->Value().StrictEquals(other.Value());
|
|
2939
2927
|
}
|
|
2940
2928
|
|
|
2941
2929
|
template <typename T>
|
|
2942
|
-
inline bool Reference<T>::operator
|
|
2943
|
-
return !this->operator
|
|
2930
|
+
inline bool Reference<T>::operator!=(const Reference<T>& other) const {
|
|
2931
|
+
return !this->operator==(other);
|
|
2944
2932
|
}
|
|
2945
2933
|
|
|
2946
2934
|
template <typename T>
|
|
@@ -3037,33 +3025,29 @@ inline FunctionReference Persistent(Function value) {
|
|
|
3037
3025
|
// ObjectReference class
|
|
3038
3026
|
////////////////////////////////////////////////////////////////////////////////
|
|
3039
3027
|
|
|
3040
|
-
inline ObjectReference::ObjectReference(): Reference<Object>() {
|
|
3041
|
-
}
|
|
3028
|
+
inline ObjectReference::ObjectReference() : Reference<Object>() {}
|
|
3042
3029
|
|
|
3043
|
-
inline ObjectReference::ObjectReference(napi_env env, napi_ref ref)
|
|
3044
|
-
}
|
|
3030
|
+
inline ObjectReference::ObjectReference(napi_env env, napi_ref ref)
|
|
3031
|
+
: Reference<Object>(env, ref) {}
|
|
3045
3032
|
|
|
3046
3033
|
inline ObjectReference::ObjectReference(Reference<Object>&& other)
|
|
3047
|
-
|
|
3048
|
-
}
|
|
3034
|
+
: Reference<Object>(std::move(other)) {}
|
|
3049
3035
|
|
|
3050
|
-
inline ObjectReference& ObjectReference::operator
|
|
3036
|
+
inline ObjectReference& ObjectReference::operator=(Reference<Object>&& other) {
|
|
3051
3037
|
static_cast<Reference<Object>*>(this)->operator=(std::move(other));
|
|
3052
3038
|
return *this;
|
|
3053
3039
|
}
|
|
3054
3040
|
|
|
3055
3041
|
inline ObjectReference::ObjectReference(ObjectReference&& other)
|
|
3056
|
-
|
|
3057
|
-
}
|
|
3042
|
+
: Reference<Object>(std::move(other)) {}
|
|
3058
3043
|
|
|
3059
|
-
inline ObjectReference& ObjectReference::operator
|
|
3044
|
+
inline ObjectReference& ObjectReference::operator=(ObjectReference&& other) {
|
|
3060
3045
|
static_cast<Reference<Object>*>(this)->operator=(std::move(other));
|
|
3061
3046
|
return *this;
|
|
3062
3047
|
}
|
|
3063
3048
|
|
|
3064
3049
|
inline ObjectReference::ObjectReference(const ObjectReference& other)
|
|
3065
|
-
|
|
3066
|
-
}
|
|
3050
|
+
: Reference<Object>(other) {}
|
|
3067
3051
|
|
|
3068
3052
|
inline MaybeOrValue<Napi::Value> ObjectReference::Get(
|
|
3069
3053
|
const char* utf8name) const {
|
|
@@ -3215,27 +3199,25 @@ inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
|
|
|
3215
3199
|
// FunctionReference class
|
|
3216
3200
|
////////////////////////////////////////////////////////////////////////////////
|
|
3217
3201
|
|
|
3218
|
-
inline FunctionReference::FunctionReference(): Reference<Function>() {
|
|
3219
|
-
}
|
|
3202
|
+
inline FunctionReference::FunctionReference() : Reference<Function>() {}
|
|
3220
3203
|
|
|
3221
3204
|
inline FunctionReference::FunctionReference(napi_env env, napi_ref ref)
|
|
3222
|
-
|
|
3223
|
-
}
|
|
3205
|
+
: Reference<Function>(env, ref) {}
|
|
3224
3206
|
|
|
3225
3207
|
inline FunctionReference::FunctionReference(Reference<Function>&& other)
|
|
3226
|
-
|
|
3227
|
-
}
|
|
3208
|
+
: Reference<Function>(std::move(other)) {}
|
|
3228
3209
|
|
|
3229
|
-
inline FunctionReference& FunctionReference::operator
|
|
3210
|
+
inline FunctionReference& FunctionReference::operator=(
|
|
3211
|
+
Reference<Function>&& other) {
|
|
3230
3212
|
static_cast<Reference<Function>*>(this)->operator=(std::move(other));
|
|
3231
3213
|
return *this;
|
|
3232
3214
|
}
|
|
3233
3215
|
|
|
3234
3216
|
inline FunctionReference::FunctionReference(FunctionReference&& other)
|
|
3235
|
-
|
|
3236
|
-
}
|
|
3217
|
+
: Reference<Function>(std::move(other)) {}
|
|
3237
3218
|
|
|
3238
|
-
inline FunctionReference& FunctionReference::operator
|
|
3219
|
+
inline FunctionReference& FunctionReference::operator=(
|
|
3220
|
+
FunctionReference&& other) {
|
|
3239
3221
|
static_cast<Reference<Function>*>(this)->operator=(std::move(other));
|
|
3240
3222
|
return *this;
|
|
3241
3223
|
}
|
|
@@ -3441,10 +3423,15 @@ inline MaybeOrValue<Object> FunctionReference::New(
|
|
|
3441
3423
|
////////////////////////////////////////////////////////////////////////////////
|
|
3442
3424
|
|
|
3443
3425
|
inline CallbackInfo::CallbackInfo(napi_env env, napi_callback_info info)
|
|
3444
|
-
: _env(env),
|
|
3426
|
+
: _env(env),
|
|
3427
|
+
_info(info),
|
|
3428
|
+
_this(nullptr),
|
|
3429
|
+
_dynamicArgs(nullptr),
|
|
3430
|
+
_data(nullptr) {
|
|
3445
3431
|
_argc = _staticArgCount;
|
|
3446
3432
|
_argv = _staticArgs;
|
|
3447
|
-
napi_status status =
|
|
3433
|
+
napi_status status =
|
|
3434
|
+
napi_get_cb_info(env, info, &_argc, _argv, &_this, &_data);
|
|
3448
3435
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
3449
3436
|
|
|
3450
3437
|
if (_argc > _staticArgCount) {
|
|
@@ -3464,6 +3451,10 @@ inline CallbackInfo::~CallbackInfo() {
|
|
|
3464
3451
|
}
|
|
3465
3452
|
}
|
|
3466
3453
|
|
|
3454
|
+
inline CallbackInfo::operator napi_callback_info() const {
|
|
3455
|
+
return _info;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3467
3458
|
inline Value CallbackInfo::NewTarget() const {
|
|
3468
3459
|
napi_value newTarget;
|
|
3469
3460
|
napi_status status = napi_get_new_target(_env, _info, &newTarget);
|
|
@@ -3483,7 +3474,7 @@ inline size_t CallbackInfo::Length() const {
|
|
|
3483
3474
|
return _argc;
|
|
3484
3475
|
}
|
|
3485
3476
|
|
|
3486
|
-
inline const Value CallbackInfo::operator
|
|
3477
|
+
inline const Value CallbackInfo::operator[](size_t index) const {
|
|
3487
3478
|
return index < _argc ? Value(_env, _argv[index]) : Env().Undefined();
|
|
3488
3479
|
}
|
|
3489
3480
|
|
|
@@ -3507,10 +3498,8 @@ inline void CallbackInfo::SetData(void* data) {
|
|
|
3507
3498
|
////////////////////////////////////////////////////////////////////////////////
|
|
3508
3499
|
|
|
3509
3500
|
template <typename PropertyDescriptor::GetterCallback Getter>
|
|
3510
|
-
PropertyDescriptor
|
|
3511
|
-
|
|
3512
|
-
napi_property_attributes attributes,
|
|
3513
|
-
void* data) {
|
|
3501
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3502
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
3514
3503
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3515
3504
|
|
|
3516
3505
|
desc.utf8name = utf8name;
|
|
@@ -3522,18 +3511,16 @@ PropertyDescriptor::Accessor(const char* utf8name,
|
|
|
3522
3511
|
}
|
|
3523
3512
|
|
|
3524
3513
|
template <typename PropertyDescriptor::GetterCallback Getter>
|
|
3525
|
-
PropertyDescriptor
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3514
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3515
|
+
const std::string& utf8name,
|
|
3516
|
+
napi_property_attributes attributes,
|
|
3517
|
+
void* data) {
|
|
3529
3518
|
return Accessor<Getter>(utf8name.c_str(), attributes, data);
|
|
3530
3519
|
}
|
|
3531
3520
|
|
|
3532
3521
|
template <typename PropertyDescriptor::GetterCallback Getter>
|
|
3533
|
-
PropertyDescriptor
|
|
3534
|
-
|
|
3535
|
-
napi_property_attributes attributes,
|
|
3536
|
-
void* data) {
|
|
3522
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3523
|
+
Name name, napi_property_attributes attributes, void* data) {
|
|
3537
3524
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3538
3525
|
|
|
3539
3526
|
desc.name = name;
|
|
@@ -3544,14 +3531,10 @@ PropertyDescriptor::Accessor(Name name,
|
|
|
3544
3531
|
return desc;
|
|
3545
3532
|
}
|
|
3546
3533
|
|
|
3547
|
-
template <
|
|
3548
|
-
typename PropertyDescriptor::
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
PropertyDescriptor::Accessor(const char* utf8name,
|
|
3552
|
-
napi_property_attributes attributes,
|
|
3553
|
-
void* data) {
|
|
3554
|
-
|
|
3534
|
+
template <typename PropertyDescriptor::GetterCallback Getter,
|
|
3535
|
+
typename PropertyDescriptor::SetterCallback Setter>
|
|
3536
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3537
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
3555
3538
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3556
3539
|
|
|
3557
3540
|
desc.utf8name = utf8name;
|
|
@@ -3563,23 +3546,19 @@ PropertyDescriptor::Accessor(const char* utf8name,
|
|
|
3563
3546
|
return desc;
|
|
3564
3547
|
}
|
|
3565
3548
|
|
|
3566
|
-
template <
|
|
3567
|
-
typename PropertyDescriptor::
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
void* data) {
|
|
3549
|
+
template <typename PropertyDescriptor::GetterCallback Getter,
|
|
3550
|
+
typename PropertyDescriptor::SetterCallback Setter>
|
|
3551
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3552
|
+
const std::string& utf8name,
|
|
3553
|
+
napi_property_attributes attributes,
|
|
3554
|
+
void* data) {
|
|
3573
3555
|
return Accessor<Getter, Setter>(utf8name.c_str(), attributes, data);
|
|
3574
3556
|
}
|
|
3575
3557
|
|
|
3576
|
-
template <
|
|
3577
|
-
typename PropertyDescriptor::
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
PropertyDescriptor::Accessor(Name name,
|
|
3581
|
-
napi_property_attributes attributes,
|
|
3582
|
-
void* data) {
|
|
3558
|
+
template <typename PropertyDescriptor::GetterCallback Getter,
|
|
3559
|
+
typename PropertyDescriptor::SetterCallback Setter>
|
|
3560
|
+
PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3561
|
+
Name name, napi_property_attributes attributes, void* data) {
|
|
3583
3562
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3584
3563
|
|
|
3585
3564
|
desc.name = name;
|
|
@@ -3592,15 +3571,15 @@ PropertyDescriptor::Accessor(Name name,
|
|
|
3592
3571
|
}
|
|
3593
3572
|
|
|
3594
3573
|
template <typename Getter>
|
|
3595
|
-
inline PropertyDescriptor
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3574
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3575
|
+
Napi::Env env,
|
|
3576
|
+
Napi::Object object,
|
|
3577
|
+
const char* utf8name,
|
|
3578
|
+
Getter getter,
|
|
3579
|
+
napi_property_attributes attributes,
|
|
3580
|
+
void* data) {
|
|
3602
3581
|
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
3603
|
-
auto callbackData = new CbData({
|
|
3582
|
+
auto callbackData = new CbData({getter, data});
|
|
3604
3583
|
|
|
3605
3584
|
napi_status status = AttachData(env, object, callbackData);
|
|
3606
3585
|
if (status != napi_ok) {
|
|
@@ -3608,37 +3587,37 @@ PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
3608
3587
|
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
3609
3588
|
}
|
|
3610
3589
|
|
|
3611
|
-
return PropertyDescriptor({
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
callbackData
|
|
3620
|
-
});
|
|
3590
|
+
return PropertyDescriptor({utf8name,
|
|
3591
|
+
nullptr,
|
|
3592
|
+
nullptr,
|
|
3593
|
+
CbData::Wrapper,
|
|
3594
|
+
nullptr,
|
|
3595
|
+
nullptr,
|
|
3596
|
+
attributes,
|
|
3597
|
+
callbackData});
|
|
3621
3598
|
}
|
|
3622
3599
|
|
|
3623
3600
|
template <typename Getter>
|
|
3624
|
-
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3601
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3602
|
+
Napi::Env env,
|
|
3603
|
+
Napi::Object object,
|
|
3604
|
+
const std::string& utf8name,
|
|
3605
|
+
Getter getter,
|
|
3606
|
+
napi_property_attributes attributes,
|
|
3607
|
+
void* data) {
|
|
3630
3608
|
return Accessor(env, object, utf8name.c_str(), getter, attributes, data);
|
|
3631
3609
|
}
|
|
3632
3610
|
|
|
3633
3611
|
template <typename Getter>
|
|
3634
|
-
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3612
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3613
|
+
Napi::Env env,
|
|
3614
|
+
Napi::Object object,
|
|
3615
|
+
Name name,
|
|
3616
|
+
Getter getter,
|
|
3617
|
+
napi_property_attributes attributes,
|
|
3618
|
+
void* data) {
|
|
3640
3619
|
using CbData = details::CallbackData<Getter, Napi::Value>;
|
|
3641
|
-
auto callbackData = new CbData({
|
|
3620
|
+
auto callbackData = new CbData({getter, data});
|
|
3642
3621
|
|
|
3643
3622
|
napi_status status = AttachData(env, object, callbackData);
|
|
3644
3623
|
if (status != napi_ok) {
|
|
@@ -3646,28 +3625,27 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
3646
3625
|
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
3647
3626
|
}
|
|
3648
3627
|
|
|
3649
|
-
return PropertyDescriptor({
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
callbackData
|
|
3658
|
-
});
|
|
3628
|
+
return PropertyDescriptor({nullptr,
|
|
3629
|
+
name,
|
|
3630
|
+
nullptr,
|
|
3631
|
+
CbData::Wrapper,
|
|
3632
|
+
nullptr,
|
|
3633
|
+
nullptr,
|
|
3634
|
+
attributes,
|
|
3635
|
+
callbackData});
|
|
3659
3636
|
}
|
|
3660
3637
|
|
|
3661
3638
|
template <typename Getter, typename Setter>
|
|
3662
|
-
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3639
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3640
|
+
Napi::Env env,
|
|
3641
|
+
Napi::Object object,
|
|
3642
|
+
const char* utf8name,
|
|
3643
|
+
Getter getter,
|
|
3644
|
+
Setter setter,
|
|
3645
|
+
napi_property_attributes attributes,
|
|
3646
|
+
void* data) {
|
|
3669
3647
|
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
3670
|
-
auto callbackData = new CbData({
|
|
3648
|
+
auto callbackData = new CbData({getter, setter, data});
|
|
3671
3649
|
|
|
3672
3650
|
napi_status status = AttachData(env, object, callbackData);
|
|
3673
3651
|
if (status != napi_ok) {
|
|
@@ -3675,39 +3653,40 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
3675
3653
|
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
3676
3654
|
}
|
|
3677
3655
|
|
|
3678
|
-
return PropertyDescriptor({
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
callbackData
|
|
3687
|
-
});
|
|
3656
|
+
return PropertyDescriptor({utf8name,
|
|
3657
|
+
nullptr,
|
|
3658
|
+
nullptr,
|
|
3659
|
+
CbData::GetterWrapper,
|
|
3660
|
+
CbData::SetterWrapper,
|
|
3661
|
+
nullptr,
|
|
3662
|
+
attributes,
|
|
3663
|
+
callbackData});
|
|
3688
3664
|
}
|
|
3689
3665
|
|
|
3690
3666
|
template <typename Getter, typename Setter>
|
|
3691
|
-
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3667
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3668
|
+
Napi::Env env,
|
|
3669
|
+
Napi::Object object,
|
|
3670
|
+
const std::string& utf8name,
|
|
3671
|
+
Getter getter,
|
|
3672
|
+
Setter setter,
|
|
3673
|
+
napi_property_attributes attributes,
|
|
3674
|
+
void* data) {
|
|
3675
|
+
return Accessor(
|
|
3676
|
+
env, object, utf8name.c_str(), getter, setter, attributes, data);
|
|
3699
3677
|
}
|
|
3700
3678
|
|
|
3701
3679
|
template <typename Getter, typename Setter>
|
|
3702
|
-
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3680
|
+
inline PropertyDescriptor PropertyDescriptor::Accessor(
|
|
3681
|
+
Napi::Env env,
|
|
3682
|
+
Napi::Object object,
|
|
3683
|
+
Name name,
|
|
3684
|
+
Getter getter,
|
|
3685
|
+
Setter setter,
|
|
3686
|
+
napi_property_attributes attributes,
|
|
3687
|
+
void* data) {
|
|
3709
3688
|
using CbData = details::AccessorCallbackData<Getter, Setter>;
|
|
3710
|
-
auto callbackData = new CbData({
|
|
3689
|
+
auto callbackData = new CbData({getter, setter, data});
|
|
3711
3690
|
|
|
3712
3691
|
napi_status status = AttachData(env, object, callbackData);
|
|
3713
3692
|
if (status != napi_ok) {
|
|
@@ -3715,99 +3694,99 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
|
|
|
3715
3694
|
NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
|
|
3716
3695
|
}
|
|
3717
3696
|
|
|
3718
|
-
return PropertyDescriptor({
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
callbackData
|
|
3727
|
-
});
|
|
3697
|
+
return PropertyDescriptor({nullptr,
|
|
3698
|
+
name,
|
|
3699
|
+
nullptr,
|
|
3700
|
+
CbData::GetterWrapper,
|
|
3701
|
+
CbData::SetterWrapper,
|
|
3702
|
+
nullptr,
|
|
3703
|
+
attributes,
|
|
3704
|
+
callbackData});
|
|
3728
3705
|
}
|
|
3729
3706
|
|
|
3730
3707
|
template <typename Callable>
|
|
3731
|
-
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
});
|
|
3708
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3709
|
+
Napi::Env env,
|
|
3710
|
+
Napi::Object /*object*/,
|
|
3711
|
+
const char* utf8name,
|
|
3712
|
+
Callable cb,
|
|
3713
|
+
napi_property_attributes attributes,
|
|
3714
|
+
void* data) {
|
|
3715
|
+
return PropertyDescriptor({utf8name,
|
|
3716
|
+
nullptr,
|
|
3717
|
+
nullptr,
|
|
3718
|
+
nullptr,
|
|
3719
|
+
nullptr,
|
|
3720
|
+
Napi::Function::New(env, cb, utf8name, data),
|
|
3721
|
+
attributes,
|
|
3722
|
+
nullptr});
|
|
3747
3723
|
}
|
|
3748
3724
|
|
|
3749
3725
|
template <typename Callable>
|
|
3750
|
-
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3726
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3727
|
+
Napi::Env env,
|
|
3728
|
+
Napi::Object object,
|
|
3729
|
+
const std::string& utf8name,
|
|
3730
|
+
Callable cb,
|
|
3731
|
+
napi_property_attributes attributes,
|
|
3732
|
+
void* data) {
|
|
3756
3733
|
return Function(env, object, utf8name.c_str(), cb, attributes, data);
|
|
3757
3734
|
}
|
|
3758
3735
|
|
|
3759
3736
|
template <typename Callable>
|
|
3760
|
-
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
});
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
inline PropertyDescriptor PropertyDescriptor::Value(const char* utf8name,
|
|
3779
|
-
napi_value value,
|
|
3780
|
-
napi_property_attributes attributes) {
|
|
3781
|
-
return PropertyDescriptor({
|
|
3782
|
-
utf8name, nullptr, nullptr, nullptr, nullptr, value, attributes, nullptr
|
|
3783
|
-
});
|
|
3737
|
+
inline PropertyDescriptor PropertyDescriptor::Function(
|
|
3738
|
+
Napi::Env env,
|
|
3739
|
+
Napi::Object /*object*/,
|
|
3740
|
+
Name name,
|
|
3741
|
+
Callable cb,
|
|
3742
|
+
napi_property_attributes attributes,
|
|
3743
|
+
void* data) {
|
|
3744
|
+
return PropertyDescriptor({nullptr,
|
|
3745
|
+
name,
|
|
3746
|
+
nullptr,
|
|
3747
|
+
nullptr,
|
|
3748
|
+
nullptr,
|
|
3749
|
+
Napi::Function::New(env, cb, nullptr, data),
|
|
3750
|
+
attributes,
|
|
3751
|
+
nullptr});
|
|
3784
3752
|
}
|
|
3785
3753
|
|
|
3786
|
-
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3787
|
-
|
|
3788
|
-
|
|
3754
|
+
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3755
|
+
const char* utf8name,
|
|
3756
|
+
napi_value value,
|
|
3757
|
+
napi_property_attributes attributes) {
|
|
3758
|
+
return PropertyDescriptor({utf8name,
|
|
3759
|
+
nullptr,
|
|
3760
|
+
nullptr,
|
|
3761
|
+
nullptr,
|
|
3762
|
+
nullptr,
|
|
3763
|
+
value,
|
|
3764
|
+
attributes,
|
|
3765
|
+
nullptr});
|
|
3766
|
+
}
|
|
3767
|
+
|
|
3768
|
+
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3769
|
+
const std::string& utf8name,
|
|
3770
|
+
napi_value value,
|
|
3771
|
+
napi_property_attributes attributes) {
|
|
3789
3772
|
return Value(utf8name.c_str(), value, attributes);
|
|
3790
3773
|
}
|
|
3791
3774
|
|
|
3792
|
-
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
nullptr, name, nullptr, nullptr, nullptr, value, attributes, nullptr
|
|
3797
|
-
});
|
|
3775
|
+
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3776
|
+
napi_value name, napi_value value, napi_property_attributes attributes) {
|
|
3777
|
+
return PropertyDescriptor(
|
|
3778
|
+
{nullptr, name, nullptr, nullptr, nullptr, value, attributes, nullptr});
|
|
3798
3779
|
}
|
|
3799
3780
|
|
|
3800
|
-
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3801
|
-
|
|
3802
|
-
napi_property_attributes attributes) {
|
|
3781
|
+
inline PropertyDescriptor PropertyDescriptor::Value(
|
|
3782
|
+
Name name, Napi::Value value, napi_property_attributes attributes) {
|
|
3803
3783
|
napi_value nameValue = name;
|
|
3804
3784
|
napi_value valueValue = value;
|
|
3805
3785
|
return PropertyDescriptor::Value(nameValue, valueValue, attributes);
|
|
3806
3786
|
}
|
|
3807
3787
|
|
|
3808
3788
|
inline PropertyDescriptor::PropertyDescriptor(napi_property_descriptor desc)
|
|
3809
|
-
|
|
3810
|
-
}
|
|
3789
|
+
: _desc(desc) {}
|
|
3811
3790
|
|
|
3812
3791
|
inline PropertyDescriptor::operator napi_property_descriptor&() {
|
|
3813
3792
|
return _desc;
|
|
@@ -3822,26 +3801,22 @@ inline PropertyDescriptor::operator const napi_property_descriptor&() const {
|
|
|
3822
3801
|
////////////////////////////////////////////////////////////////////////////////
|
|
3823
3802
|
|
|
3824
3803
|
template <typename T>
|
|
3825
|
-
inline void InstanceWrap<T>::AttachPropData(
|
|
3826
|
-
|
|
3827
|
-
const napi_property_descriptor* prop) {
|
|
3804
|
+
inline void InstanceWrap<T>::AttachPropData(
|
|
3805
|
+
napi_env env, napi_value value, const napi_property_descriptor* prop) {
|
|
3828
3806
|
napi_status status;
|
|
3829
3807
|
if (!(prop->attributes & napi_static)) {
|
|
3830
3808
|
if (prop->method == T::InstanceVoidMethodCallbackWrapper) {
|
|
3831
|
-
status = Napi::details::AttachData(
|
|
3832
|
-
|
|
3833
|
-
static_cast<InstanceVoidMethodCallbackData*>(prop->data));
|
|
3809
|
+
status = Napi::details::AttachData(
|
|
3810
|
+
env, value, static_cast<InstanceVoidMethodCallbackData*>(prop->data));
|
|
3834
3811
|
NAPI_THROW_IF_FAILED_VOID(env, status);
|
|
3835
3812
|
} else if (prop->method == T::InstanceMethodCallbackWrapper) {
|
|
3836
|
-
status = Napi::details::AttachData(
|
|
3837
|
-
|
|
3838
|
-
static_cast<InstanceMethodCallbackData*>(prop->data));
|
|
3813
|
+
status = Napi::details::AttachData(
|
|
3814
|
+
env, value, static_cast<InstanceMethodCallbackData*>(prop->data));
|
|
3839
3815
|
NAPI_THROW_IF_FAILED_VOID(env, status);
|
|
3840
3816
|
} else if (prop->getter == T::InstanceGetterCallbackWrapper ||
|
|
3841
|
-
|
|
3842
|
-
status = Napi::details::AttachData(
|
|
3843
|
-
|
|
3844
|
-
static_cast<InstanceAccessorCallbackData*>(prop->data));
|
|
3817
|
+
prop->setter == T::InstanceSetterCallbackWrapper) {
|
|
3818
|
+
status = Napi::details::AttachData(
|
|
3819
|
+
env, value, static_cast<InstanceAccessorCallbackData*>(prop->data));
|
|
3845
3820
|
NAPI_THROW_IF_FAILED_VOID(env, status);
|
|
3846
3821
|
}
|
|
3847
3822
|
}
|
|
@@ -3854,7 +3829,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3854
3829
|
napi_property_attributes attributes,
|
|
3855
3830
|
void* data) {
|
|
3856
3831
|
InstanceVoidMethodCallbackData* callbackData =
|
|
3857
|
-
|
|
3832
|
+
new InstanceVoidMethodCallbackData({method, data});
|
|
3858
3833
|
|
|
3859
3834
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3860
3835
|
desc.utf8name = utf8name;
|
|
@@ -3870,7 +3845,8 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3870
3845
|
InstanceMethodCallback method,
|
|
3871
3846
|
napi_property_attributes attributes,
|
|
3872
3847
|
void* data) {
|
|
3873
|
-
InstanceMethodCallbackData* callbackData =
|
|
3848
|
+
InstanceMethodCallbackData* callbackData =
|
|
3849
|
+
new InstanceMethodCallbackData({method, data});
|
|
3874
3850
|
|
|
3875
3851
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3876
3852
|
desc.utf8name = utf8name;
|
|
@@ -3887,7 +3863,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3887
3863
|
napi_property_attributes attributes,
|
|
3888
3864
|
void* data) {
|
|
3889
3865
|
InstanceVoidMethodCallbackData* callbackData =
|
|
3890
|
-
|
|
3866
|
+
new InstanceVoidMethodCallbackData({method, data});
|
|
3891
3867
|
|
|
3892
3868
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3893
3869
|
desc.name = name;
|
|
@@ -3903,7 +3879,8 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3903
3879
|
InstanceMethodCallback method,
|
|
3904
3880
|
napi_property_attributes attributes,
|
|
3905
3881
|
void* data) {
|
|
3906
|
-
InstanceMethodCallbackData* callbackData =
|
|
3882
|
+
InstanceMethodCallbackData* callbackData =
|
|
3883
|
+
new InstanceMethodCallbackData({method, data});
|
|
3907
3884
|
|
|
3908
3885
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3909
3886
|
desc.name = name;
|
|
@@ -3916,9 +3893,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3916
3893
|
template <typename T>
|
|
3917
3894
|
template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
|
|
3918
3895
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
3919
|
-
const char* utf8name,
|
|
3920
|
-
napi_property_attributes attributes,
|
|
3921
|
-
void* data) {
|
|
3896
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
3922
3897
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3923
3898
|
desc.utf8name = utf8name;
|
|
3924
3899
|
desc.method = details::TemplatedInstanceVoidCallback<T, method>;
|
|
@@ -3930,9 +3905,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3930
3905
|
template <typename T>
|
|
3931
3906
|
template <typename InstanceWrap<T>::InstanceMethodCallback method>
|
|
3932
3907
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
3933
|
-
const char* utf8name,
|
|
3934
|
-
napi_property_attributes attributes,
|
|
3935
|
-
void* data) {
|
|
3908
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
3936
3909
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3937
3910
|
desc.utf8name = utf8name;
|
|
3938
3911
|
desc.method = details::TemplatedInstanceCallback<T, method>;
|
|
@@ -3944,9 +3917,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3944
3917
|
template <typename T>
|
|
3945
3918
|
template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
|
|
3946
3919
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
3947
|
-
Symbol name,
|
|
3948
|
-
napi_property_attributes attributes,
|
|
3949
|
-
void* data) {
|
|
3920
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
3950
3921
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3951
3922
|
desc.name = name;
|
|
3952
3923
|
desc.method = details::TemplatedInstanceVoidCallback<T, method>;
|
|
@@ -3958,9 +3929,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
|
3958
3929
|
template <typename T>
|
|
3959
3930
|
template <typename InstanceWrap<T>::InstanceMethodCallback method>
|
|
3960
3931
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
|
|
3961
|
-
Symbol name,
|
|
3962
|
-
napi_property_attributes attributes,
|
|
3963
|
-
void* data) {
|
|
3932
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
3964
3933
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3965
3934
|
desc.name = name;
|
|
3966
3935
|
desc.method = details::TemplatedInstanceCallback<T, method>;
|
|
@@ -3977,7 +3946,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
|
|
|
3977
3946
|
napi_property_attributes attributes,
|
|
3978
3947
|
void* data) {
|
|
3979
3948
|
InstanceAccessorCallbackData* callbackData =
|
|
3980
|
-
|
|
3949
|
+
new InstanceAccessorCallbackData({getter, setter, data});
|
|
3981
3950
|
|
|
3982
3951
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
3983
3952
|
desc.utf8name = utf8name;
|
|
@@ -3996,7 +3965,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
|
|
|
3996
3965
|
napi_property_attributes attributes,
|
|
3997
3966
|
void* data) {
|
|
3998
3967
|
InstanceAccessorCallbackData* callbackData =
|
|
3999
|
-
|
|
3968
|
+
new InstanceAccessorCallbackData({getter, setter, data});
|
|
4000
3969
|
|
|
4001
3970
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4002
3971
|
desc.name = name;
|
|
@@ -4011,9 +3980,7 @@ template <typename T>
|
|
|
4011
3980
|
template <typename InstanceWrap<T>::InstanceGetterCallback getter,
|
|
4012
3981
|
typename InstanceWrap<T>::InstanceSetterCallback setter>
|
|
4013
3982
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
|
|
4014
|
-
const char* utf8name,
|
|
4015
|
-
napi_property_attributes attributes,
|
|
4016
|
-
void* data) {
|
|
3983
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
4017
3984
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4018
3985
|
desc.utf8name = utf8name;
|
|
4019
3986
|
desc.getter = details::TemplatedInstanceCallback<T, getter>;
|
|
@@ -4027,9 +3994,7 @@ template <typename T>
|
|
|
4027
3994
|
template <typename InstanceWrap<T>::InstanceGetterCallback getter,
|
|
4028
3995
|
typename InstanceWrap<T>::InstanceSetterCallback setter>
|
|
4029
3996
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
|
|
4030
|
-
Symbol name,
|
|
4031
|
-
napi_property_attributes attributes,
|
|
4032
|
-
void* data) {
|
|
3997
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
4033
3998
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4034
3999
|
desc.name = name;
|
|
4035
4000
|
desc.getter = details::TemplatedInstanceCallback<T, getter>;
|
|
@@ -4053,9 +4018,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
|
|
|
4053
4018
|
|
|
4054
4019
|
template <typename T>
|
|
4055
4020
|
inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
|
|
4056
|
-
Symbol name,
|
|
4057
|
-
Napi::Value value,
|
|
4058
|
-
napi_property_attributes attributes) {
|
|
4021
|
+
Symbol name, Napi::Value value, napi_property_attributes attributes) {
|
|
4059
4022
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4060
4023
|
desc.name = name;
|
|
4061
4024
|
desc.value = value;
|
|
@@ -4065,12 +4028,11 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
|
|
|
4065
4028
|
|
|
4066
4029
|
template <typename T>
|
|
4067
4030
|
inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
|
|
4068
|
-
napi_env env,
|
|
4069
|
-
napi_callback_info info) {
|
|
4031
|
+
napi_env env, napi_callback_info info) {
|
|
4070
4032
|
return details::WrapCallback([&] {
|
|
4071
4033
|
CallbackInfo callbackInfo(env, info);
|
|
4072
4034
|
InstanceVoidMethodCallbackData* callbackData =
|
|
4073
|
-
|
|
4035
|
+
reinterpret_cast<InstanceVoidMethodCallbackData*>(callbackInfo.Data());
|
|
4074
4036
|
callbackInfo.SetData(callbackData->data);
|
|
4075
4037
|
T* instance = T::Unwrap(callbackInfo.This().As<Object>());
|
|
4076
4038
|
auto cb = callbackData->callback;
|
|
@@ -4081,12 +4043,11 @@ inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
|
|
|
4081
4043
|
|
|
4082
4044
|
template <typename T>
|
|
4083
4045
|
inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
|
|
4084
|
-
napi_env env,
|
|
4085
|
-
napi_callback_info info) {
|
|
4046
|
+
napi_env env, napi_callback_info info) {
|
|
4086
4047
|
return details::WrapCallback([&] {
|
|
4087
4048
|
CallbackInfo callbackInfo(env, info);
|
|
4088
4049
|
InstanceMethodCallbackData* callbackData =
|
|
4089
|
-
|
|
4050
|
+
reinterpret_cast<InstanceMethodCallbackData*>(callbackInfo.Data());
|
|
4090
4051
|
callbackInfo.SetData(callbackData->data);
|
|
4091
4052
|
T* instance = T::Unwrap(callbackInfo.This().As<Object>());
|
|
4092
4053
|
auto cb = callbackData->callback;
|
|
@@ -4096,12 +4057,11 @@ inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
|
|
|
4096
4057
|
|
|
4097
4058
|
template <typename T>
|
|
4098
4059
|
inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
|
|
4099
|
-
napi_env env,
|
|
4100
|
-
napi_callback_info info) {
|
|
4060
|
+
napi_env env, napi_callback_info info) {
|
|
4101
4061
|
return details::WrapCallback([&] {
|
|
4102
4062
|
CallbackInfo callbackInfo(env, info);
|
|
4103
4063
|
InstanceAccessorCallbackData* callbackData =
|
|
4104
|
-
|
|
4064
|
+
reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
|
|
4105
4065
|
callbackInfo.SetData(callbackData->data);
|
|
4106
4066
|
T* instance = T::Unwrap(callbackInfo.This().As<Object>());
|
|
4107
4067
|
auto cb = callbackData->getterCallback;
|
|
@@ -4111,12 +4071,11 @@ inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
|
|
|
4111
4071
|
|
|
4112
4072
|
template <typename T>
|
|
4113
4073
|
inline napi_value InstanceWrap<T>::InstanceSetterCallbackWrapper(
|
|
4114
|
-
napi_env env,
|
|
4115
|
-
napi_callback_info info) {
|
|
4074
|
+
napi_env env, napi_callback_info info) {
|
|
4116
4075
|
return details::WrapCallback([&] {
|
|
4117
4076
|
CallbackInfo callbackInfo(env, info);
|
|
4118
4077
|
InstanceAccessorCallbackData* callbackData =
|
|
4119
|
-
|
|
4078
|
+
reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
|
|
4120
4079
|
callbackInfo.SetData(callbackData->data);
|
|
4121
4080
|
T* instance = T::Unwrap(callbackInfo.This().As<Object>());
|
|
4122
4081
|
auto cb = callbackData->setterCallback;
|
|
@@ -4169,7 +4128,7 @@ inline ObjectWrap<T>::~ObjectWrap() {
|
|
|
4169
4128
|
}
|
|
4170
4129
|
}
|
|
4171
4130
|
|
|
4172
|
-
template<typename T>
|
|
4131
|
+
template <typename T>
|
|
4173
4132
|
inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
|
|
4174
4133
|
void* unwrapped;
|
|
4175
4134
|
napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
|
|
@@ -4178,12 +4137,12 @@ inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
|
|
|
4178
4137
|
}
|
|
4179
4138
|
|
|
4180
4139
|
template <typename T>
|
|
4181
|
-
inline Function
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4140
|
+
inline Function ObjectWrap<T>::DefineClass(
|
|
4141
|
+
Napi::Env env,
|
|
4142
|
+
const char* utf8name,
|
|
4143
|
+
const size_t props_count,
|
|
4144
|
+
const napi_property_descriptor* descriptors,
|
|
4145
|
+
void* data) {
|
|
4187
4146
|
napi_status status;
|
|
4188
4147
|
std::vector<napi_property_descriptor> props(props_count);
|
|
4189
4148
|
|
|
@@ -4199,16 +4158,18 @@ ObjectWrap<T>::DefineClass(Napi::Env env,
|
|
|
4199
4158
|
props[index] = descriptors[index];
|
|
4200
4159
|
napi_property_descriptor* prop = &props[index];
|
|
4201
4160
|
if (prop->method == T::StaticMethodCallbackWrapper) {
|
|
4202
|
-
status =
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4161
|
+
status =
|
|
4162
|
+
CreateFunction(env,
|
|
4163
|
+
utf8name,
|
|
4164
|
+
prop->method,
|
|
4165
|
+
static_cast<StaticMethodCallbackData*>(prop->data),
|
|
4166
|
+
&(prop->value));
|
|
4207
4167
|
NAPI_THROW_IF_FAILED(env, status, Function());
|
|
4208
4168
|
prop->method = nullptr;
|
|
4209
4169
|
prop->data = nullptr;
|
|
4210
4170
|
} else if (prop->method == T::StaticVoidMethodCallbackWrapper) {
|
|
4211
|
-
status =
|
|
4171
|
+
status =
|
|
4172
|
+
CreateFunction(env,
|
|
4212
4173
|
utf8name,
|
|
4213
4174
|
prop->method,
|
|
4214
4175
|
static_cast<StaticVoidMethodCallbackData*>(prop->data),
|
|
@@ -4238,9 +4199,8 @@ ObjectWrap<T>::DefineClass(Napi::Env env,
|
|
|
4238
4199
|
|
|
4239
4200
|
if (prop->getter == T::StaticGetterCallbackWrapper ||
|
|
4240
4201
|
prop->setter == T::StaticSetterCallbackWrapper) {
|
|
4241
|
-
status = Napi::details::AttachData(
|
|
4242
|
-
|
|
4243
|
-
static_cast<StaticAccessorCallbackData*>(prop->data));
|
|
4202
|
+
status = Napi::details::AttachData(
|
|
4203
|
+
env, value, static_cast<StaticAccessorCallbackData*>(prop->data));
|
|
4244
4204
|
NAPI_THROW_IF_FAILED(env, status, Function());
|
|
4245
4205
|
} else {
|
|
4246
4206
|
// InstanceWrap<T>::AttachPropData is responsible for attaching the data
|
|
@@ -4258,11 +4218,12 @@ inline Function ObjectWrap<T>::DefineClass(
|
|
|
4258
4218
|
const char* utf8name,
|
|
4259
4219
|
const std::initializer_list<ClassPropertyDescriptor<T>>& properties,
|
|
4260
4220
|
void* data) {
|
|
4261
|
-
return DefineClass(
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4221
|
+
return DefineClass(
|
|
4222
|
+
env,
|
|
4223
|
+
utf8name,
|
|
4224
|
+
properties.size(),
|
|
4225
|
+
reinterpret_cast<const napi_property_descriptor*>(properties.begin()),
|
|
4226
|
+
data);
|
|
4266
4227
|
}
|
|
4267
4228
|
|
|
4268
4229
|
template <typename T>
|
|
@@ -4271,11 +4232,12 @@ inline Function ObjectWrap<T>::DefineClass(
|
|
|
4271
4232
|
const char* utf8name,
|
|
4272
4233
|
const std::vector<ClassPropertyDescriptor<T>>& properties,
|
|
4273
4234
|
void* data) {
|
|
4274
|
-
return DefineClass(
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4235
|
+
return DefineClass(
|
|
4236
|
+
env,
|
|
4237
|
+
utf8name,
|
|
4238
|
+
properties.size(),
|
|
4239
|
+
reinterpret_cast<const napi_property_descriptor*>(properties.data()),
|
|
4240
|
+
data);
|
|
4279
4241
|
}
|
|
4280
4242
|
|
|
4281
4243
|
template <typename T>
|
|
@@ -4284,13 +4246,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
|
4284
4246
|
StaticVoidMethodCallback method,
|
|
4285
4247
|
napi_property_attributes attributes,
|
|
4286
4248
|
void* data) {
|
|
4287
|
-
StaticVoidMethodCallbackData* callbackData =
|
|
4249
|
+
StaticVoidMethodCallbackData* callbackData =
|
|
4250
|
+
new StaticVoidMethodCallbackData({method, data});
|
|
4288
4251
|
|
|
4289
4252
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4290
4253
|
desc.utf8name = utf8name;
|
|
4291
4254
|
desc.method = T::StaticVoidMethodCallbackWrapper;
|
|
4292
4255
|
desc.data = callbackData;
|
|
4293
|
-
desc.attributes =
|
|
4256
|
+
desc.attributes =
|
|
4257
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4294
4258
|
return desc;
|
|
4295
4259
|
}
|
|
4296
4260
|
|
|
@@ -4300,13 +4264,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
|
4300
4264
|
StaticMethodCallback method,
|
|
4301
4265
|
napi_property_attributes attributes,
|
|
4302
4266
|
void* data) {
|
|
4303
|
-
StaticMethodCallbackData* callbackData =
|
|
4267
|
+
StaticMethodCallbackData* callbackData =
|
|
4268
|
+
new StaticMethodCallbackData({method, data});
|
|
4304
4269
|
|
|
4305
4270
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4306
4271
|
desc.utf8name = utf8name;
|
|
4307
4272
|
desc.method = T::StaticMethodCallbackWrapper;
|
|
4308
4273
|
desc.data = callbackData;
|
|
4309
|
-
desc.attributes =
|
|
4274
|
+
desc.attributes =
|
|
4275
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4310
4276
|
return desc;
|
|
4311
4277
|
}
|
|
4312
4278
|
|
|
@@ -4316,13 +4282,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
|
4316
4282
|
StaticVoidMethodCallback method,
|
|
4317
4283
|
napi_property_attributes attributes,
|
|
4318
4284
|
void* data) {
|
|
4319
|
-
StaticVoidMethodCallbackData* callbackData =
|
|
4285
|
+
StaticVoidMethodCallbackData* callbackData =
|
|
4286
|
+
new StaticVoidMethodCallbackData({method, data});
|
|
4320
4287
|
|
|
4321
4288
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4322
4289
|
desc.name = name;
|
|
4323
4290
|
desc.method = T::StaticVoidMethodCallbackWrapper;
|
|
4324
4291
|
desc.data = callbackData;
|
|
4325
|
-
desc.attributes =
|
|
4292
|
+
desc.attributes =
|
|
4293
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4326
4294
|
return desc;
|
|
4327
4295
|
}
|
|
4328
4296
|
|
|
@@ -4332,69 +4300,67 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
|
4332
4300
|
StaticMethodCallback method,
|
|
4333
4301
|
napi_property_attributes attributes,
|
|
4334
4302
|
void* data) {
|
|
4335
|
-
StaticMethodCallbackData* callbackData =
|
|
4303
|
+
StaticMethodCallbackData* callbackData =
|
|
4304
|
+
new StaticMethodCallbackData({method, data});
|
|
4336
4305
|
|
|
4337
4306
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4338
4307
|
desc.name = name;
|
|
4339
4308
|
desc.method = T::StaticMethodCallbackWrapper;
|
|
4340
4309
|
desc.data = callbackData;
|
|
4341
|
-
desc.attributes =
|
|
4310
|
+
desc.attributes =
|
|
4311
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4342
4312
|
return desc;
|
|
4343
4313
|
}
|
|
4344
4314
|
|
|
4345
4315
|
template <typename T>
|
|
4346
4316
|
template <typename ObjectWrap<T>::StaticVoidMethodCallback method>
|
|
4347
4317
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
4348
|
-
const char* utf8name,
|
|
4349
|
-
napi_property_attributes attributes,
|
|
4350
|
-
void* data) {
|
|
4318
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
4351
4319
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4352
4320
|
desc.utf8name = utf8name;
|
|
4353
4321
|
desc.method = details::TemplatedVoidCallback<method>;
|
|
4354
4322
|
desc.data = data;
|
|
4355
|
-
desc.attributes =
|
|
4323
|
+
desc.attributes =
|
|
4324
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4356
4325
|
return desc;
|
|
4357
4326
|
}
|
|
4358
4327
|
|
|
4359
4328
|
template <typename T>
|
|
4360
4329
|
template <typename ObjectWrap<T>::StaticVoidMethodCallback method>
|
|
4361
4330
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
4362
|
-
Symbol name,
|
|
4363
|
-
napi_property_attributes attributes,
|
|
4364
|
-
void* data) {
|
|
4331
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
4365
4332
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4366
4333
|
desc.name = name;
|
|
4367
4334
|
desc.method = details::TemplatedVoidCallback<method>;
|
|
4368
4335
|
desc.data = data;
|
|
4369
|
-
desc.attributes =
|
|
4336
|
+
desc.attributes =
|
|
4337
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4370
4338
|
return desc;
|
|
4371
4339
|
}
|
|
4372
4340
|
|
|
4373
4341
|
template <typename T>
|
|
4374
4342
|
template <typename ObjectWrap<T>::StaticMethodCallback method>
|
|
4375
4343
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
4376
|
-
const char* utf8name,
|
|
4377
|
-
napi_property_attributes attributes,
|
|
4378
|
-
void* data) {
|
|
4344
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
4379
4345
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4380
4346
|
desc.utf8name = utf8name;
|
|
4381
4347
|
desc.method = details::TemplatedCallback<method>;
|
|
4382
4348
|
desc.data = data;
|
|
4383
|
-
desc.attributes =
|
|
4349
|
+
desc.attributes =
|
|
4350
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4384
4351
|
return desc;
|
|
4385
4352
|
}
|
|
4386
4353
|
|
|
4387
4354
|
template <typename T>
|
|
4388
4355
|
template <typename ObjectWrap<T>::StaticMethodCallback method>
|
|
4389
4356
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
|
|
4390
|
-
Symbol name,
|
|
4391
|
-
napi_property_attributes attributes,
|
|
4392
|
-
void* data) {
|
|
4357
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
4393
4358
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4394
4359
|
desc.name = name;
|
|
4395
4360
|
desc.method = details::TemplatedCallback<method>;
|
|
4396
4361
|
desc.data = data;
|
|
4397
|
-
desc.attributes =
|
|
4362
|
+
desc.attributes =
|
|
4363
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4398
4364
|
return desc;
|
|
4399
4365
|
}
|
|
4400
4366
|
|
|
@@ -4406,14 +4372,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
|
|
|
4406
4372
|
napi_property_attributes attributes,
|
|
4407
4373
|
void* data) {
|
|
4408
4374
|
StaticAccessorCallbackData* callbackData =
|
|
4409
|
-
|
|
4375
|
+
new StaticAccessorCallbackData({getter, setter, data});
|
|
4410
4376
|
|
|
4411
4377
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4412
4378
|
desc.utf8name = utf8name;
|
|
4413
4379
|
desc.getter = getter != nullptr ? T::StaticGetterCallbackWrapper : nullptr;
|
|
4414
4380
|
desc.setter = setter != nullptr ? T::StaticSetterCallbackWrapper : nullptr;
|
|
4415
4381
|
desc.data = callbackData;
|
|
4416
|
-
desc.attributes =
|
|
4382
|
+
desc.attributes =
|
|
4383
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4417
4384
|
return desc;
|
|
4418
4385
|
}
|
|
4419
4386
|
|
|
@@ -4425,14 +4392,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
|
|
|
4425
4392
|
napi_property_attributes attributes,
|
|
4426
4393
|
void* data) {
|
|
4427
4394
|
StaticAccessorCallbackData* callbackData =
|
|
4428
|
-
|
|
4395
|
+
new StaticAccessorCallbackData({getter, setter, data});
|
|
4429
4396
|
|
|
4430
4397
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4431
4398
|
desc.name = name;
|
|
4432
4399
|
desc.getter = getter != nullptr ? T::StaticGetterCallbackWrapper : nullptr;
|
|
4433
4400
|
desc.setter = setter != nullptr ? T::StaticSetterCallbackWrapper : nullptr;
|
|
4434
4401
|
desc.data = callbackData;
|
|
4435
|
-
desc.attributes =
|
|
4402
|
+
desc.attributes =
|
|
4403
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4436
4404
|
return desc;
|
|
4437
4405
|
}
|
|
4438
4406
|
|
|
@@ -4440,15 +4408,14 @@ template <typename T>
|
|
|
4440
4408
|
template <typename ObjectWrap<T>::StaticGetterCallback getter,
|
|
4441
4409
|
typename ObjectWrap<T>::StaticSetterCallback setter>
|
|
4442
4410
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
|
|
4443
|
-
const char* utf8name,
|
|
4444
|
-
napi_property_attributes attributes,
|
|
4445
|
-
void* data) {
|
|
4411
|
+
const char* utf8name, napi_property_attributes attributes, void* data) {
|
|
4446
4412
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4447
4413
|
desc.utf8name = utf8name;
|
|
4448
4414
|
desc.getter = details::TemplatedCallback<getter>;
|
|
4449
4415
|
desc.setter = This::WrapStaticSetter(This::StaticSetterTag<setter>());
|
|
4450
4416
|
desc.data = data;
|
|
4451
|
-
desc.attributes =
|
|
4417
|
+
desc.attributes =
|
|
4418
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4452
4419
|
return desc;
|
|
4453
4420
|
}
|
|
4454
4421
|
|
|
@@ -4456,35 +4423,38 @@ template <typename T>
|
|
|
4456
4423
|
template <typename ObjectWrap<T>::StaticGetterCallback getter,
|
|
4457
4424
|
typename ObjectWrap<T>::StaticSetterCallback setter>
|
|
4458
4425
|
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
|
|
4459
|
-
Symbol name,
|
|
4460
|
-
napi_property_attributes attributes,
|
|
4461
|
-
void* data) {
|
|
4426
|
+
Symbol name, napi_property_attributes attributes, void* data) {
|
|
4462
4427
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4463
4428
|
desc.name = name;
|
|
4464
4429
|
desc.getter = details::TemplatedCallback<getter>;
|
|
4465
4430
|
desc.setter = This::WrapStaticSetter(This::StaticSetterTag<setter>());
|
|
4466
4431
|
desc.data = data;
|
|
4467
|
-
desc.attributes =
|
|
4432
|
+
desc.attributes =
|
|
4433
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4468
4434
|
return desc;
|
|
4469
4435
|
}
|
|
4470
4436
|
|
|
4471
4437
|
template <typename T>
|
|
4472
|
-
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
|
|
4473
|
-
|
|
4438
|
+
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
|
|
4439
|
+
const char* utf8name,
|
|
4440
|
+
Napi::Value value,
|
|
4441
|
+
napi_property_attributes attributes) {
|
|
4474
4442
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4475
4443
|
desc.utf8name = utf8name;
|
|
4476
4444
|
desc.value = value;
|
|
4477
|
-
desc.attributes =
|
|
4445
|
+
desc.attributes =
|
|
4446
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4478
4447
|
return desc;
|
|
4479
4448
|
}
|
|
4480
4449
|
|
|
4481
4450
|
template <typename T>
|
|
4482
|
-
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
|
|
4483
|
-
Napi::Value value, napi_property_attributes attributes) {
|
|
4451
|
+
inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
|
|
4452
|
+
Symbol name, Napi::Value value, napi_property_attributes attributes) {
|
|
4484
4453
|
napi_property_descriptor desc = napi_property_descriptor();
|
|
4485
4454
|
desc.name = name;
|
|
4486
4455
|
desc.value = value;
|
|
4487
|
-
desc.attributes =
|
|
4456
|
+
desc.attributes =
|
|
4457
|
+
static_cast<napi_property_attributes>(attributes | napi_static);
|
|
4488
4458
|
return desc;
|
|
4489
4459
|
}
|
|
4490
4460
|
|
|
@@ -4502,8 +4472,7 @@ inline void ObjectWrap<T>::Finalize(Napi::Env /*env*/) {}
|
|
|
4502
4472
|
|
|
4503
4473
|
template <typename T>
|
|
4504
4474
|
inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
4505
|
-
napi_env env,
|
|
4506
|
-
napi_callback_info info) {
|
|
4475
|
+
napi_env env, napi_callback_info info) {
|
|
4507
4476
|
napi_value new_target;
|
|
4508
4477
|
napi_status status = napi_get_new_target(env, info, &new_target);
|
|
4509
4478
|
if (status != napi_ok) return nullptr;
|
|
@@ -4528,7 +4497,7 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4528
4497
|
} else {
|
|
4529
4498
|
instance->_construction_failed = false;
|
|
4530
4499
|
}
|
|
4531
|
-
#
|
|
4500
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
4532
4501
|
return callbackInfo.This();
|
|
4533
4502
|
});
|
|
4534
4503
|
|
|
@@ -4537,12 +4506,11 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
|
|
|
4537
4506
|
|
|
4538
4507
|
template <typename T>
|
|
4539
4508
|
inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
|
|
4540
|
-
napi_env env,
|
|
4541
|
-
napi_callback_info info) {
|
|
4509
|
+
napi_env env, napi_callback_info info) {
|
|
4542
4510
|
return details::WrapCallback([&] {
|
|
4543
4511
|
CallbackInfo callbackInfo(env, info);
|
|
4544
4512
|
StaticVoidMethodCallbackData* callbackData =
|
|
4545
|
-
|
|
4513
|
+
reinterpret_cast<StaticVoidMethodCallbackData*>(callbackInfo.Data());
|
|
4546
4514
|
callbackInfo.SetData(callbackData->data);
|
|
4547
4515
|
callbackData->callback(callbackInfo);
|
|
4548
4516
|
return nullptr;
|
|
@@ -4551,12 +4519,11 @@ inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
|
|
|
4551
4519
|
|
|
4552
4520
|
template <typename T>
|
|
4553
4521
|
inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
|
|
4554
|
-
napi_env env,
|
|
4555
|
-
napi_callback_info info) {
|
|
4522
|
+
napi_env env, napi_callback_info info) {
|
|
4556
4523
|
return details::WrapCallback([&] {
|
|
4557
4524
|
CallbackInfo callbackInfo(env, info);
|
|
4558
4525
|
StaticMethodCallbackData* callbackData =
|
|
4559
|
-
|
|
4526
|
+
reinterpret_cast<StaticMethodCallbackData*>(callbackInfo.Data());
|
|
4560
4527
|
callbackInfo.SetData(callbackData->data);
|
|
4561
4528
|
return callbackData->callback(callbackInfo);
|
|
4562
4529
|
});
|
|
@@ -4564,12 +4531,11 @@ inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
|
|
|
4564
4531
|
|
|
4565
4532
|
template <typename T>
|
|
4566
4533
|
inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
|
|
4567
|
-
napi_env env,
|
|
4568
|
-
napi_callback_info info) {
|
|
4534
|
+
napi_env env, napi_callback_info info) {
|
|
4569
4535
|
return details::WrapCallback([&] {
|
|
4570
4536
|
CallbackInfo callbackInfo(env, info);
|
|
4571
4537
|
StaticAccessorCallbackData* callbackData =
|
|
4572
|
-
|
|
4538
|
+
reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
|
|
4573
4539
|
callbackInfo.SetData(callbackData->data);
|
|
4574
4540
|
return callbackData->getterCallback(callbackInfo);
|
|
4575
4541
|
});
|
|
@@ -4577,12 +4543,11 @@ inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
|
|
|
4577
4543
|
|
|
4578
4544
|
template <typename T>
|
|
4579
4545
|
inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
|
|
4580
|
-
napi_env env,
|
|
4581
|
-
napi_callback_info info) {
|
|
4546
|
+
napi_env env, napi_callback_info info) {
|
|
4582
4547
|
return details::WrapCallback([&] {
|
|
4583
4548
|
CallbackInfo callbackInfo(env, info);
|
|
4584
4549
|
StaticAccessorCallbackData* callbackData =
|
|
4585
|
-
|
|
4550
|
+
reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
|
|
4586
4551
|
callbackInfo.SetData(callbackData->data);
|
|
4587
4552
|
callbackData->setterCallback(callbackInfo, callbackInfo[0]);
|
|
4588
4553
|
return nullptr;
|
|
@@ -4590,7 +4555,9 @@ inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
|
|
|
4590
4555
|
}
|
|
4591
4556
|
|
|
4592
4557
|
template <typename T>
|
|
4593
|
-
inline void ObjectWrap<T>::FinalizeCallback(napi_env env,
|
|
4558
|
+
inline void ObjectWrap<T>::FinalizeCallback(napi_env env,
|
|
4559
|
+
void* data,
|
|
4560
|
+
void* /*hint*/) {
|
|
4594
4561
|
HandleScope scope(env);
|
|
4595
4562
|
T* instance = static_cast<T*>(data);
|
|
4596
4563
|
instance->Finalize(Napi::Env(env));
|
|
@@ -4613,8 +4580,7 @@ inline napi_value ObjectWrap<T>::WrappedMethod(
|
|
|
4613
4580
|
////////////////////////////////////////////////////////////////////////////////
|
|
4614
4581
|
|
|
4615
4582
|
inline HandleScope::HandleScope(napi_env env, napi_handle_scope scope)
|
|
4616
|
-
: _env(env), _scope(scope) {
|
|
4617
|
-
}
|
|
4583
|
+
: _env(env), _scope(scope) {}
|
|
4618
4584
|
|
|
4619
4585
|
inline HandleScope::HandleScope(Napi::Env env) : _env(env) {
|
|
4620
4586
|
napi_status status = napi_open_handle_scope(_env, &_scope);
|
|
@@ -4623,9 +4589,8 @@ inline HandleScope::HandleScope(Napi::Env env) : _env(env) {
|
|
|
4623
4589
|
|
|
4624
4590
|
inline HandleScope::~HandleScope() {
|
|
4625
4591
|
napi_status status = napi_close_handle_scope(_env, _scope);
|
|
4626
|
-
NAPI_FATAL_IF_FAILED(
|
|
4627
|
-
|
|
4628
|
-
"napi_close_handle_scope");
|
|
4592
|
+
NAPI_FATAL_IF_FAILED(
|
|
4593
|
+
status, "HandleScope::~HandleScope", "napi_close_handle_scope");
|
|
4629
4594
|
}
|
|
4630
4595
|
|
|
4631
4596
|
inline HandleScope::operator napi_handle_scope() const {
|
|
@@ -4641,8 +4606,8 @@ inline Napi::Env HandleScope::Env() const {
|
|
|
4641
4606
|
////////////////////////////////////////////////////////////////////////////////
|
|
4642
4607
|
|
|
4643
4608
|
inline EscapableHandleScope::EscapableHandleScope(
|
|
4644
|
-
|
|
4645
|
-
}
|
|
4609
|
+
napi_env env, napi_escapable_handle_scope scope)
|
|
4610
|
+
: _env(env), _scope(scope) {}
|
|
4646
4611
|
|
|
4647
4612
|
inline EscapableHandleScope::EscapableHandleScope(Napi::Env env) : _env(env) {
|
|
4648
4613
|
napi_status status = napi_open_escapable_handle_scope(_env, &_scope);
|
|
@@ -4671,28 +4636,25 @@ inline Value EscapableHandleScope::Escape(napi_value escapee) {
|
|
|
4671
4636
|
return Value(_env, result);
|
|
4672
4637
|
}
|
|
4673
4638
|
|
|
4674
|
-
|
|
4675
4639
|
#if (NAPI_VERSION > 2)
|
|
4676
4640
|
////////////////////////////////////////////////////////////////////////////////
|
|
4677
4641
|
// CallbackScope class
|
|
4678
4642
|
////////////////////////////////////////////////////////////////////////////////
|
|
4679
4643
|
|
|
4680
|
-
inline CallbackScope::CallbackScope(
|
|
4681
|
-
|
|
4682
|
-
}
|
|
4644
|
+
inline CallbackScope::CallbackScope(napi_env env, napi_callback_scope scope)
|
|
4645
|
+
: _env(env), _scope(scope) {}
|
|
4683
4646
|
|
|
4684
4647
|
inline CallbackScope::CallbackScope(napi_env env, napi_async_context context)
|
|
4685
4648
|
: _env(env) {
|
|
4686
|
-
napi_status status =
|
|
4687
|
-
_env, Object::New(env), context, &_scope);
|
|
4649
|
+
napi_status status =
|
|
4650
|
+
napi_open_callback_scope(_env, Object::New(env), context, &_scope);
|
|
4688
4651
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
4689
4652
|
}
|
|
4690
4653
|
|
|
4691
4654
|
inline CallbackScope::~CallbackScope() {
|
|
4692
4655
|
napi_status status = napi_close_callback_scope(_env, _scope);
|
|
4693
|
-
NAPI_FATAL_IF_FAILED(
|
|
4694
|
-
|
|
4695
|
-
"napi_close_callback_scope");
|
|
4656
|
+
NAPI_FATAL_IF_FAILED(
|
|
4657
|
+
status, "CallbackScope::~CallbackScope", "napi_close_callback_scope");
|
|
4696
4658
|
}
|
|
4697
4659
|
|
|
4698
4660
|
inline CallbackScope::operator napi_callback_scope() const {
|
|
@@ -4709,8 +4671,7 @@ inline Napi::Env CallbackScope::Env() const {
|
|
|
4709
4671
|
////////////////////////////////////////////////////////////////////////////////
|
|
4710
4672
|
|
|
4711
4673
|
inline AsyncContext::AsyncContext(napi_env env, const char* resource_name)
|
|
4712
|
-
|
|
4713
|
-
}
|
|
4674
|
+
: AsyncContext(env, resource_name, Object::New(env)) {}
|
|
4714
4675
|
|
|
4715
4676
|
inline AsyncContext::AsyncContext(napi_env env,
|
|
4716
4677
|
const char* resource_name,
|
|
@@ -4739,7 +4700,7 @@ inline AsyncContext::AsyncContext(AsyncContext&& other) {
|
|
|
4739
4700
|
other._context = nullptr;
|
|
4740
4701
|
}
|
|
4741
4702
|
|
|
4742
|
-
inline AsyncContext& AsyncContext::operator
|
|
4703
|
+
inline AsyncContext& AsyncContext::operator=(AsyncContext&& other) {
|
|
4743
4704
|
_env = other._env;
|
|
4744
4705
|
other._env = nullptr;
|
|
4745
4706
|
_context = other._context;
|
|
@@ -4760,78 +4721,72 @@ inline Napi::Env AsyncContext::Env() const {
|
|
|
4760
4721
|
////////////////////////////////////////////////////////////////////////////////
|
|
4761
4722
|
|
|
4762
4723
|
inline AsyncWorker::AsyncWorker(const Function& callback)
|
|
4763
|
-
|
|
4764
|
-
}
|
|
4724
|
+
: AsyncWorker(callback, "generic") {}
|
|
4765
4725
|
|
|
4766
4726
|
inline AsyncWorker::AsyncWorker(const Function& callback,
|
|
4767
4727
|
const char* resource_name)
|
|
4768
|
-
|
|
4769
|
-
}
|
|
4728
|
+
: AsyncWorker(callback, resource_name, Object::New(callback.Env())) {}
|
|
4770
4729
|
|
|
4771
4730
|
inline AsyncWorker::AsyncWorker(const Function& callback,
|
|
4772
4731
|
const char* resource_name,
|
|
4773
4732
|
const Object& resource)
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
resource_name,
|
|
4777
|
-
resource) {
|
|
4778
|
-
}
|
|
4733
|
+
: AsyncWorker(
|
|
4734
|
+
Object::New(callback.Env()), callback, resource_name, resource) {}
|
|
4779
4735
|
|
|
4780
4736
|
inline AsyncWorker::AsyncWorker(const Object& receiver,
|
|
4781
4737
|
const Function& callback)
|
|
4782
|
-
|
|
4783
|
-
}
|
|
4738
|
+
: AsyncWorker(receiver, callback, "generic") {}
|
|
4784
4739
|
|
|
4785
4740
|
inline AsyncWorker::AsyncWorker(const Object& receiver,
|
|
4786
4741
|
const Function& callback,
|
|
4787
4742
|
const char* resource_name)
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
resource_name,
|
|
4791
|
-
Object::New(callback.Env())) {
|
|
4792
|
-
}
|
|
4743
|
+
: AsyncWorker(
|
|
4744
|
+
receiver, callback, resource_name, Object::New(callback.Env())) {}
|
|
4793
4745
|
|
|
4794
4746
|
inline AsyncWorker::AsyncWorker(const Object& receiver,
|
|
4795
4747
|
const Function& callback,
|
|
4796
4748
|
const char* resource_name,
|
|
4797
4749
|
const Object& resource)
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4750
|
+
: _env(callback.Env()),
|
|
4751
|
+
_receiver(Napi::Persistent(receiver)),
|
|
4752
|
+
_callback(Napi::Persistent(callback)),
|
|
4753
|
+
_suppress_destruct(false) {
|
|
4802
4754
|
napi_value resource_id;
|
|
4803
4755
|
napi_status status = napi_create_string_latin1(
|
|
4804
4756
|
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
|
|
4805
4757
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
4806
4758
|
|
|
4807
|
-
status = napi_create_async_work(_env,
|
|
4808
|
-
|
|
4759
|
+
status = napi_create_async_work(_env,
|
|
4760
|
+
resource,
|
|
4761
|
+
resource_id,
|
|
4762
|
+
OnAsyncWorkExecute,
|
|
4763
|
+
OnAsyncWorkComplete,
|
|
4764
|
+
this,
|
|
4765
|
+
&_work);
|
|
4809
4766
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
4810
4767
|
}
|
|
4811
4768
|
|
|
4812
|
-
inline AsyncWorker::AsyncWorker(Napi::Env env)
|
|
4813
|
-
: AsyncWorker(env, "generic") {
|
|
4814
|
-
}
|
|
4769
|
+
inline AsyncWorker::AsyncWorker(Napi::Env env) : AsyncWorker(env, "generic") {}
|
|
4815
4770
|
|
|
4816
|
-
inline AsyncWorker::AsyncWorker(Napi::Env env,
|
|
4817
|
-
|
|
4818
|
-
: AsyncWorker(env, resource_name, Object::New(env)) {
|
|
4819
|
-
}
|
|
4771
|
+
inline AsyncWorker::AsyncWorker(Napi::Env env, const char* resource_name)
|
|
4772
|
+
: AsyncWorker(env, resource_name, Object::New(env)) {}
|
|
4820
4773
|
|
|
4821
4774
|
inline AsyncWorker::AsyncWorker(Napi::Env env,
|
|
4822
4775
|
const char* resource_name,
|
|
4823
4776
|
const Object& resource)
|
|
4824
|
-
|
|
4825
|
-
_receiver(),
|
|
4826
|
-
_callback(),
|
|
4827
|
-
_suppress_destruct(false) {
|
|
4777
|
+
: _env(env), _receiver(), _callback(), _suppress_destruct(false) {
|
|
4828
4778
|
napi_value resource_id;
|
|
4829
4779
|
napi_status status = napi_create_string_latin1(
|
|
4830
4780
|
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
|
|
4831
4781
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
4832
4782
|
|
|
4833
|
-
status = napi_create_async_work(_env,
|
|
4834
|
-
|
|
4783
|
+
status = napi_create_async_work(_env,
|
|
4784
|
+
resource,
|
|
4785
|
+
resource_id,
|
|
4786
|
+
OnAsyncWorkExecute,
|
|
4787
|
+
OnAsyncWorkComplete,
|
|
4788
|
+
this,
|
|
4789
|
+
&_work);
|
|
4835
4790
|
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
4836
4791
|
}
|
|
4837
4792
|
|
|
@@ -4857,7 +4812,7 @@ inline AsyncWorker::AsyncWorker(AsyncWorker&& other) {
|
|
|
4857
4812
|
_suppress_destruct = other._suppress_destruct;
|
|
4858
4813
|
}
|
|
4859
4814
|
|
|
4860
|
-
inline AsyncWorker& AsyncWorker::operator
|
|
4815
|
+
inline AsyncWorker& AsyncWorker::operator=(AsyncWorker&& other) {
|
|
4861
4816
|
_env = other._env;
|
|
4862
4817
|
other._env = nullptr;
|
|
4863
4818
|
_work = other._work;
|
|
@@ -4907,7 +4862,8 @@ inline void AsyncWorker::OnOK() {
|
|
|
4907
4862
|
|
|
4908
4863
|
inline void AsyncWorker::OnError(const Error& e) {
|
|
4909
4864
|
if (!_callback.IsEmpty()) {
|
|
4910
|
-
_callback.Call(_receiver.Value(),
|
|
4865
|
+
_callback.Call(_receiver.Value(),
|
|
4866
|
+
std::initializer_list<napi_value>{e.Value()});
|
|
4911
4867
|
}
|
|
4912
4868
|
}
|
|
4913
4869
|
|
|
@@ -4937,9 +4893,9 @@ inline void AsyncWorker::OnExecute(Napi::Env /*DO_NOT_USE*/) {
|
|
|
4937
4893
|
} catch (const std::exception& e) {
|
|
4938
4894
|
SetError(e.what());
|
|
4939
4895
|
}
|
|
4940
|
-
#else
|
|
4896
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
4941
4897
|
Execute();
|
|
4942
|
-
#endif
|
|
4898
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
4943
4899
|
}
|
|
4944
4900
|
|
|
4945
4901
|
inline void AsyncWorker::OnAsyncWorkComplete(napi_env env,
|
|
@@ -4954,8 +4910,7 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) {
|
|
|
4954
4910
|
details::WrapCallback([&] {
|
|
4955
4911
|
if (_error.size() == 0) {
|
|
4956
4912
|
OnOK();
|
|
4957
|
-
}
|
|
4958
|
-
else {
|
|
4913
|
+
} else {
|
|
4959
4914
|
OnError(Error::New(_env, _error));
|
|
4960
4915
|
}
|
|
4961
4916
|
return nullptr;
|
|
@@ -5458,68 +5413,93 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::FunctionOrEmpty(
|
|
|
5458
5413
|
// static
|
|
5459
5414
|
template <typename ResourceString>
|
|
5460
5415
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
return New(
|
|
5466
|
-
|
|
5416
|
+
const Function& callback,
|
|
5417
|
+
ResourceString resourceName,
|
|
5418
|
+
size_t maxQueueSize,
|
|
5419
|
+
size_t initialThreadCount) {
|
|
5420
|
+
return New(
|
|
5421
|
+
env, callback, Object(), resourceName, maxQueueSize, initialThreadCount);
|
|
5467
5422
|
}
|
|
5468
5423
|
|
|
5469
5424
|
// static
|
|
5470
5425
|
template <typename ResourceString, typename ContextType>
|
|
5471
5426
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
return New(env,
|
|
5478
|
-
|
|
5427
|
+
const Function& callback,
|
|
5428
|
+
ResourceString resourceName,
|
|
5429
|
+
size_t maxQueueSize,
|
|
5430
|
+
size_t initialThreadCount,
|
|
5431
|
+
ContextType* context) {
|
|
5432
|
+
return New(env,
|
|
5433
|
+
callback,
|
|
5434
|
+
Object(),
|
|
5435
|
+
resourceName,
|
|
5436
|
+
maxQueueSize,
|
|
5437
|
+
initialThreadCount,
|
|
5438
|
+
context);
|
|
5479
5439
|
}
|
|
5480
5440
|
|
|
5481
5441
|
// static
|
|
5482
5442
|
template <typename ResourceString, typename Finalizer>
|
|
5483
5443
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
return New(env,
|
|
5490
|
-
|
|
5444
|
+
const Function& callback,
|
|
5445
|
+
ResourceString resourceName,
|
|
5446
|
+
size_t maxQueueSize,
|
|
5447
|
+
size_t initialThreadCount,
|
|
5448
|
+
Finalizer finalizeCallback) {
|
|
5449
|
+
return New(env,
|
|
5450
|
+
callback,
|
|
5451
|
+
Object(),
|
|
5452
|
+
resourceName,
|
|
5453
|
+
maxQueueSize,
|
|
5454
|
+
initialThreadCount,
|
|
5455
|
+
finalizeCallback);
|
|
5491
5456
|
}
|
|
5492
5457
|
|
|
5493
5458
|
// static
|
|
5494
|
-
template <typename ResourceString,
|
|
5459
|
+
template <typename ResourceString,
|
|
5460
|
+
typename Finalizer,
|
|
5495
5461
|
typename FinalizerDataType>
|
|
5496
5462
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
return New(env,
|
|
5504
|
-
|
|
5463
|
+
const Function& callback,
|
|
5464
|
+
ResourceString resourceName,
|
|
5465
|
+
size_t maxQueueSize,
|
|
5466
|
+
size_t initialThreadCount,
|
|
5467
|
+
Finalizer finalizeCallback,
|
|
5468
|
+
FinalizerDataType* data) {
|
|
5469
|
+
return New(env,
|
|
5470
|
+
callback,
|
|
5471
|
+
Object(),
|
|
5472
|
+
resourceName,
|
|
5473
|
+
maxQueueSize,
|
|
5474
|
+
initialThreadCount,
|
|
5475
|
+
finalizeCallback,
|
|
5476
|
+
data);
|
|
5505
5477
|
}
|
|
5506
5478
|
|
|
5507
5479
|
// static
|
|
5508
5480
|
template <typename ResourceString, typename ContextType, typename Finalizer>
|
|
5509
5481
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
return New(env,
|
|
5517
|
-
|
|
5482
|
+
const Function& callback,
|
|
5483
|
+
ResourceString resourceName,
|
|
5484
|
+
size_t maxQueueSize,
|
|
5485
|
+
size_t initialThreadCount,
|
|
5486
|
+
ContextType* context,
|
|
5487
|
+
Finalizer finalizeCallback) {
|
|
5488
|
+
return New(env,
|
|
5489
|
+
callback,
|
|
5490
|
+
Object(),
|
|
5491
|
+
resourceName,
|
|
5492
|
+
maxQueueSize,
|
|
5493
|
+
initialThreadCount,
|
|
5494
|
+
context,
|
|
5495
|
+
finalizeCallback);
|
|
5518
5496
|
}
|
|
5519
5497
|
|
|
5520
5498
|
// static
|
|
5521
|
-
template <typename ResourceString,
|
|
5522
|
-
typename
|
|
5499
|
+
template <typename ResourceString,
|
|
5500
|
+
typename ContextType,
|
|
5501
|
+
typename Finalizer,
|
|
5502
|
+
typename FinalizerDataType>
|
|
5523
5503
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5524
5504
|
const Function& callback,
|
|
5525
5505
|
ResourceString resourceName,
|
|
@@ -5528,89 +5508,128 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
|
5528
5508
|
ContextType* context,
|
|
5529
5509
|
Finalizer finalizeCallback,
|
|
5530
5510
|
FinalizerDataType* data) {
|
|
5531
|
-
return New(env,
|
|
5532
|
-
|
|
5511
|
+
return New(env,
|
|
5512
|
+
callback,
|
|
5513
|
+
Object(),
|
|
5514
|
+
resourceName,
|
|
5515
|
+
maxQueueSize,
|
|
5516
|
+
initialThreadCount,
|
|
5517
|
+
context,
|
|
5518
|
+
finalizeCallback,
|
|
5519
|
+
data);
|
|
5533
5520
|
}
|
|
5534
5521
|
|
|
5535
5522
|
// static
|
|
5536
5523
|
template <typename ResourceString>
|
|
5537
5524
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
return New(env,
|
|
5544
|
-
|
|
5525
|
+
const Function& callback,
|
|
5526
|
+
const Object& resource,
|
|
5527
|
+
ResourceString resourceName,
|
|
5528
|
+
size_t maxQueueSize,
|
|
5529
|
+
size_t initialThreadCount) {
|
|
5530
|
+
return New(env,
|
|
5531
|
+
callback,
|
|
5532
|
+
resource,
|
|
5533
|
+
resourceName,
|
|
5534
|
+
maxQueueSize,
|
|
5535
|
+
initialThreadCount,
|
|
5536
|
+
static_cast<void*>(nullptr) /* context */);
|
|
5545
5537
|
}
|
|
5546
5538
|
|
|
5547
5539
|
// static
|
|
5548
5540
|
template <typename ResourceString, typename ContextType>
|
|
5549
5541
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
return New(env,
|
|
5557
|
-
|
|
5542
|
+
const Function& callback,
|
|
5543
|
+
const Object& resource,
|
|
5544
|
+
ResourceString resourceName,
|
|
5545
|
+
size_t maxQueueSize,
|
|
5546
|
+
size_t initialThreadCount,
|
|
5547
|
+
ContextType* context) {
|
|
5548
|
+
return New(env,
|
|
5549
|
+
callback,
|
|
5550
|
+
resource,
|
|
5551
|
+
resourceName,
|
|
5552
|
+
maxQueueSize,
|
|
5553
|
+
initialThreadCount,
|
|
5554
|
+
context,
|
|
5558
5555
|
[](Env, ContextType*) {} /* empty finalizer */);
|
|
5559
5556
|
}
|
|
5560
5557
|
|
|
5561
5558
|
// static
|
|
5562
5559
|
template <typename ResourceString, typename Finalizer>
|
|
5563
5560
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
return New(env,
|
|
5571
|
-
|
|
5572
|
-
|
|
5561
|
+
const Function& callback,
|
|
5562
|
+
const Object& resource,
|
|
5563
|
+
ResourceString resourceName,
|
|
5564
|
+
size_t maxQueueSize,
|
|
5565
|
+
size_t initialThreadCount,
|
|
5566
|
+
Finalizer finalizeCallback) {
|
|
5567
|
+
return New(env,
|
|
5568
|
+
callback,
|
|
5569
|
+
resource,
|
|
5570
|
+
resourceName,
|
|
5571
|
+
maxQueueSize,
|
|
5572
|
+
initialThreadCount,
|
|
5573
|
+
static_cast<void*>(nullptr) /* context */,
|
|
5574
|
+
finalizeCallback,
|
|
5575
|
+
static_cast<void*>(nullptr) /* data */,
|
|
5573
5576
|
details::ThreadSafeFinalize<void, Finalizer>::Wrapper);
|
|
5574
5577
|
}
|
|
5575
5578
|
|
|
5576
5579
|
// static
|
|
5577
|
-
template <typename ResourceString,
|
|
5580
|
+
template <typename ResourceString,
|
|
5581
|
+
typename Finalizer,
|
|
5578
5582
|
typename FinalizerDataType>
|
|
5579
5583
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
return New(env,
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5584
|
+
const Function& callback,
|
|
5585
|
+
const Object& resource,
|
|
5586
|
+
ResourceString resourceName,
|
|
5587
|
+
size_t maxQueueSize,
|
|
5588
|
+
size_t initialThreadCount,
|
|
5589
|
+
Finalizer finalizeCallback,
|
|
5590
|
+
FinalizerDataType* data) {
|
|
5591
|
+
return New(env,
|
|
5592
|
+
callback,
|
|
5593
|
+
resource,
|
|
5594
|
+
resourceName,
|
|
5595
|
+
maxQueueSize,
|
|
5596
|
+
initialThreadCount,
|
|
5597
|
+
static_cast<void*>(nullptr) /* context */,
|
|
5598
|
+
finalizeCallback,
|
|
5599
|
+
data,
|
|
5600
|
+
details::ThreadSafeFinalize<void, Finalizer, FinalizerDataType>::
|
|
5601
|
+
FinalizeWrapperWithData);
|
|
5592
5602
|
}
|
|
5593
5603
|
|
|
5594
5604
|
// static
|
|
5595
5605
|
template <typename ResourceString, typename ContextType, typename Finalizer>
|
|
5596
5606
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
return New(
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5607
|
+
const Function& callback,
|
|
5608
|
+
const Object& resource,
|
|
5609
|
+
ResourceString resourceName,
|
|
5610
|
+
size_t maxQueueSize,
|
|
5611
|
+
size_t initialThreadCount,
|
|
5612
|
+
ContextType* context,
|
|
5613
|
+
Finalizer finalizeCallback) {
|
|
5614
|
+
return New(
|
|
5615
|
+
env,
|
|
5616
|
+
callback,
|
|
5617
|
+
resource,
|
|
5618
|
+
resourceName,
|
|
5619
|
+
maxQueueSize,
|
|
5620
|
+
initialThreadCount,
|
|
5621
|
+
context,
|
|
5622
|
+
finalizeCallback,
|
|
5623
|
+
static_cast<void*>(nullptr) /* data */,
|
|
5624
|
+
details::ThreadSafeFinalize<ContextType,
|
|
5625
|
+
Finalizer>::FinalizeWrapperWithContext);
|
|
5609
5626
|
}
|
|
5610
5627
|
|
|
5611
5628
|
// static
|
|
5612
|
-
template <typename ResourceString,
|
|
5613
|
-
typename
|
|
5629
|
+
template <typename ResourceString,
|
|
5630
|
+
typename ContextType,
|
|
5631
|
+
typename Finalizer,
|
|
5632
|
+
typename FinalizerDataType>
|
|
5614
5633
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5615
5634
|
const Function& callback,
|
|
5616
5635
|
const Object& resource,
|
|
@@ -5620,20 +5639,24 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
|
5620
5639
|
ContextType* context,
|
|
5621
5640
|
Finalizer finalizeCallback,
|
|
5622
5641
|
FinalizerDataType* data) {
|
|
5623
|
-
return New(
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5642
|
+
return New(
|
|
5643
|
+
env,
|
|
5644
|
+
callback,
|
|
5645
|
+
resource,
|
|
5646
|
+
resourceName,
|
|
5647
|
+
maxQueueSize,
|
|
5648
|
+
initialThreadCount,
|
|
5649
|
+
context,
|
|
5650
|
+
finalizeCallback,
|
|
5651
|
+
data,
|
|
5652
|
+
details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
|
|
5653
|
+
FinalizeFinalizeWrapperWithDataAndContext);
|
|
5627
5654
|
}
|
|
5628
5655
|
|
|
5629
|
-
inline ThreadSafeFunction::ThreadSafeFunction()
|
|
5630
|
-
: _tsfn() {
|
|
5631
|
-
}
|
|
5656
|
+
inline ThreadSafeFunction::ThreadSafeFunction() : _tsfn() {}
|
|
5632
5657
|
|
|
5633
|
-
inline ThreadSafeFunction::ThreadSafeFunction(
|
|
5634
|
-
|
|
5635
|
-
: _tsfn(tsfn) {
|
|
5636
|
-
}
|
|
5658
|
+
inline ThreadSafeFunction::ThreadSafeFunction(napi_threadsafe_function tsfn)
|
|
5659
|
+
: _tsfn(tsfn) {}
|
|
5637
5660
|
|
|
5638
5661
|
inline ThreadSafeFunction::operator napi_threadsafe_function() const {
|
|
5639
5662
|
return _tsfn;
|
|
@@ -5644,20 +5667,18 @@ inline napi_status ThreadSafeFunction::BlockingCall() const {
|
|
|
5644
5667
|
}
|
|
5645
5668
|
|
|
5646
5669
|
template <>
|
|
5647
|
-
inline napi_status ThreadSafeFunction::BlockingCall(
|
|
5648
|
-
void* data) const {
|
|
5670
|
+
inline napi_status ThreadSafeFunction::BlockingCall(void* data) const {
|
|
5649
5671
|
return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_blocking);
|
|
5650
5672
|
}
|
|
5651
5673
|
|
|
5652
5674
|
template <typename Callback>
|
|
5653
|
-
inline napi_status ThreadSafeFunction::BlockingCall(
|
|
5654
|
-
Callback callback) const {
|
|
5675
|
+
inline napi_status ThreadSafeFunction::BlockingCall(Callback callback) const {
|
|
5655
5676
|
return CallInternal(new CallbackWrapper(callback), napi_tsfn_blocking);
|
|
5656
5677
|
}
|
|
5657
5678
|
|
|
5658
5679
|
template <typename DataType, typename Callback>
|
|
5659
|
-
inline napi_status ThreadSafeFunction::BlockingCall(
|
|
5660
|
-
|
|
5680
|
+
inline napi_status ThreadSafeFunction::BlockingCall(DataType* data,
|
|
5681
|
+
Callback callback) const {
|
|
5661
5682
|
auto wrapper = [data, callback](Env env, Function jsCallback) {
|
|
5662
5683
|
callback(env, jsCallback, data);
|
|
5663
5684
|
};
|
|
@@ -5669,8 +5690,7 @@ inline napi_status ThreadSafeFunction::NonBlockingCall() const {
|
|
|
5669
5690
|
}
|
|
5670
5691
|
|
|
5671
5692
|
template <>
|
|
5672
|
-
inline napi_status ThreadSafeFunction::NonBlockingCall(
|
|
5673
|
-
void* data) const {
|
|
5693
|
+
inline napi_status ThreadSafeFunction::NonBlockingCall(void* data) const {
|
|
5674
5694
|
return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_nonblocking);
|
|
5675
5695
|
}
|
|
5676
5696
|
|
|
@@ -5715,17 +5735,21 @@ inline napi_status ThreadSafeFunction::Abort() const {
|
|
|
5715
5735
|
return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort);
|
|
5716
5736
|
}
|
|
5717
5737
|
|
|
5718
|
-
inline ThreadSafeFunction::ConvertibleContext
|
|
5719
|
-
|
|
5738
|
+
inline ThreadSafeFunction::ConvertibleContext ThreadSafeFunction::GetContext()
|
|
5739
|
+
const {
|
|
5720
5740
|
void* context;
|
|
5721
5741
|
napi_status status = napi_get_threadsafe_function_context(_tsfn, &context);
|
|
5722
|
-
NAPI_FATAL_IF_FAILED(status,
|
|
5723
|
-
|
|
5742
|
+
NAPI_FATAL_IF_FAILED(status,
|
|
5743
|
+
"ThreadSafeFunction::GetContext",
|
|
5744
|
+
"napi_get_threadsafe_function_context");
|
|
5745
|
+
return ConvertibleContext({context});
|
|
5724
5746
|
}
|
|
5725
5747
|
|
|
5726
5748
|
// static
|
|
5727
|
-
template <typename ResourceString,
|
|
5728
|
-
typename
|
|
5749
|
+
template <typename ResourceString,
|
|
5750
|
+
typename ContextType,
|
|
5751
|
+
typename Finalizer,
|
|
5752
|
+
typename FinalizerDataType>
|
|
5729
5753
|
inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
5730
5754
|
const Function& callback,
|
|
5731
5755
|
const Object& resource,
|
|
@@ -5736,16 +5760,26 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
|
5736
5760
|
Finalizer finalizeCallback,
|
|
5737
5761
|
FinalizerDataType* data,
|
|
5738
5762
|
napi_finalize wrapper) {
|
|
5739
|
-
static_assert(details::can_make_string<ResourceString>::value
|
|
5740
|
-
|
|
5741
|
-
|
|
5763
|
+
static_assert(details::can_make_string<ResourceString>::value ||
|
|
5764
|
+
std::is_convertible<ResourceString, napi_value>::value,
|
|
5765
|
+
"Resource name should be convertible to the string type");
|
|
5742
5766
|
|
|
5743
5767
|
ThreadSafeFunction tsfn;
|
|
5744
|
-
auto* finalizeData = new details::
|
|
5745
|
-
FinalizerDataType>(
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5768
|
+
auto* finalizeData = new details::
|
|
5769
|
+
ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
|
|
5770
|
+
{data, finalizeCallback});
|
|
5771
|
+
napi_status status =
|
|
5772
|
+
napi_create_threadsafe_function(env,
|
|
5773
|
+
callback,
|
|
5774
|
+
resource,
|
|
5775
|
+
Value::From(env, resourceName),
|
|
5776
|
+
maxQueueSize,
|
|
5777
|
+
initialThreadCount,
|
|
5778
|
+
finalizeData,
|
|
5779
|
+
wrapper,
|
|
5780
|
+
context,
|
|
5781
|
+
CallJS,
|
|
5782
|
+
&tsfn._tsfn);
|
|
5749
5783
|
if (status != napi_ok) {
|
|
5750
5784
|
delete finalizeData;
|
|
5751
5785
|
NAPI_THROW_IF_FAILED(env, status, ThreadSafeFunction());
|
|
@@ -5757,8 +5791,8 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
|
|
|
5757
5791
|
inline napi_status ThreadSafeFunction::CallInternal(
|
|
5758
5792
|
CallbackWrapper* callbackWrapper,
|
|
5759
5793
|
napi_threadsafe_function_call_mode mode) const {
|
|
5760
|
-
napi_status status =
|
|
5761
|
-
_tsfn, callbackWrapper, mode);
|
|
5794
|
+
napi_status status =
|
|
5795
|
+
napi_call_threadsafe_function(_tsfn, callbackWrapper, mode);
|
|
5762
5796
|
if (status != napi_ok && callbackWrapper != nullptr) {
|
|
5763
5797
|
delete callbackWrapper;
|
|
5764
5798
|
}
|
|
@@ -5788,13 +5822,15 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
|
|
|
5788
5822
|
// Async Progress Worker Base class
|
|
5789
5823
|
////////////////////////////////////////////////////////////////////////////////
|
|
5790
5824
|
template <typename DataType>
|
|
5791
|
-
inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5825
|
+
inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
|
|
5826
|
+
const Object& receiver,
|
|
5827
|
+
const Function& callback,
|
|
5828
|
+
const char* resource_name,
|
|
5829
|
+
const Object& resource,
|
|
5830
|
+
size_t queue_size)
|
|
5831
|
+
: AsyncWorker(receiver, callback, resource_name, resource) {
|
|
5832
|
+
// Fill all possible arguments to work around ambiguous
|
|
5833
|
+
// ThreadSafeFunction::New signatures.
|
|
5798
5834
|
_tsfn = ThreadSafeFunction::New(callback.Env(),
|
|
5799
5835
|
callback,
|
|
5800
5836
|
resource,
|
|
@@ -5808,15 +5844,18 @@ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(const Object&
|
|
|
5808
5844
|
|
|
5809
5845
|
#if NAPI_VERSION > 4
|
|
5810
5846
|
template <typename DataType>
|
|
5811
|
-
inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5847
|
+
inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
|
|
5848
|
+
Napi::Env env,
|
|
5849
|
+
const char* resource_name,
|
|
5850
|
+
const Object& resource,
|
|
5851
|
+
size_t queue_size)
|
|
5852
|
+
: AsyncWorker(env, resource_name, resource) {
|
|
5816
5853
|
// TODO: Once the changes to make the callback optional for threadsafe
|
|
5817
|
-
// functions are available on all versions we can remove the dummy Function
|
|
5854
|
+
// functions are available on all versions we can remove the dummy Function
|
|
5855
|
+
// here.
|
|
5818
5856
|
Function callback;
|
|
5819
|
-
// Fill all possible arguments to work around ambiguous
|
|
5857
|
+
// Fill all possible arguments to work around ambiguous
|
|
5858
|
+
// ThreadSafeFunction::New signatures.
|
|
5820
5859
|
_tsfn = ThreadSafeFunction::New(env,
|
|
5821
5860
|
callback,
|
|
5822
5861
|
resource,
|
|
@@ -5829,38 +5868,45 @@ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(Napi::Env env,
|
|
|
5829
5868
|
}
|
|
5830
5869
|
#endif
|
|
5831
5870
|
|
|
5832
|
-
template<typename DataType>
|
|
5871
|
+
template <typename DataType>
|
|
5833
5872
|
inline AsyncProgressWorkerBase<DataType>::~AsyncProgressWorkerBase() {
|
|
5834
5873
|
// Abort pending tsfn call.
|
|
5835
5874
|
// Don't send progress events after we've already completed.
|
|
5836
|
-
// It's ok to call ThreadSafeFunction::Abort and ThreadSafeFunction::Release
|
|
5875
|
+
// It's ok to call ThreadSafeFunction::Abort and ThreadSafeFunction::Release
|
|
5876
|
+
// duplicated.
|
|
5837
5877
|
_tsfn.Abort();
|
|
5838
5878
|
}
|
|
5839
5879
|
|
|
5840
5880
|
template <typename DataType>
|
|
5841
|
-
inline void AsyncProgressWorkerBase<DataType>::OnAsyncWorkProgress(
|
|
5842
|
-
|
|
5843
|
-
void* data) {
|
|
5881
|
+
inline void AsyncProgressWorkerBase<DataType>::OnAsyncWorkProgress(
|
|
5882
|
+
Napi::Env /* env */, Napi::Function /* jsCallback */, void* data) {
|
|
5844
5883
|
ThreadSafeData* tsd = static_cast<ThreadSafeData*>(data);
|
|
5845
5884
|
tsd->asyncprogressworker()->OnWorkProgress(tsd->data());
|
|
5846
5885
|
delete tsd;
|
|
5847
5886
|
}
|
|
5848
5887
|
|
|
5849
5888
|
template <typename DataType>
|
|
5850
|
-
inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(
|
|
5889
|
+
inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(
|
|
5890
|
+
DataType* data) {
|
|
5851
5891
|
auto tsd = new AsyncProgressWorkerBase::ThreadSafeData(this, data);
|
|
5852
|
-
|
|
5892
|
+
auto ret = _tsfn.NonBlockingCall(tsd, OnAsyncWorkProgress);
|
|
5893
|
+
if (ret != napi_ok) {
|
|
5894
|
+
delete tsd;
|
|
5895
|
+
}
|
|
5896
|
+
return ret;
|
|
5853
5897
|
}
|
|
5854
5898
|
|
|
5855
5899
|
template <typename DataType>
|
|
5856
|
-
inline void AsyncProgressWorkerBase<DataType>::OnWorkComplete(
|
|
5900
|
+
inline void AsyncProgressWorkerBase<DataType>::OnWorkComplete(
|
|
5901
|
+
Napi::Env /* env */, napi_status status) {
|
|
5857
5902
|
_work_completed = true;
|
|
5858
5903
|
_complete_status = status;
|
|
5859
5904
|
_tsfn.Release();
|
|
5860
5905
|
}
|
|
5861
5906
|
|
|
5862
5907
|
template <typename DataType>
|
|
5863
|
-
inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(
|
|
5908
|
+
inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(
|
|
5909
|
+
Napi::Env env, void* /* data */, AsyncProgressWorkerBase* context) {
|
|
5864
5910
|
if (context->_work_completed) {
|
|
5865
5911
|
context->AsyncWorker::OnWorkComplete(env, context->_complete_status);
|
|
5866
5912
|
}
|
|
@@ -5869,76 +5915,65 @@ inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(Napi
|
|
|
5869
5915
|
////////////////////////////////////////////////////////////////////////////////
|
|
5870
5916
|
// Async Progress Worker class
|
|
5871
5917
|
////////////////////////////////////////////////////////////////////////////////
|
|
5872
|
-
template<class T>
|
|
5918
|
+
template <class T>
|
|
5873
5919
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback)
|
|
5874
|
-
|
|
5875
|
-
}
|
|
5920
|
+
: AsyncProgressWorker(callback, "generic") {}
|
|
5876
5921
|
|
|
5877
|
-
template<class T>
|
|
5922
|
+
template <class T>
|
|
5878
5923
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback,
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
}
|
|
5924
|
+
const char* resource_name)
|
|
5925
|
+
: AsyncProgressWorker(
|
|
5926
|
+
callback, resource_name, Object::New(callback.Env())) {}
|
|
5882
5927
|
|
|
5883
|
-
template<class T>
|
|
5928
|
+
template <class T>
|
|
5884
5929
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback,
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
resource_name,
|
|
5890
|
-
resource) {
|
|
5891
|
-
}
|
|
5930
|
+
const char* resource_name,
|
|
5931
|
+
const Object& resource)
|
|
5932
|
+
: AsyncProgressWorker(
|
|
5933
|
+
Object::New(callback.Env()), callback, resource_name, resource) {}
|
|
5892
5934
|
|
|
5893
|
-
template<class T>
|
|
5935
|
+
template <class T>
|
|
5894
5936
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
|
|
5895
5937
|
const Function& callback)
|
|
5896
|
-
|
|
5897
|
-
}
|
|
5938
|
+
: AsyncProgressWorker(receiver, callback, "generic") {}
|
|
5898
5939
|
|
|
5899
|
-
template<class T>
|
|
5940
|
+
template <class T>
|
|
5900
5941
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
|
|
5901
5942
|
const Function& callback,
|
|
5902
5943
|
const char* resource_name)
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
resource_name,
|
|
5906
|
-
Object::New(callback.Env())) {
|
|
5907
|
-
}
|
|
5944
|
+
: AsyncProgressWorker(
|
|
5945
|
+
receiver, callback, resource_name, Object::New(callback.Env())) {}
|
|
5908
5946
|
|
|
5909
|
-
template<class T>
|
|
5947
|
+
template <class T>
|
|
5910
5948
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
|
|
5911
5949
|
const Function& callback,
|
|
5912
5950
|
const char* resource_name,
|
|
5913
5951
|
const Object& resource)
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
}
|
|
5952
|
+
: AsyncProgressWorkerBase(receiver, callback, resource_name, resource),
|
|
5953
|
+
_asyncdata(nullptr),
|
|
5954
|
+
_asyncsize(0),
|
|
5955
|
+
_signaled(false) {}
|
|
5918
5956
|
|
|
5919
5957
|
#if NAPI_VERSION > 4
|
|
5920
|
-
template<class T>
|
|
5958
|
+
template <class T>
|
|
5921
5959
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env)
|
|
5922
|
-
|
|
5923
|
-
}
|
|
5960
|
+
: AsyncProgressWorker(env, "generic") {}
|
|
5924
5961
|
|
|
5925
|
-
template<class T>
|
|
5962
|
+
template <class T>
|
|
5926
5963
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
|
|
5927
5964
|
const char* resource_name)
|
|
5928
|
-
|
|
5929
|
-
}
|
|
5965
|
+
: AsyncProgressWorker(env, resource_name, Object::New(env)) {}
|
|
5930
5966
|
|
|
5931
|
-
template<class T>
|
|
5967
|
+
template <class T>
|
|
5932
5968
|
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
|
|
5933
5969
|
const char* resource_name,
|
|
5934
5970
|
const Object& resource)
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
}
|
|
5971
|
+
: AsyncProgressWorkerBase(env, resource_name, resource),
|
|
5972
|
+
_asyncdata(nullptr),
|
|
5973
|
+
_asyncsize(0) {}
|
|
5939
5974
|
#endif
|
|
5940
5975
|
|
|
5941
|
-
template<class T>
|
|
5976
|
+
template <class T>
|
|
5942
5977
|
inline AsyncProgressWorker<T>::~AsyncProgressWorker() {
|
|
5943
5978
|
{
|
|
5944
5979
|
std::lock_guard<std::mutex> lock(this->_mutex);
|
|
@@ -5947,22 +5982,25 @@ inline AsyncProgressWorker<T>::~AsyncProgressWorker() {
|
|
|
5947
5982
|
}
|
|
5948
5983
|
}
|
|
5949
5984
|
|
|
5950
|
-
template<class T>
|
|
5985
|
+
template <class T>
|
|
5951
5986
|
inline void AsyncProgressWorker<T>::Execute() {
|
|
5952
5987
|
ExecutionProgress progress(this);
|
|
5953
5988
|
Execute(progress);
|
|
5954
5989
|
}
|
|
5955
5990
|
|
|
5956
|
-
template<class T>
|
|
5991
|
+
template <class T>
|
|
5957
5992
|
inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
|
|
5958
5993
|
T* data;
|
|
5959
5994
|
size_t size;
|
|
5995
|
+
bool signaled;
|
|
5960
5996
|
{
|
|
5961
5997
|
std::lock_guard<std::mutex> lock(this->_mutex);
|
|
5962
5998
|
data = this->_asyncdata;
|
|
5963
5999
|
size = this->_asyncsize;
|
|
6000
|
+
signaled = this->_signaled;
|
|
5964
6001
|
this->_asyncdata = nullptr;
|
|
5965
6002
|
this->_asyncsize = 0;
|
|
6003
|
+
this->_signaled = false;
|
|
5966
6004
|
}
|
|
5967
6005
|
|
|
5968
6006
|
/**
|
|
@@ -5972,7 +6010,7 @@ inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
|
|
|
5972
6010
|
* the deferring the signal of uv_async_t is been sent again, i.e. potential
|
|
5973
6011
|
* not coalesced two calls of the TSFN callback.
|
|
5974
6012
|
*/
|
|
5975
|
-
if (data == nullptr) {
|
|
6013
|
+
if (data == nullptr && !signaled) {
|
|
5976
6014
|
return;
|
|
5977
6015
|
}
|
|
5978
6016
|
|
|
@@ -5980,119 +6018,119 @@ inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
|
|
|
5980
6018
|
delete[] data;
|
|
5981
6019
|
}
|
|
5982
6020
|
|
|
5983
|
-
template<class T>
|
|
6021
|
+
template <class T>
|
|
5984
6022
|
inline void AsyncProgressWorker<T>::SendProgress_(const T* data, size_t count) {
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
6023
|
+
T* new_data = new T[count];
|
|
6024
|
+
std::copy(data, data + count, new_data);
|
|
6025
|
+
|
|
6026
|
+
T* old_data;
|
|
6027
|
+
{
|
|
6028
|
+
std::lock_guard<std::mutex> lock(this->_mutex);
|
|
6029
|
+
old_data = _asyncdata;
|
|
6030
|
+
_asyncdata = new_data;
|
|
6031
|
+
_asyncsize = count;
|
|
6032
|
+
_signaled = false;
|
|
6033
|
+
}
|
|
6034
|
+
this->NonBlockingCall(nullptr);
|
|
5996
6035
|
|
|
5997
|
-
|
|
6036
|
+
delete[] old_data;
|
|
5998
6037
|
}
|
|
5999
6038
|
|
|
6000
|
-
template<class T>
|
|
6001
|
-
inline void AsyncProgressWorker<T>::Signal()
|
|
6039
|
+
template <class T>
|
|
6040
|
+
inline void AsyncProgressWorker<T>::Signal() {
|
|
6041
|
+
{
|
|
6042
|
+
std::lock_guard<std::mutex> lock(this->_mutex);
|
|
6043
|
+
_signaled = true;
|
|
6044
|
+
}
|
|
6002
6045
|
this->NonBlockingCall(static_cast<T*>(nullptr));
|
|
6003
6046
|
}
|
|
6004
6047
|
|
|
6005
|
-
template<class T>
|
|
6048
|
+
template <class T>
|
|
6006
6049
|
inline void AsyncProgressWorker<T>::ExecutionProgress::Signal() const {
|
|
6007
|
-
_worker->Signal();
|
|
6050
|
+
this->_worker->Signal();
|
|
6008
6051
|
}
|
|
6009
6052
|
|
|
6010
|
-
template<class T>
|
|
6011
|
-
inline void AsyncProgressWorker<T>::ExecutionProgress::Send(
|
|
6053
|
+
template <class T>
|
|
6054
|
+
inline void AsyncProgressWorker<T>::ExecutionProgress::Send(
|
|
6055
|
+
const T* data, size_t count) const {
|
|
6012
6056
|
_worker->SendProgress_(data, count);
|
|
6013
6057
|
}
|
|
6014
6058
|
|
|
6015
6059
|
////////////////////////////////////////////////////////////////////////////////
|
|
6016
6060
|
// Async Progress Queue Worker class
|
|
6017
6061
|
////////////////////////////////////////////////////////////////////////////////
|
|
6018
|
-
template<class T>
|
|
6019
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6020
|
-
|
|
6021
|
-
}
|
|
6062
|
+
template <class T>
|
|
6063
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6064
|
+
const Function& callback)
|
|
6065
|
+
: AsyncProgressQueueWorker(callback, "generic") {}
|
|
6022
6066
|
|
|
6023
|
-
template<class T>
|
|
6024
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
}
|
|
6067
|
+
template <class T>
|
|
6068
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6069
|
+
const Function& callback, const char* resource_name)
|
|
6070
|
+
: AsyncProgressQueueWorker(
|
|
6071
|
+
callback, resource_name, Object::New(callback.Env())) {}
|
|
6028
6072
|
|
|
6029
|
-
template<class T>
|
|
6030
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
callback,
|
|
6035
|
-
resource_name,
|
|
6036
|
-
resource) {
|
|
6037
|
-
}
|
|
6073
|
+
template <class T>
|
|
6074
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6075
|
+
const Function& callback, const char* resource_name, const Object& resource)
|
|
6076
|
+
: AsyncProgressQueueWorker(
|
|
6077
|
+
Object::New(callback.Env()), callback, resource_name, resource) {}
|
|
6038
6078
|
|
|
6039
|
-
template<class T>
|
|
6040
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
}
|
|
6079
|
+
template <class T>
|
|
6080
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6081
|
+
const Object& receiver, const Function& callback)
|
|
6082
|
+
: AsyncProgressQueueWorker(receiver, callback, "generic") {}
|
|
6044
6083
|
|
|
6045
|
-
template<class T>
|
|
6046
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
callback,
|
|
6051
|
-
resource_name,
|
|
6052
|
-
Object::New(callback.Env())) {
|
|
6053
|
-
}
|
|
6084
|
+
template <class T>
|
|
6085
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6086
|
+
const Object& receiver, const Function& callback, const char* resource_name)
|
|
6087
|
+
: AsyncProgressQueueWorker(
|
|
6088
|
+
receiver, callback, resource_name, Object::New(callback.Env())) {}
|
|
6054
6089
|
|
|
6055
|
-
template<class T>
|
|
6056
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6090
|
+
template <class T>
|
|
6091
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6092
|
+
const Object& receiver,
|
|
6093
|
+
const Function& callback,
|
|
6094
|
+
const char* resource_name,
|
|
6095
|
+
const Object& resource)
|
|
6096
|
+
: AsyncProgressWorkerBase<std::pair<T*, size_t>>(
|
|
6097
|
+
receiver,
|
|
6098
|
+
callback,
|
|
6099
|
+
resource_name,
|
|
6100
|
+
resource,
|
|
6101
|
+
/** unlimited queue size */ 0) {}
|
|
6062
6102
|
|
|
6063
6103
|
#if NAPI_VERSION > 4
|
|
6064
|
-
template<class T>
|
|
6104
|
+
template <class T>
|
|
6065
6105
|
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(Napi::Env env)
|
|
6066
|
-
|
|
6067
|
-
}
|
|
6106
|
+
: AsyncProgressQueueWorker(env, "generic") {}
|
|
6068
6107
|
|
|
6069
|
-
template<class T>
|
|
6070
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
}
|
|
6108
|
+
template <class T>
|
|
6109
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6110
|
+
Napi::Env env, const char* resource_name)
|
|
6111
|
+
: AsyncProgressQueueWorker(env, resource_name, Object::New(env)) {}
|
|
6074
6112
|
|
|
6075
|
-
template<class T>
|
|
6076
|
-
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
}
|
|
6113
|
+
template <class T>
|
|
6114
|
+
inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
|
|
6115
|
+
Napi::Env env, const char* resource_name, const Object& resource)
|
|
6116
|
+
: AsyncProgressWorkerBase<std::pair<T*, size_t>>(
|
|
6117
|
+
env, resource_name, resource, /** unlimited queue size */ 0) {}
|
|
6081
6118
|
#endif
|
|
6082
6119
|
|
|
6083
|
-
template<class T>
|
|
6120
|
+
template <class T>
|
|
6084
6121
|
inline void AsyncProgressQueueWorker<T>::Execute() {
|
|
6085
6122
|
ExecutionProgress progress(this);
|
|
6086
6123
|
Execute(progress);
|
|
6087
6124
|
}
|
|
6088
6125
|
|
|
6089
|
-
template<class T>
|
|
6090
|
-
inline void AsyncProgressQueueWorker<T>::OnWorkProgress(
|
|
6126
|
+
template <class T>
|
|
6127
|
+
inline void AsyncProgressQueueWorker<T>::OnWorkProgress(
|
|
6128
|
+
std::pair<T*, size_t>* datapair) {
|
|
6091
6129
|
if (datapair == nullptr) {
|
|
6092
6130
|
return;
|
|
6093
6131
|
}
|
|
6094
6132
|
|
|
6095
|
-
T
|
|
6133
|
+
T* data = datapair->first;
|
|
6096
6134
|
size_t size = datapair->second;
|
|
6097
6135
|
|
|
6098
6136
|
this->OnProgress(data, size);
|
|
@@ -6100,33 +6138,36 @@ inline void AsyncProgressQueueWorker<T>::OnWorkProgress(std::pair<T*, size_t>* d
|
|
|
6100
6138
|
delete[] data;
|
|
6101
6139
|
}
|
|
6102
6140
|
|
|
6103
|
-
template<class T>
|
|
6104
|
-
inline void AsyncProgressQueueWorker<T>::SendProgress_(const T* data,
|
|
6105
|
-
|
|
6106
|
-
|
|
6141
|
+
template <class T>
|
|
6142
|
+
inline void AsyncProgressQueueWorker<T>::SendProgress_(const T* data,
|
|
6143
|
+
size_t count) {
|
|
6144
|
+
T* new_data = new T[count];
|
|
6145
|
+
std::copy(data, data + count, new_data);
|
|
6107
6146
|
|
|
6108
|
-
|
|
6109
|
-
|
|
6147
|
+
auto pair = new std::pair<T*, size_t>(new_data, count);
|
|
6148
|
+
this->NonBlockingCall(pair);
|
|
6110
6149
|
}
|
|
6111
6150
|
|
|
6112
|
-
template<class T>
|
|
6151
|
+
template <class T>
|
|
6113
6152
|
inline void AsyncProgressQueueWorker<T>::Signal() const {
|
|
6114
|
-
this->
|
|
6153
|
+
this->SendProgress_(static_cast<T*>(nullptr), 0);
|
|
6115
6154
|
}
|
|
6116
6155
|
|
|
6117
|
-
template<class T>
|
|
6118
|
-
inline void AsyncProgressQueueWorker<T>::OnWorkComplete(Napi::Env env,
|
|
6156
|
+
template <class T>
|
|
6157
|
+
inline void AsyncProgressQueueWorker<T>::OnWorkComplete(Napi::Env env,
|
|
6158
|
+
napi_status status) {
|
|
6119
6159
|
// Draining queued items in TSFN.
|
|
6120
6160
|
AsyncProgressWorkerBase<std::pair<T*, size_t>>::OnWorkComplete(env, status);
|
|
6121
6161
|
}
|
|
6122
6162
|
|
|
6123
|
-
template<class T>
|
|
6163
|
+
template <class T>
|
|
6124
6164
|
inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Signal() const {
|
|
6125
|
-
_worker->
|
|
6165
|
+
_worker->SendProgress_(static_cast<T*>(nullptr), 0);
|
|
6126
6166
|
}
|
|
6127
6167
|
|
|
6128
|
-
template<class T>
|
|
6129
|
-
inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
|
|
6168
|
+
template <class T>
|
|
6169
|
+
inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
|
|
6170
|
+
const T* data, size_t count) const {
|
|
6130
6171
|
_worker->SendProgress_(data, count);
|
|
6131
6172
|
}
|
|
6132
6173
|
#endif // NAPI_VERSION > 3 && !defined(__wasm32__)
|
|
@@ -6135,9 +6176,11 @@ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(const T* data,
|
|
|
6135
6176
|
// Memory Management class
|
|
6136
6177
|
////////////////////////////////////////////////////////////////////////////////
|
|
6137
6178
|
|
|
6138
|
-
inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
|
|
6179
|
+
inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
|
|
6180
|
+
int64_t change_in_bytes) {
|
|
6139
6181
|
int64_t result;
|
|
6140
|
-
napi_status status =
|
|
6182
|
+
napi_status status =
|
|
6183
|
+
napi_adjust_external_memory(env, change_in_bytes, &result);
|
|
6141
6184
|
NAPI_THROW_IF_FAILED(env, status, 0);
|
|
6142
6185
|
return result;
|
|
6143
6186
|
}
|
|
@@ -6178,24 +6221,20 @@ inline T* Addon<T>::Unwrap(Object wrapper) {
|
|
|
6178
6221
|
}
|
|
6179
6222
|
|
|
6180
6223
|
template <typename T>
|
|
6181
|
-
inline void
|
|
6182
|
-
|
|
6183
|
-
const std::initializer_list<AddonProp>& props) {
|
|
6224
|
+
inline void Addon<T>::DefineAddon(
|
|
6225
|
+
Object exports, const std::initializer_list<AddonProp>& props) {
|
|
6184
6226
|
DefineProperties(exports, props);
|
|
6185
6227
|
entry_point_ = exports;
|
|
6186
6228
|
}
|
|
6187
6229
|
|
|
6188
6230
|
template <typename T>
|
|
6189
|
-
inline Napi::Object
|
|
6190
|
-
|
|
6191
|
-
const std::initializer_list<AddonProp>& props) {
|
|
6231
|
+
inline Napi::Object Addon<T>::DefineProperties(
|
|
6232
|
+
Object object, const std::initializer_list<AddonProp>& props) {
|
|
6192
6233
|
const napi_property_descriptor* properties =
|
|
6193
|
-
|
|
6234
|
+
reinterpret_cast<const napi_property_descriptor*>(props.begin());
|
|
6194
6235
|
size_t size = props.size();
|
|
6195
|
-
napi_status status =
|
|
6196
|
-
|
|
6197
|
-
size,
|
|
6198
|
-
properties);
|
|
6236
|
+
napi_status status =
|
|
6237
|
+
napi_define_properties(object.Env(), object, size, properties);
|
|
6199
6238
|
NAPI_THROW_IF_FAILED(object.Env(), status, object);
|
|
6200
6239
|
for (size_t idx = 0; idx < size; idx++)
|
|
6201
6240
|
T::AttachPropData(object.Env(), object, &properties[idx]);
|
|
@@ -6214,6 +6253,11 @@ Env::CleanupHook<Hook> Env::AddCleanupHook(Hook hook) {
|
|
|
6214
6253
|
return CleanupHook<Hook>(*this, hook);
|
|
6215
6254
|
}
|
|
6216
6255
|
|
|
6256
|
+
template <typename Hook, typename Arg>
|
|
6257
|
+
Env::CleanupHook<Hook, Arg>::CleanupHook() {
|
|
6258
|
+
data = nullptr;
|
|
6259
|
+
}
|
|
6260
|
+
|
|
6217
6261
|
template <typename Hook, typename Arg>
|
|
6218
6262
|
Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::Env env, Hook hook)
|
|
6219
6263
|
: wrapper(Env::CleanupHook<Hook, Arg>::Wrapper) {
|
|
@@ -6254,6 +6298,6 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
|
|
|
6254
6298
|
} // namespace NAPI_CPP_CUSTOM_NAMESPACE
|
|
6255
6299
|
#endif
|
|
6256
6300
|
|
|
6257
|
-
}
|
|
6301
|
+
} // namespace Napi
|
|
6258
6302
|
|
|
6259
|
-
#endif
|
|
6303
|
+
#endif // SRC_NAPI_INL_H_
|