@basemaps/lambda-tiler 6.38.0 → 6.40.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/build/__tests__/config.data.d.ts.map +1 -1
  3. package/build/__tests__/config.data.js +142 -1
  4. package/build/__tests__/config.data.js.map +1 -1
  5. package/build/__tests__/wmts.capability.test.js +9 -16
  6. package/build/__tests__/wmts.capability.test.js.map +1 -1
  7. package/build/__tests__/xyz.util.d.ts.map +1 -1
  8. package/build/__tests__/xyz.util.js +6 -2
  9. package/build/__tests__/xyz.util.js.map +1 -1
  10. package/build/cli/render.tile.d.ts +2 -0
  11. package/build/cli/render.tile.d.ts.map +1 -0
  12. package/build/cli/render.tile.js +33 -0
  13. package/build/cli/render.tile.js.map +1 -0
  14. package/build/routes/__tests__/attribution.test.js +63 -3
  15. package/build/routes/__tests__/attribution.test.js.map +1 -1
  16. package/build/routes/__tests__/tile.style.json.test.js +91 -43
  17. package/build/routes/__tests__/tile.style.json.test.js.map +1 -1
  18. package/build/routes/__tests__/wmts.test.js +50 -8
  19. package/build/routes/__tests__/wmts.test.js.map +1 -1
  20. package/build/routes/attribution.d.ts +12 -0
  21. package/build/routes/attribution.d.ts.map +1 -1
  22. package/build/routes/attribution.js +29 -27
  23. package/build/routes/attribution.js.map +1 -1
  24. package/build/routes/tile.json.d.ts.map +1 -1
  25. package/build/routes/tile.json.js +2 -1
  26. package/build/routes/tile.json.js.map +1 -1
  27. package/build/routes/tile.style.json.d.ts +2 -2
  28. package/build/routes/tile.style.json.d.ts.map +1 -1
  29. package/build/routes/tile.style.json.js +7 -4
  30. package/build/routes/tile.style.json.js.map +1 -1
  31. package/build/routes/tile.wmts.d.ts.map +1 -1
  32. package/build/routes/tile.wmts.js +3 -1
  33. package/build/routes/tile.wmts.js.map +1 -1
  34. package/build/routes/tile.xyz.raster.d.ts.map +1 -1
  35. package/build/routes/tile.xyz.raster.js +9 -6
  36. package/build/routes/tile.xyz.raster.js.map +1 -1
  37. package/build/util/__test__/filter.test.d.ts +2 -0
  38. package/build/util/__test__/filter.test.d.ts.map +1 -0
  39. package/build/util/__test__/filter.test.js +64 -0
  40. package/build/util/__test__/filter.test.js.map +1 -0
  41. package/build/util/config.loader.d.ts.map +1 -1
  42. package/build/util/config.loader.js +2 -3
  43. package/build/util/config.loader.js.map +1 -1
  44. package/build/util/filter.d.ts +15 -0
  45. package/build/util/filter.d.ts.map +1 -0
  46. package/build/util/filter.js +59 -0
  47. package/build/util/filter.js.map +1 -0
  48. package/build/wmts.capability.d.ts +8 -5
  49. package/build/wmts.capability.d.ts.map +1 -1
  50. package/build/wmts.capability.js +17 -15
  51. package/build/wmts.capability.js.map +1 -1
  52. package/dist/index.js +60 -60
  53. package/dist/node_modules/.package-lock.json +14 -14
  54. package/dist/node_modules/minimist/.eslintrc +25 -50
  55. package/dist/node_modules/minimist/CHANGELOG.md +87 -1
  56. package/dist/node_modules/minimist/README.md +14 -10
  57. package/dist/node_modules/minimist/example/parse.js +2 -0
  58. package/dist/node_modules/minimist/index.js +256 -242
  59. package/dist/node_modules/minimist/package.json +73 -73
  60. package/dist/node_modules/minimist/test/all_bool.js +26 -24
  61. package/dist/node_modules/minimist/test/bool.js +146 -147
  62. package/dist/node_modules/minimist/test/dash.js +33 -21
  63. package/dist/node_modules/minimist/test/default_bool.js +26 -24
  64. package/dist/node_modules/minimist/test/dotted.js +13 -11
  65. package/dist/node_modules/minimist/test/kv_short.js +26 -10
  66. package/dist/node_modules/minimist/test/long.js +28 -26
  67. package/dist/node_modules/minimist/test/num.js +30 -28
  68. package/dist/node_modules/minimist/test/parse.js +169 -157
  69. package/dist/node_modules/minimist/test/parse_modified.js +7 -5
  70. package/dist/node_modules/minimist/test/proto.js +41 -37
  71. package/dist/node_modules/minimist/test/short.js +57 -55
  72. package/dist/node_modules/minimist/test/stop_early.js +10 -8
  73. package/dist/node_modules/minimist/test/unknown.js +83 -81
  74. package/dist/node_modules/minimist/test/whitespace.js +6 -4
  75. package/dist/node_modules/node-abi/.circleci/config.yml +7 -25
  76. package/dist/node_modules/node-abi/.github/CODEOWNERS +1 -0
  77. package/dist/node_modules/node-abi/.github/workflows/update-abi.yml +5 -4
  78. package/dist/node_modules/node-abi/CONTRIBUTING.md +1 -1
  79. package/dist/node_modules/node-abi/README.md +5 -3
  80. package/dist/node_modules/node-abi/abi_registry.json +14 -0
  81. package/dist/node_modules/node-abi/package.json +5 -6
  82. package/dist/node_modules/node-addon-api/README.md +36 -12
  83. package/dist/node_modules/node-addon-api/index.js +3 -3
  84. package/dist/node_modules/node-addon-api/napi-inl.deprecated.h +121 -127
  85. package/dist/node_modules/node-addon-api/napi-inl.h +1166 -1122
  86. package/dist/node_modules/node-addon-api/napi.h +2786 -2675
  87. package/dist/node_modules/node-addon-api/package.json +42 -1
  88. package/dist/node_modules/node-addon-api/tools/check-napi.js +13 -14
  89. package/dist/node_modules/node-addon-api/tools/conversion.js +161 -169
  90. package/dist/node_modules/node-addon-api/tools/eslint-format.js +9 -1
  91. package/dist/node_modules/readable-stream/README.md +1 -1
  92. package/dist/node_modules/readable-stream/lib/_stream_duplex.js +12 -25
  93. package/dist/node_modules/readable-stream/lib/_stream_passthrough.js +2 -4
  94. package/dist/node_modules/readable-stream/lib/_stream_readable.js +176 -273
  95. package/dist/node_modules/readable-stream/lib/_stream_transform.js +26 -37
  96. package/dist/node_modules/readable-stream/lib/_stream_writable.js +118 -174
  97. package/dist/node_modules/readable-stream/lib/internal/streams/async_iterator.js +10 -37
  98. package/dist/node_modules/readable-stream/lib/internal/streams/buffer_list.js +20 -47
  99. package/dist/node_modules/readable-stream/lib/internal/streams/destroy.js +8 -17
  100. package/dist/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +1 -19
  101. package/dist/node_modules/readable-stream/lib/internal/streams/from.js +12 -24
  102. package/dist/node_modules/readable-stream/lib/internal/streams/pipeline.js +5 -16
  103. package/dist/node_modules/readable-stream/lib/internal/streams/state.js +2 -7
  104. package/dist/node_modules/readable-stream/package.json +1 -1
  105. package/dist/package-lock.json +15 -346
  106. package/dist/package.json +1 -1
  107. package/package.json +8 -8
  108. package/src/__tests__/config.data.ts +142 -1
  109. package/src/__tests__/wmts.capability.test.ts +9 -16
  110. package/src/__tests__/xyz.util.ts +6 -2
  111. package/src/cli/render.tile.ts +38 -0
  112. package/src/routes/__tests__/attribution.test.ts +65 -3
  113. package/src/routes/__tests__/tile.style.json.test.ts +100 -44
  114. package/src/routes/__tests__/wmts.test.ts +70 -9
  115. package/src/routes/attribution.ts +24 -28
  116. package/src/routes/tile.json.ts +2 -1
  117. package/src/routes/tile.style.json.ts +13 -5
  118. package/src/routes/tile.wmts.ts +3 -1
  119. package/src/routes/tile.xyz.raster.ts +10 -7
  120. package/src/util/__test__/filter.test.ts +80 -0
  121. package/src/util/config.loader.ts +1 -2
  122. package/src/util/filter.ts +60 -0
  123. package/src/wmts.capability.ts +19 -14
  124. package/tsconfig.tsbuildinfo +1 -1
  125. package/test-dump.js +0 -6
  126. package/test-imagery.js +0 -3
@@ -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
- static inline napi_status AttachData(napi_env env,
34
- napi_value obj,
35
- FreeType* data,
36
- napi_finalize finalizer = nullptr,
37
- void* hint = nullptr) {
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
- nullptr,
56
- symbol,
57
- nullptr,
58
- nullptr,
59
- nullptr,
60
- external,
61
- napi_default,
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 // NAPI_CPP_EXCEPTIONS
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 // NAPI_CPP_EXCEPTIONS
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 the
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 // NAPI_CPP_EXCEPTIONS
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 // NAPI_CPP_EXCEPTIONS
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
- static_cast<CallbackData*>(callbackInfo.Data());
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
- static_cast<CallbackData*>(callbackInfo.Data());
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
- static napi_value
146
- TemplatedVoidCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
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
- static napi_value
156
- TemplatedCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
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
- static napi_value
166
- TemplatedInstanceCallback(napi_env env, napi_callback_info info) NAPI_NOEXCEPT {
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
- static napi_value
176
- TemplatedInstanceVoidCallback(napi_env env,
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(Env(env), static_cast<T*>(data), finalizeData->hint);
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
- void Wrapper(napi_env env, void* rawFinalizeData, void* /* rawContext */) {
219
- if (rawFinalizeData == nullptr)
220
- return;
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
- void FinalizeWrapperWithData(napi_env env,
230
- void* rawFinalizeData,
231
- void* /* rawContext */) {
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
- void FinalizeWrapperWithContext(napi_env env,
243
- void* rawFinalizeData,
244
- void* rawContext) {
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
- void FinalizeFinalizeWrapperWithDataAndContext(napi_env env,
256
- void* rawFinalizeData,
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(Env(env), finalizeData->data,
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 static inline CallJsWrapper(
274
- napi_env env, napi_value jsCallback, void* context, void* data) {
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 static inline CallJsWrapper(
283
- napi_env env, napi_value jsCallback, void* /*context*/, void* /*data*/) {
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
- napi_value GetterWrapper(napi_env env, napi_callback_info info) {
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
- static_cast<AccessorCallbackData*>(callbackInfo.Data());
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
- napi_value SetterWrapper(napi_env env, napi_callback_info info) {
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
- static_cast<AccessorCallbackData*>(callbackInfo.Data());
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
- # include "napi-inl.deprecated.h"
346
- #endif // !NODE_ADDON_API_DISABLE_DEPRECATED
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_ ## classname(napi_env env, \
363
- napi_value exports) { \
364
- return Napi::RegisterModule(env, exports, &classname::Init); \
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(registerCallback(Napi::Env(env),
381
- Napi::Object(env, exports)));
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) result = false; // Checking for a pending exception shouldn't throw.
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
- napi_set_instance_data(_env, data, [](napi_env env, void* data, void*) {
541
- fini(env, static_cast<T*>(data));
542
- }, nullptr);
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
- napi_set_instance_data(_env, data,
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
- }, hint);
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> void Env::DefaultFini(Env, T* data) {
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) : _env(env), _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 ==(const Value& other) const {
582
+ inline bool Value::operator==(const Value& other) const {
593
583
  return StrictEquals(other);
594
584
  }
595
585
 
596
- inline bool Value::operator !=(const Value& other) const {
597
- return !this->operator ==(other);
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) : Napi::Value(env, 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, int sign_bit, size_t word_count, const uint64_t* words) {
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 = napi_create_bigint_words(env, sign_bit, word_count, words, &value);
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 = napi_get_value_bigint_int64(
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 = napi_get_value_bigint_uint64(
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 = napi_get_value_bigint_words(
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, size_t* word_count, uint64_t* words) {
934
- napi_status status = napi_get_value_bigint_words(
935
- _env, _value, sign_bit, word_count, words);
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 = napi_create_string_utf8(env, val, std::strlen(val), &value);
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 = napi_create_string_utf16(env, val, std::u16string(val).size(), &value);
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 = napi_get_value_string_utf8(_env, _value, nullptr, 0, &length);
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(_env, _value, &value[0], value.capacity(), nullptr);
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 = napi_get_value_string_utf16(_env, _value, nullptr, 0, &length);
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(_env, _value, &value[0], value.capacity(), nullptr);
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
- String::New(env, description) : static_cast<napi_value>(nullptr);
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).Global().Get("Symbol").As<Object>().Get(name).As<Symbol>();
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...> struct disjunction : std::false_type {};
1208
- template <typename B> struct disjunction<B> : B {};
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 *>::type,
1216
- typename std::is_convertible<T, const char16_t *>::type,
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
- std::is_integral<T>::value || std::is_floating_point<T>::value,
1225
- details::vf_number<T>,
1226
- typename std::conditional<
1227
- details::can_make_string<T>::value,
1228
- String,
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
- std::is_convertible<T, const char*>::value,
1240
- details::vf_utf8_charp,
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
- std::is_convertible<T, std::string>::value,
1246
- details::vf_utf8_string,
1247
- typename std::conditional<
1248
- std::is_convertible<T, std::u16string>::value,
1249
- details::vf_utf16_string,
1250
- Dummy
1251
- >::type
1252
- >::type
1253
- >::type
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> template <typename ValueType>
1273
- inline Object::PropertyLValue<Key>& Object::PropertyLValue<Key>::operator =(ValueType value) {
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
- : _env(object.Env()), _object(object), _key(key) {}
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 = napi_create_string_utf8(_env, utf8name, std::strlen(utf8name), &key);
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(_env, _value, 1,
1484
- reinterpret_cast<const napi_property_descriptor*>(&property));
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(_env, _value, properties.size(),
1491
- reinterpret_cast<const napi_property_descriptor*>(properties.begin()));
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(_env, _value, properties.size(),
1498
- reinterpret_cast<const napi_property_descriptor*>(properties.data()));
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
- details::AttachData(_env,
1535
- *this,
1536
- data,
1537
- details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
1538
- finalizeData);
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 = napi_create_external(env, data, nullptr, nullptr, &value);
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 = napi_create_external(
1656
- env,
1657
- data,
1658
- details::FinalizeData<T, Finalizer>::Wrapper,
1659
- finalizeData,
1660
- &value);
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
- env,
1680
- data,
1681
- details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
1682
- finalizeData,
1683
- &value);
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) : Value(env, 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
- env, externalData, byteLength, nullptr, nullptr, &value);
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
- env,
1773
- externalData,
1774
- byteLength,
1775
- details::FinalizeData<void, Finalizer>::Wrapper,
1776
- finalizeData,
1777
- &value);
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
- env,
1798
- externalData,
1799
- byteLength,
1800
- details::FinalizeData<void, Finalizer, Hint>::WrapperWithHint,
1801
- finalizeData,
1802
- &value);
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
- : Object(env, value) {
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 = napi_get_arraybuffer_info(_env, _value, nullptr, &length);
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(env,
1859
- "Start offset is outside the bounds of the buffer"),
1860
- DataView());
1851
+ NAPI_THROW(RangeError::New(
1852
+ env, "Start offset is outside the bounds of the buffer"),
1853
+ DataView());
1861
1854
  }
1862
- return New(env, arrayBuffer, byteOffset,
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 = napi_create_dataview(
1876
- env, byteLength, arrayBuffer, byteOffset, &value);
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
- _env,
1887
- _value /* dataView */,
1888
- &_length /* byteLength */,
1889
- &_data /* data */,
1890
- nullptr /* arrayBuffer */,
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
- _env,
1899
- _value /* dataView */,
1900
- nullptr /* byteLength */,
1901
- nullptr /* data */,
1902
- &arrayBuffer /* arrayBuffer */,
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
- _env,
1912
- _value /* dataView */,
1913
- nullptr /* byteLength */,
1914
- nullptr /* data */,
1915
- nullptr /* arrayBuffer */,
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(RangeError::New(_env,
1998
- "Offset is outside the bounds of the DataView"), 0);
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(RangeError::New(_env,
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
- : Object(), _type(TypedArray::unknown_array_type), _length(0) {
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
- : Object(env, value), _type(TypedArray::unknown_array_type), _length(0) {
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
- : Object(env, value), _type(type), _length(length) {
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 (TypedArrayType()) {
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
- _env, _value, nullptr, nullptr, nullptr, nullptr, &byteOffset);
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
- _env, _value, nullptr, nullptr, nullptr, &arrayBuffer, nullptr);
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 = Napi::ArrayBuffer::New(env, elementLength * sizeof (T));
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
- env, type, elementLength, arrayBuffer, bufferOffset, &value);
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
- env, value, type, elementLength,
2125
- reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(arrayBuffer.Data()) + bufferOffset));
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
- : TypedArray(env, value), _data(nullptr) {
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
- : TypedArray(env, value, type, length), _data(data) {
2144
+ : TypedArray(env, value, type, length), _data(data) {
2155
2145
  if (!(type == TypedArrayTypeForPrimitiveType<T>() ||
2156
- (type == napi_uint8_clamped_array && std::is_same<T, uint8_t>::value))) {
2157
- NAPI_THROW_VOID(TypeError::New(env, "Array type must match the template parameter. "
2158
- "(Uint8 arrays may optionally have the \"clamped\" array type.)"));
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 [](size_t index) {
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 [](size_t index) const {
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
- static inline napi_status
2188
- CreateFunction(napi_env env,
2189
- const char* utf8name,
2190
- napi_callback cb,
2191
- CbData* data,
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 = CreateFunction(env,
2253
- utf8name,
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) : Object(env, 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 = napi_call_function(
2340
- _env, recv, _value, argc, args, &result);
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 = napi_make_callback(
2366
- _env, context, recv, _value, argc, args, &result);
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 = napi_create_buffer(env, length * sizeof (T), &data, &value);
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
- env, length * sizeof (T), data, nullptr, nullptr, &value);
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 = napi_create_external_buffer(
2457
- env,
2458
- length * sizeof (T),
2459
- data,
2460
- details::FinalizeData<T, Finalizer>::Wrapper,
2461
- finalizeData,
2462
- &value);
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
- env,
2483
- length * sizeof (T),
2484
- data,
2485
- details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
2486
- finalizeData,
2487
- &value);
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 = napi_create_buffer_copy(
2499
- env, length * sizeof (T), data, nullptr, &value);
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
- : Uint8Array(env, value), _length(0), _data(nullptr) {
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
- : Uint8Array(env, value), _length(length), _data(data) {
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 = napi_get_buffer_info(_env, _value, &voidData, &byteLength);
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 (T);
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(status, "Error::New", "napi_get_and_clear_last_exception");
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
- env,
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>(env, message, std::strlen(message), napi_create_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>(env, message.c_str(), message.size(), napi_create_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, const char* message) {
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) : ObjectReference(env, nullptr) {
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 =(Error&& other) {
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 =(const Error& other) {
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 // NAPI_CPP_EXCEPTIONS
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 // NAPI_CPP_EXCEPTIONS
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 // NAPI_CPP_EXCEPTIONS
2794
- NAPI_FATAL_IF_FAILED(status, "Error::ThrowAsJavaScriptException", "napi_throw");
2795
- #endif // NAPI_CPP_EXCEPTIONS
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 // NAPI_CPP_EXCEPTIONS
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>(env, message, std::strlen(message), napi_create_type_error);
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>(env, message.c_str(), message.size(), napi_create_type_error);
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) : Error(env, 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>(env, message, std::strlen(message), napi_create_range_error);
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>(env, message.c_str(), message.size(), napi_create_range_error);
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) : Error(env, 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, uint32_t initialRefcount) {
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() : _env(nullptr), _ref(nullptr), _suppressDestruct(false) {
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
- : _env(env), _ref(ref), _suppressDestruct(false) {
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
- : _env(other._env), _ref(other._ref), _suppressDestruct(other._suppressDestruct) {
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 =(Reference<T>&& other) {
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
- : _env(other._env), _ref(nullptr), _suppressDestruct(false) {
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 always creates a
2924
- // strong reference to the given value even if the incoming reference is weak.
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(status, "Reference<T>::Reference", "napi_create_reference");
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 ==(const Reference<T> &other) const {
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 !=(const Reference<T> &other) const {
2943
- return !this->operator ==(other);
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): Reference<Object>(env, 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
- : Reference<Object>(std::move(other)) {
3048
- }
3034
+ : Reference<Object>(std::move(other)) {}
3049
3035
 
3050
- inline ObjectReference& ObjectReference::operator =(Reference<Object>&& other) {
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
- : Reference<Object>(std::move(other)) {
3057
- }
3042
+ : Reference<Object>(std::move(other)) {}
3058
3043
 
3059
- inline ObjectReference& ObjectReference::operator =(ObjectReference&& other) {
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
- : Reference<Object>(other) {
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
- : Reference<Function>(env, ref) {
3223
- }
3205
+ : Reference<Function>(env, ref) {}
3224
3206
 
3225
3207
  inline FunctionReference::FunctionReference(Reference<Function>&& other)
3226
- : Reference<Function>(std::move(other)) {
3227
- }
3208
+ : Reference<Function>(std::move(other)) {}
3228
3209
 
3229
- inline FunctionReference& FunctionReference::operator =(Reference<Function>&& other) {
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
- : Reference<Function>(std::move(other)) {
3236
- }
3217
+ : Reference<Function>(std::move(other)) {}
3237
3218
 
3238
- inline FunctionReference& FunctionReference::operator =(FunctionReference&& other) {
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), _info(info), _this(nullptr), _dynamicArgs(nullptr), _data(nullptr) {
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 = napi_get_cb_info(env, info, &_argc, _argv, &_this, &_data);
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 [](size_t index) const {
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
- PropertyDescriptor::Accessor(const char* utf8name,
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
- PropertyDescriptor::Accessor(const std::string& utf8name,
3527
- napi_property_attributes attributes,
3528
- void* data) {
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
- PropertyDescriptor::Accessor(Name name,
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::GetterCallback Getter,
3549
- typename PropertyDescriptor::SetterCallback Setter>
3550
- PropertyDescriptor
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::GetterCallback Getter,
3568
- typename PropertyDescriptor::SetterCallback Setter>
3569
- PropertyDescriptor
3570
- PropertyDescriptor::Accessor(const std::string& utf8name,
3571
- napi_property_attributes attributes,
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::GetterCallback Getter,
3578
- typename PropertyDescriptor::SetterCallback Setter>
3579
- PropertyDescriptor
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
- PropertyDescriptor::Accessor(Napi::Env env,
3597
- Napi::Object object,
3598
- const char* utf8name,
3599
- Getter getter,
3600
- napi_property_attributes attributes,
3601
- void* data) {
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({ getter, data });
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
- utf8name,
3613
- nullptr,
3614
- nullptr,
3615
- CbData::Wrapper,
3616
- nullptr,
3617
- nullptr,
3618
- attributes,
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(Napi::Env env,
3625
- Napi::Object object,
3626
- const std::string& utf8name,
3627
- Getter getter,
3628
- napi_property_attributes attributes,
3629
- void* data) {
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(Napi::Env env,
3635
- Napi::Object object,
3636
- Name name,
3637
- Getter getter,
3638
- napi_property_attributes attributes,
3639
- void* data) {
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({ getter, data });
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
- nullptr,
3651
- name,
3652
- nullptr,
3653
- CbData::Wrapper,
3654
- nullptr,
3655
- nullptr,
3656
- attributes,
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(Napi::Env env,
3663
- Napi::Object object,
3664
- const char* utf8name,
3665
- Getter getter,
3666
- Setter setter,
3667
- napi_property_attributes attributes,
3668
- void* data) {
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({ getter, setter, data });
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
- utf8name,
3680
- nullptr,
3681
- nullptr,
3682
- CbData::GetterWrapper,
3683
- CbData::SetterWrapper,
3684
- nullptr,
3685
- attributes,
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(Napi::Env env,
3692
- Napi::Object object,
3693
- const std::string& utf8name,
3694
- Getter getter,
3695
- Setter setter,
3696
- napi_property_attributes attributes,
3697
- void* data) {
3698
- return Accessor(env, object, utf8name.c_str(), getter, setter, attributes, data);
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(Napi::Env env,
3703
- Napi::Object object,
3704
- Name name,
3705
- Getter getter,
3706
- Setter setter,
3707
- napi_property_attributes attributes,
3708
- void* data) {
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({ getter, setter, data });
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
- nullptr,
3720
- name,
3721
- nullptr,
3722
- CbData::GetterWrapper,
3723
- CbData::SetterWrapper,
3724
- nullptr,
3725
- attributes,
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(Napi::Env env,
3732
- Napi::Object /*object*/,
3733
- const char* utf8name,
3734
- Callable cb,
3735
- napi_property_attributes attributes,
3736
- void* data) {
3737
- return PropertyDescriptor({
3738
- utf8name,
3739
- nullptr,
3740
- nullptr,
3741
- nullptr,
3742
- nullptr,
3743
- Napi::Function::New(env, cb, utf8name, data),
3744
- attributes,
3745
- nullptr
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(Napi::Env env,
3751
- Napi::Object object,
3752
- const std::string& utf8name,
3753
- Callable cb,
3754
- napi_property_attributes attributes,
3755
- void* data) {
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(Napi::Env env,
3761
- Napi::Object /*object*/,
3762
- Name name,
3763
- Callable cb,
3764
- napi_property_attributes attributes,
3765
- void* data) {
3766
- return PropertyDescriptor({
3767
- nullptr,
3768
- name,
3769
- nullptr,
3770
- nullptr,
3771
- nullptr,
3772
- Napi::Function::New(env, cb, nullptr, data),
3773
- attributes,
3774
- nullptr
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(const std::string& utf8name,
3787
- napi_value value,
3788
- napi_property_attributes attributes) {
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(napi_value name,
3793
- napi_value value,
3794
- napi_property_attributes attributes) {
3795
- return PropertyDescriptor({
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(Name name,
3801
- Napi::Value value,
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
- : _desc(desc) {
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(napi_env env,
3826
- napi_value value,
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(env,
3832
- value,
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(env,
3837
- value,
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
- prop->setter == T::InstanceSetterCallbackWrapper) {
3842
- status = Napi::details::AttachData(env,
3843
- value,
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
- new InstanceVoidMethodCallbackData({ method, data});
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 = new InstanceMethodCallbackData({ method, data });
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
- new InstanceVoidMethodCallbackData({ method, data});
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 = new InstanceMethodCallbackData({ method, data });
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
- new InstanceAccessorCallbackData({ getter, setter, data });
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
- new InstanceAccessorCallbackData({ getter, setter, data });
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
- reinterpret_cast<InstanceVoidMethodCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<InstanceMethodCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
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
- ObjectWrap<T>::DefineClass(Napi::Env env,
4183
- const char* utf8name,
4184
- const size_t props_count,
4185
- const napi_property_descriptor* descriptors,
4186
- void* data) {
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 = CreateFunction(env,
4203
- utf8name,
4204
- prop->method,
4205
- static_cast<StaticMethodCallbackData*>(prop->data),
4206
- &(prop->value));
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 = CreateFunction(env,
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(env,
4242
- value,
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(env,
4262
- utf8name,
4263
- properties.size(),
4264
- reinterpret_cast<const napi_property_descriptor*>(properties.begin()),
4265
- data);
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(env,
4275
- utf8name,
4276
- properties.size(),
4277
- reinterpret_cast<const napi_property_descriptor*>(properties.data()),
4278
- data);
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 = new StaticVoidMethodCallbackData({ method, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = new StaticMethodCallbackData({ method, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = new StaticVoidMethodCallbackData({ method, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = new StaticMethodCallbackData({ method, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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
- new StaticAccessorCallbackData({ getter, setter, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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
- new StaticAccessorCallbackData({ getter, setter, data });
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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(const char* utf8name,
4473
- Napi::Value value, napi_property_attributes attributes) {
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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(Symbol name,
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 = static_cast<napi_property_attributes>(attributes | napi_static);
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
- # endif // NAPI_CPP_EXCEPTIONS
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
- reinterpret_cast<StaticVoidMethodCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<StaticMethodCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
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
- reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
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, void* data, void* /*hint*/) {
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(status,
4627
- "HandleScope::~HandleScope",
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
- napi_env env, napi_escapable_handle_scope scope) : _env(env), _scope(scope) {
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
- napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
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 = napi_open_callback_scope(
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(status,
4694
- "CallbackScope::~CallbackScope",
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
- : AsyncContext(env, resource_name, Object::New(env)) {
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 =(AsyncContext&& other) {
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
- : AsyncWorker(callback, "generic") {
4764
- }
4724
+ : AsyncWorker(callback, "generic") {}
4765
4725
 
4766
4726
  inline AsyncWorker::AsyncWorker(const Function& callback,
4767
4727
  const char* resource_name)
4768
- : AsyncWorker(callback, resource_name, Object::New(callback.Env())) {
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
- : AsyncWorker(Object::New(callback.Env()),
4775
- callback,
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
- : AsyncWorker(receiver, callback, "generic") {
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
- : AsyncWorker(receiver,
4789
- callback,
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
- : _env(callback.Env()),
4799
- _receiver(Napi::Persistent(receiver)),
4800
- _callback(Napi::Persistent(callback)),
4801
- _suppress_destruct(false) {
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, resource, resource_id, OnAsyncWorkExecute,
4808
- OnAsyncWorkComplete, this, &_work);
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
- const char* resource_name)
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
- : _env(env),
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, resource, resource_id, OnAsyncWorkExecute,
4834
- OnAsyncWorkComplete, this, &_work);
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 =(AsyncWorker&& other) {
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(), std::initializer_list<napi_value>{ e.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 // NAPI_CPP_EXCEPTIONS
4896
+ #else // NAPI_CPP_EXCEPTIONS
4941
4897
  Execute();
4942
- #endif // NAPI_CPP_EXCEPTIONS
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
- const Function& callback,
5462
- ResourceString resourceName,
5463
- size_t maxQueueSize,
5464
- size_t initialThreadCount) {
5465
- return New(env, callback, Object(), resourceName, maxQueueSize,
5466
- initialThreadCount);
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
- const Function& callback,
5473
- ResourceString resourceName,
5474
- size_t maxQueueSize,
5475
- size_t initialThreadCount,
5476
- ContextType* context) {
5477
- return New(env, callback, Object(), resourceName, maxQueueSize,
5478
- initialThreadCount, context);
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
- const Function& callback,
5485
- ResourceString resourceName,
5486
- size_t maxQueueSize,
5487
- size_t initialThreadCount,
5488
- Finalizer finalizeCallback) {
5489
- return New(env, callback, Object(), resourceName, maxQueueSize,
5490
- initialThreadCount, finalizeCallback);
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, typename Finalizer,
5459
+ template <typename ResourceString,
5460
+ typename Finalizer,
5495
5461
  typename FinalizerDataType>
5496
5462
  inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5497
- const Function& callback,
5498
- ResourceString resourceName,
5499
- size_t maxQueueSize,
5500
- size_t initialThreadCount,
5501
- Finalizer finalizeCallback,
5502
- FinalizerDataType* data) {
5503
- return New(env, callback, Object(), resourceName, maxQueueSize,
5504
- initialThreadCount, finalizeCallback, data);
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
- const Function& callback,
5511
- ResourceString resourceName,
5512
- size_t maxQueueSize,
5513
- size_t initialThreadCount,
5514
- ContextType* context,
5515
- Finalizer finalizeCallback) {
5516
- return New(env, callback, Object(), resourceName, maxQueueSize,
5517
- initialThreadCount, context, finalizeCallback);
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, typename ContextType,
5522
- typename Finalizer, typename FinalizerDataType>
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, callback, Object(), resourceName, maxQueueSize,
5532
- initialThreadCount, context, finalizeCallback, data);
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
- const Function& callback,
5539
- const Object& resource,
5540
- ResourceString resourceName,
5541
- size_t maxQueueSize,
5542
- size_t initialThreadCount) {
5543
- return New(env, callback, resource, resourceName, maxQueueSize,
5544
- initialThreadCount, static_cast<void*>(nullptr) /* context */);
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
- const Function& callback,
5551
- const Object& resource,
5552
- ResourceString resourceName,
5553
- size_t maxQueueSize,
5554
- size_t initialThreadCount,
5555
- ContextType* context) {
5556
- return New(env, callback, resource, resourceName, maxQueueSize,
5557
- initialThreadCount, context,
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
- const Function& callback,
5565
- const Object& resource,
5566
- ResourceString resourceName,
5567
- size_t maxQueueSize,
5568
- size_t initialThreadCount,
5569
- Finalizer finalizeCallback) {
5570
- return New(env, callback, resource, resourceName, maxQueueSize,
5571
- initialThreadCount, static_cast<void*>(nullptr) /* context */,
5572
- finalizeCallback, static_cast<void*>(nullptr) /* data */,
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, typename Finalizer,
5580
+ template <typename ResourceString,
5581
+ typename Finalizer,
5578
5582
  typename FinalizerDataType>
5579
5583
  inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5580
- const Function& callback,
5581
- const Object& resource,
5582
- ResourceString resourceName,
5583
- size_t maxQueueSize,
5584
- size_t initialThreadCount,
5585
- Finalizer finalizeCallback,
5586
- FinalizerDataType* data) {
5587
- return New(env, callback, resource, resourceName, maxQueueSize,
5588
- initialThreadCount, static_cast<void*>(nullptr) /* context */,
5589
- finalizeCallback, data,
5590
- details::ThreadSafeFinalize<
5591
- void, Finalizer, FinalizerDataType>::FinalizeWrapperWithData);
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
- const Function& callback,
5598
- const Object& resource,
5599
- ResourceString resourceName,
5600
- size_t maxQueueSize,
5601
- size_t initialThreadCount,
5602
- ContextType* context,
5603
- Finalizer finalizeCallback) {
5604
- return New(env, callback, resource, resourceName, maxQueueSize,
5605
- initialThreadCount, context, finalizeCallback,
5606
- static_cast<void*>(nullptr) /* data */,
5607
- details::ThreadSafeFinalize<
5608
- ContextType, Finalizer>::FinalizeWrapperWithContext);
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, typename ContextType,
5613
- typename Finalizer, typename FinalizerDataType>
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(env, callback, resource, resourceName, maxQueueSize,
5624
- initialThreadCount, context, finalizeCallback, data,
5625
- details::ThreadSafeFinalize<ContextType, Finalizer,
5626
- FinalizerDataType>::FinalizeFinalizeWrapperWithDataAndContext);
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
- napi_threadsafe_function tsfn)
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
- DataType* data, Callback callback) const {
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
- ThreadSafeFunction::GetContext() const {
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, "ThreadSafeFunction::GetContext", "napi_get_threadsafe_function_context");
5723
- return ConvertibleContext({ context });
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, typename ContextType,
5728
- typename Finalizer, typename FinalizerDataType>
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
- || std::is_convertible<ResourceString, napi_value>::value,
5741
- "Resource name should be convertible to the string type");
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::ThreadSafeFinalize<ContextType, Finalizer,
5745
- FinalizerDataType>({ data, finalizeCallback });
5746
- napi_status status = napi_create_threadsafe_function(env, callback, resource,
5747
- Value::From(env, resourceName), maxQueueSize, initialThreadCount,
5748
- finalizeData, wrapper, context, CallJS, &tsfn._tsfn);
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 = napi_call_threadsafe_function(
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(const Object& receiver,
5792
- const Function& callback,
5793
- const char* resource_name,
5794
- const Object& resource,
5795
- size_t queue_size)
5796
- : AsyncWorker(receiver, callback, resource_name, resource) {
5797
- // Fill all possible arguments to work around ambiguous ThreadSafeFunction::New signatures.
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(Napi::Env env,
5812
- const char* resource_name,
5813
- const Object& resource,
5814
- size_t queue_size)
5815
- : AsyncWorker(env, resource_name, resource) {
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 here.
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 ThreadSafeFunction::New signatures.
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 duplicated.
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(Napi::Env /* env */,
5842
- Napi::Function /* jsCallback */,
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(DataType* data) {
5889
+ inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(
5890
+ DataType* data) {
5851
5891
  auto tsd = new AsyncProgressWorkerBase::ThreadSafeData(this, data);
5852
- return _tsfn.NonBlockingCall(tsd, OnAsyncWorkProgress);
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(Napi::Env /* env */, napi_status status) {
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(Napi::Env env, void* /* data */, AsyncProgressWorkerBase* context) {
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
- : AsyncProgressWorker(callback, "generic") {
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
- const char* resource_name)
5880
- : AsyncProgressWorker(callback, resource_name, Object::New(callback.Env())) {
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
- const char* resource_name,
5886
- const Object& resource)
5887
- : AsyncProgressWorker(Object::New(callback.Env()),
5888
- callback,
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
- : AsyncProgressWorker(receiver, callback, "generic") {
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
- : AsyncProgressWorker(receiver,
5904
- callback,
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
- : AsyncProgressWorkerBase(receiver, callback, resource_name, resource),
5915
- _asyncdata(nullptr),
5916
- _asyncsize(0) {
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
- : AsyncProgressWorker(env, "generic") {
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
- : AsyncProgressWorker(env, resource_name, Object::New(env)) {
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
- : AsyncProgressWorkerBase(env, resource_name, resource),
5936
- _asyncdata(nullptr),
5937
- _asyncsize(0) {
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
- T* new_data = new T[count];
5986
- std::copy(data, data + count, new_data);
5987
-
5988
- T* old_data;
5989
- {
5990
- std::lock_guard<std::mutex> lock(this->_mutex);
5991
- old_data = _asyncdata;
5992
- _asyncdata = new_data;
5993
- _asyncsize = count;
5994
- }
5995
- this->NonBlockingCall(nullptr);
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
- delete[] old_data;
6036
+ delete[] old_data;
5998
6037
  }
5999
6038
 
6000
- template<class T>
6001
- inline void AsyncProgressWorker<T>::Signal() const {
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(const T* data, size_t count) const {
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(const Function& callback)
6020
- : AsyncProgressQueueWorker(callback, "generic") {
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(const Function& callback,
6025
- const char* resource_name)
6026
- : AsyncProgressQueueWorker(callback, resource_name, Object::New(callback.Env())) {
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(const Function& callback,
6031
- const char* resource_name,
6032
- const Object& resource)
6033
- : AsyncProgressQueueWorker(Object::New(callback.Env()),
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(const Object& receiver,
6041
- const Function& callback)
6042
- : AsyncProgressQueueWorker(receiver, callback, "generic") {
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(const Object& receiver,
6047
- const Function& callback,
6048
- const char* resource_name)
6049
- : AsyncProgressQueueWorker(receiver,
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(const Object& receiver,
6057
- const Function& callback,
6058
- const char* resource_name,
6059
- const Object& resource)
6060
- : AsyncProgressWorkerBase<std::pair<T*, size_t>>(receiver, callback, resource_name, resource, /** unlimited queue size */0) {
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
- : AsyncProgressQueueWorker(env, "generic") {
6067
- }
6106
+ : AsyncProgressQueueWorker(env, "generic") {}
6068
6107
 
6069
- template<class T>
6070
- inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(Napi::Env env,
6071
- const char* resource_name)
6072
- : AsyncProgressQueueWorker(env, resource_name, Object::New(env)) {
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(Napi::Env env,
6077
- const char* resource_name,
6078
- const Object& resource)
6079
- : AsyncProgressWorkerBase<std::pair<T*, size_t>>(env, resource_name, resource, /** unlimited queue size */0) {
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(std::pair<T*, size_t>* datapair) {
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 *data = datapair->first;
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, size_t count) {
6105
- T* new_data = new T[count];
6106
- std::copy(data, data + count, new_data);
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
- auto pair = new std::pair<T*, size_t>(new_data, count);
6109
- this->NonBlockingCall(pair);
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->NonBlockingCall(nullptr);
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, napi_status status) {
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->Signal();
6165
+ _worker->SendProgress_(static_cast<T*>(nullptr), 0);
6126
6166
  }
6127
6167
 
6128
- template<class T>
6129
- inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(const T* data, size_t count) const {
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, int64_t change_in_bytes) {
6179
+ inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
6180
+ int64_t change_in_bytes) {
6139
6181
  int64_t result;
6140
- napi_status status = napi_adjust_external_memory(env, change_in_bytes, &result);
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
- Addon<T>::DefineAddon(Object exports,
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
- Addon<T>::DefineProperties(Object object,
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
- reinterpret_cast<const napi_property_descriptor*>(props.begin());
6234
+ reinterpret_cast<const napi_property_descriptor*>(props.begin());
6194
6235
  size_t size = props.size();
6195
- napi_status status = napi_define_properties(object.Env(),
6196
- object,
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
- } // namespace Napi
6301
+ } // namespace Napi
6258
6302
 
6259
- #endif // SRC_NAPI_INL_H_
6303
+ #endif // SRC_NAPI_INL_H_