koffi 2.3.3 → 2.3.5

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 (192) hide show
  1. package/CHANGELOG.md +19 -3
  2. package/doc/changelog.md +4 -0
  3. package/doc/index.rst +1 -2
  4. package/doc/types.md +3 -3
  5. package/package.json +2 -2
  6. package/src/core/libcc/libcc.cc +2 -2
  7. package/src/koffi/build/2.3.5/koffi_darwin_arm64.tar.gz +0 -0
  8. package/src/koffi/build/2.3.5/koffi_darwin_x64.tar.gz +0 -0
  9. package/src/koffi/build/2.3.5/koffi_freebsd_arm64.tar.gz +0 -0
  10. package/src/koffi/build/2.3.5/koffi_freebsd_ia32.tar.gz +0 -0
  11. package/src/koffi/build/2.3.5/koffi_freebsd_x64.tar.gz +0 -0
  12. package/src/koffi/build/2.3.5/koffi_linux_arm32hf.tar.gz +0 -0
  13. package/src/koffi/build/2.3.5/koffi_linux_arm64.tar.gz +0 -0
  14. package/src/koffi/build/2.3.5/koffi_linux_ia32.tar.gz +0 -0
  15. package/src/koffi/build/2.3.5/koffi_linux_riscv64hf64.tar.gz +0 -0
  16. package/src/koffi/build/2.3.5/koffi_linux_x64.tar.gz +0 -0
  17. package/src/koffi/build/2.3.5/koffi_openbsd_ia32.tar.gz +0 -0
  18. package/src/koffi/build/2.3.5/koffi_openbsd_x64.tar.gz +0 -0
  19. package/src/koffi/build/2.3.5/koffi_win32_arm64.tar.gz +0 -0
  20. package/src/koffi/build/2.3.5/koffi_win32_ia32.tar.gz +0 -0
  21. package/src/koffi/build/2.3.5/koffi_win32_x64.tar.gz +0 -0
  22. package/src/koffi/src/abi_arm32.cc +43 -14
  23. package/src/koffi/src/abi_arm64.cc +95 -21
  24. package/src/koffi/src/abi_riscv64.cc +125 -64
  25. package/src/koffi/src/abi_x64_sysv.cc +38 -20
  26. package/src/koffi/src/abi_x64_win.cc +11 -5
  27. package/src/koffi/src/abi_x86.cc +14 -7
  28. package/src/koffi/src/call.cc +114 -44
  29. package/src/koffi/src/call.hh +6 -4
  30. package/src/koffi/src/ffi.cc +172 -147
  31. package/src/koffi/src/ffi.hh +18 -10
  32. package/src/koffi/src/index.d.ts +28 -7
  33. package/src/koffi/src/util.cc +261 -69
  34. package/src/koffi/src/util.hh +34 -8
  35. package/vendor/node-addon-api/CHANGELOG.md +122 -9
  36. package/vendor/node-addon-api/CONTRIBUTING.md +10 -10
  37. package/vendor/node-addon-api/README.md +36 -12
  38. package/vendor/node-addon-api/benchmark/function_args.cc +95 -62
  39. package/vendor/node-addon-api/benchmark/function_args.js +6 -6
  40. package/vendor/node-addon-api/benchmark/index.js +1 -1
  41. package/vendor/node-addon-api/benchmark/property_descriptor.cc +27 -34
  42. package/vendor/node-addon-api/benchmark/property_descriptor.js +5 -4
  43. package/vendor/node-addon-api/doc/async_operations.md +1 -1
  44. package/vendor/node-addon-api/doc/async_worker_variants.md +23 -2
  45. package/vendor/node-addon-api/doc/cmake-js.md +1 -1
  46. package/vendor/node-addon-api/doc/error_handling.md +3 -3
  47. package/vendor/node-addon-api/doc/external.md +7 -0
  48. package/vendor/node-addon-api/doc/handle_scope.md +14 -0
  49. package/vendor/node-addon-api/doc/hierarchy.md +1 -1
  50. package/vendor/node-addon-api/doc/object.md +27 -0
  51. package/vendor/node-addon-api/index.js +3 -3
  52. package/vendor/node-addon-api/napi-inl.deprecated.h +121 -127
  53. package/vendor/node-addon-api/napi-inl.h +1178 -1144
  54. package/vendor/node-addon-api/napi.h +2786 -2675
  55. package/vendor/node-addon-api/package.json +42 -1
  56. package/vendor/node-addon-api/test/addon.cc +8 -6
  57. package/vendor/node-addon-api/test/addon_build/index.js +9 -9
  58. package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +2 -1
  59. package/vendor/node-addon-api/test/addon_build/tpl/index.js +4 -4
  60. package/vendor/node-addon-api/test/addon_data.cc +12 -13
  61. package/vendor/node-addon-api/test/array_buffer.js +3 -2
  62. package/vendor/node-addon-api/test/async_progress_queue_worker.cc +13 -3
  63. package/vendor/node-addon-api/test/async_progress_queue_worker.js +5 -5
  64. package/vendor/node-addon-api/test/async_progress_worker.cc +65 -9
  65. package/vendor/node-addon-api/test/async_progress_worker.js +14 -9
  66. package/vendor/node-addon-api/test/async_worker.cc +236 -3
  67. package/vendor/node-addon-api/test/async_worker.js +122 -37
  68. package/vendor/node-addon-api/test/async_worker_nocallback.js +9 -3
  69. package/vendor/node-addon-api/test/async_worker_persistent.js +2 -2
  70. package/vendor/node-addon-api/test/basic_types/array.js +3 -4
  71. package/vendor/node-addon-api/test/basic_types/boolean.cc +4 -2
  72. package/vendor/node-addon-api/test/basic_types/boolean.js +1 -2
  73. package/vendor/node-addon-api/test/basic_types/number.cc +12 -6
  74. package/vendor/node-addon-api/test/basic_types/number.js +19 -18
  75. package/vendor/node-addon-api/test/basic_types/value.cc +52 -1
  76. package/vendor/node-addon-api/test/basic_types/value.js +44 -21
  77. package/vendor/node-addon-api/test/bigint.cc +2 -1
  78. package/vendor/node-addon-api/test/binding.cc +11 -5
  79. package/vendor/node-addon-api/test/binding.gyp +3 -1
  80. package/vendor/node-addon-api/test/buffer.cc +46 -38
  81. package/vendor/node-addon-api/test/buffer.js +12 -12
  82. package/vendor/node-addon-api/test/callbackInfo.cc +27 -0
  83. package/vendor/node-addon-api/test/callbackInfo.js +9 -0
  84. package/vendor/node-addon-api/test/callbackscope.cc +19 -2
  85. package/vendor/node-addon-api/test/callbackscope.js +20 -20
  86. package/vendor/node-addon-api/test/common/index.js +37 -4
  87. package/vendor/node-addon-api/test/dataview/dataview.js +5 -5
  88. package/vendor/node-addon-api/test/dataview/dataview_read_write.js +14 -12
  89. package/vendor/node-addon-api/test/date.cc +2 -1
  90. package/vendor/node-addon-api/test/date.js +2 -2
  91. package/vendor/node-addon-api/test/env_cleanup.cc +12 -0
  92. package/vendor/node-addon-api/test/env_cleanup.js +38 -39
  93. package/vendor/node-addon-api/test/error.cc +6 -5
  94. package/vendor/node-addon-api/test/error_terminating_environment.js +64 -60
  95. package/vendor/node-addon-api/test/external.cc +36 -32
  96. package/vendor/node-addon-api/test/external.js +43 -46
  97. package/vendor/node-addon-api/test/function.cc +58 -44
  98. package/vendor/node-addon-api/test/function.js +4 -0
  99. package/vendor/node-addon-api/test/function_reference.cc +15 -13
  100. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +50 -53
  101. package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +33 -34
  102. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +38 -40
  103. package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +47 -49
  104. package/vendor/node-addon-api/test/handlescope.cc +29 -3
  105. package/vendor/node-addon-api/test/handlescope.js +5 -3
  106. package/vendor/node-addon-api/test/index.js +1 -5
  107. package/vendor/node-addon-api/test/maybe/check.cc +49 -3
  108. package/vendor/node-addon-api/test/maybe/index.js +19 -7
  109. package/vendor/node-addon-api/test/memory_management.cc +9 -8
  110. package/vendor/node-addon-api/test/memory_management.js +2 -2
  111. package/vendor/node-addon-api/test/movable_callbacks.js +2 -2
  112. package/vendor/node-addon-api/test/name.js +3 -3
  113. package/vendor/node-addon-api/test/napi_child.js +2 -2
  114. package/vendor/node-addon-api/test/object/delete_property.js +7 -7
  115. package/vendor/node-addon-api/test/object/finalizer.cc +13 -12
  116. package/vendor/node-addon-api/test/object/finalizer.js +2 -2
  117. package/vendor/node-addon-api/test/object/get_property.js +6 -6
  118. package/vendor/node-addon-api/test/object/has_own_property.js +3 -3
  119. package/vendor/node-addon-api/test/object/has_property.js +4 -4
  120. package/vendor/node-addon-api/test/object/object.cc +191 -111
  121. package/vendor/node-addon-api/test/object/object.js +53 -52
  122. package/vendor/node-addon-api/test/object/object_deprecated.cc +24 -20
  123. package/vendor/node-addon-api/test/object/object_deprecated.js +3 -8
  124. package/vendor/node-addon-api/test/object/object_freeze_seal.js +54 -54
  125. package/vendor/node-addon-api/test/object/object_type_tag.cc +39 -0
  126. package/vendor/node-addon-api/test/object/object_type_tag.js +55 -0
  127. package/vendor/node-addon-api/test/object/subscript_operator.js +2 -2
  128. package/vendor/node-addon-api/test/object_reference.js +100 -100
  129. package/vendor/node-addon-api/test/objectwrap.cc +41 -34
  130. package/vendor/node-addon-api/test/objectwrap.js +23 -19
  131. package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +5 -5
  132. package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +1 -1
  133. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +7 -7
  134. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +1 -1
  135. package/vendor/node-addon-api/test/objectwrap_removewrap.js +24 -32
  136. package/vendor/node-addon-api/test/objectwrap_worker_thread.js +5 -4
  137. package/vendor/node-addon-api/test/promise.cc +7 -0
  138. package/vendor/node-addon-api/test/promise.js +3 -1
  139. package/vendor/node-addon-api/test/reference.cc +1 -1
  140. package/vendor/node-addon-api/test/reference.js +2 -2
  141. package/vendor/node-addon-api/test/run_script.cc +1 -1
  142. package/vendor/node-addon-api/test/symbol.js +59 -66
  143. package/vendor/node-addon-api/test/testUtil.js +6 -6
  144. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +64 -29
  145. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +71 -34
  146. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +111 -19
  147. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +2 -1
  148. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +36 -26
  149. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +5 -5
  150. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +3 -2
  151. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +1 -1
  152. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +47 -32
  153. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +3 -3
  154. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +22 -9
  155. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +76 -31
  156. package/vendor/node-addon-api/test/thunking_manual.cc +61 -74
  157. package/vendor/node-addon-api/test/thunking_manual.js +6 -7
  158. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +20 -20
  159. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +19 -19
  160. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +57 -5
  161. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +2 -0
  162. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +5 -5
  163. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +5 -1
  164. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +4 -3
  165. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +3 -3
  166. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +14 -0
  167. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +76 -31
  168. package/vendor/node-addon-api/test/typedarray-bigint.js +2 -2
  169. package/vendor/node-addon-api/test/typedarray.cc +263 -70
  170. package/vendor/node-addon-api/test/typedarray.js +44 -10
  171. package/vendor/node-addon-api/test/version_management.cc +16 -15
  172. package/vendor/node-addon-api/test/version_management.js +18 -20
  173. package/vendor/node-addon-api/tools/check-napi.js +13 -14
  174. package/vendor/node-addon-api/tools/conversion.js +161 -169
  175. package/vendor/node-addon-api/tools/eslint-format.js +9 -1
  176. package/vendor/node-addon-api/unit-test/README.md +4 -4
  177. package/koffi-2.3.3.tgz +0 -0
  178. package/src/koffi/build/2.3.3/koffi_darwin_arm64.tar.gz +0 -0
  179. package/src/koffi/build/2.3.3/koffi_darwin_x64.tar.gz +0 -0
  180. package/src/koffi/build/2.3.3/koffi_freebsd_arm64.tar.gz +0 -0
  181. package/src/koffi/build/2.3.3/koffi_freebsd_ia32.tar.gz +0 -0
  182. package/src/koffi/build/2.3.3/koffi_freebsd_x64.tar.gz +0 -0
  183. package/src/koffi/build/2.3.3/koffi_linux_arm32hf.tar.gz +0 -0
  184. package/src/koffi/build/2.3.3/koffi_linux_arm64.tar.gz +0 -0
  185. package/src/koffi/build/2.3.3/koffi_linux_ia32.tar.gz +0 -0
  186. package/src/koffi/build/2.3.3/koffi_linux_riscv64hf64.tar.gz +0 -0
  187. package/src/koffi/build/2.3.3/koffi_linux_x64.tar.gz +0 -0
  188. package/src/koffi/build/2.3.3/koffi_openbsd_ia32.tar.gz +0 -0
  189. package/src/koffi/build/2.3.3/koffi_openbsd_x64.tar.gz +0 -0
  190. package/src/koffi/build/2.3.3/koffi_win32_arm64.tar.gz +0 -0
  191. package/src/koffi/build/2.3.3/koffi_win32_ia32.tar.gz +0 -0
  192. package/src/koffi/build/2.3.3/koffi_win32_x64.tar.gz +0 -0
@@ -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);
@@ -1629,6 +1626,19 @@ inline MaybeOrValue<bool> Object::Seal() const {
1629
1626
  napi_status status = napi_object_seal(_env, _value);
1630
1627
  NAPI_RETURN_OR_THROW_IF_FAILED(_env, status, status == napi_ok, bool);
1631
1628
  }
1629
+
1630
+ inline void Object::TypeTag(const napi_type_tag* type_tag) const {
1631
+ napi_status status = napi_type_tag_object(_env, _value, type_tag);
1632
+ NAPI_THROW_IF_FAILED_VOID(_env, status);
1633
+ }
1634
+
1635
+ inline bool Object::CheckTypeTag(const napi_type_tag* type_tag) const {
1636
+ bool result;
1637
+ napi_status status =
1638
+ napi_check_object_type_tag(_env, _value, type_tag, &result);
1639
+ NAPI_THROW_IF_FAILED(_env, status, false);
1640
+ return result;
1641
+ }
1632
1642
  #endif // NAPI_VERSION >= 8
1633
1643
 
1634
1644
  ////////////////////////////////////////////////////////////////////////////////
@@ -1638,7 +1648,8 @@ inline MaybeOrValue<bool> Object::Seal() const {
1638
1648
  template <typename T>
1639
1649
  inline External<T> External<T>::New(napi_env env, T* data) {
1640
1650
  napi_value value;
1641
- napi_status status = napi_create_external(env, data, nullptr, nullptr, &value);
1651
+ napi_status status =
1652
+ napi_create_external(env, data, nullptr, nullptr, &value);
1642
1653
  NAPI_THROW_IF_FAILED(env, status, External());
1643
1654
  return External(env, value);
1644
1655
  }
@@ -1652,12 +1663,12 @@ inline External<T> External<T>::New(napi_env env,
1652
1663
  details::FinalizeData<T, Finalizer>* finalizeData =
1653
1664
  new details::FinalizeData<T, Finalizer>(
1654
1665
  {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);
1666
+ napi_status status =
1667
+ napi_create_external(env,
1668
+ data,
1669
+ details::FinalizeData<T, Finalizer>::Wrapper,
1670
+ finalizeData,
1671
+ &value);
1661
1672
  if (status != napi_ok) {
1662
1673
  delete finalizeData;
1663
1674
  NAPI_THROW_IF_FAILED(env, status, External());
@@ -1676,11 +1687,11 @@ inline External<T> External<T>::New(napi_env env,
1676
1687
  new details::FinalizeData<T, Finalizer, Hint>(
1677
1688
  {std::move(finalizeCallback), finalizeHint});
1678
1689
  napi_status status = napi_create_external(
1679
- env,
1680
- data,
1681
- details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
1682
- finalizeData,
1683
- &value);
1690
+ env,
1691
+ data,
1692
+ details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
1693
+ finalizeData,
1694
+ &value);
1684
1695
  if (status != napi_ok) {
1685
1696
  delete finalizeData;
1686
1697
  NAPI_THROW_IF_FAILED(env, status, External());
@@ -1689,12 +1700,11 @@ inline External<T> External<T>::New(napi_env env,
1689
1700
  }
1690
1701
 
1691
1702
  template <typename T>
1692
- inline External<T>::External() : Value() {
1693
- }
1703
+ inline External<T>::External() : Value() {}
1694
1704
 
1695
1705
  template <typename T>
1696
- inline External<T>::External(napi_env env, napi_value value) : Value(env, value) {
1697
- }
1706
+ inline External<T>::External(napi_env env, napi_value value)
1707
+ : Value(env, value) {}
1698
1708
 
1699
1709
  template <typename T>
1700
1710
  inline T* External<T>::Data() const {
@@ -1722,11 +1732,9 @@ inline Array Array::New(napi_env env, size_t length) {
1722
1732
  return Array(env, value);
1723
1733
  }
1724
1734
 
1725
- inline Array::Array() : Object() {
1726
- }
1735
+ inline Array::Array() : Object() {}
1727
1736
 
1728
- inline Array::Array(napi_env env, napi_value value) : Object(env, value) {
1729
- }
1737
+ inline Array::Array(napi_env env, napi_value value) : Object(env, value) {}
1730
1738
 
1731
1739
  inline uint32_t Array::Length() const {
1732
1740
  uint32_t result;
@@ -1753,7 +1761,7 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
1753
1761
  size_t byteLength) {
1754
1762
  napi_value value;
1755
1763
  napi_status status = napi_create_external_arraybuffer(
1756
- env, externalData, byteLength, nullptr, nullptr, &value);
1764
+ env, externalData, byteLength, nullptr, nullptr, &value);
1757
1765
  NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
1758
1766
 
1759
1767
  return ArrayBuffer(env, value);
@@ -1769,12 +1777,12 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
1769
1777
  new details::FinalizeData<void, Finalizer>(
1770
1778
  {std::move(finalizeCallback), nullptr});
1771
1779
  napi_status status = napi_create_external_arraybuffer(
1772
- env,
1773
- externalData,
1774
- byteLength,
1775
- details::FinalizeData<void, Finalizer>::Wrapper,
1776
- finalizeData,
1777
- &value);
1780
+ env,
1781
+ externalData,
1782
+ byteLength,
1783
+ details::FinalizeData<void, Finalizer>::Wrapper,
1784
+ finalizeData,
1785
+ &value);
1778
1786
  if (status != napi_ok) {
1779
1787
  delete finalizeData;
1780
1788
  NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
@@ -1794,12 +1802,12 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
1794
1802
  new details::FinalizeData<void, Finalizer, Hint>(
1795
1803
  {std::move(finalizeCallback), finalizeHint});
1796
1804
  napi_status status = napi_create_external_arraybuffer(
1797
- env,
1798
- externalData,
1799
- byteLength,
1800
- details::FinalizeData<void, Finalizer, Hint>::WrapperWithHint,
1801
- finalizeData,
1802
- &value);
1805
+ env,
1806
+ externalData,
1807
+ byteLength,
1808
+ details::FinalizeData<void, Finalizer, Hint>::WrapperWithHint,
1809
+ finalizeData,
1810
+ &value);
1803
1811
  if (status != napi_ok) {
1804
1812
  delete finalizeData;
1805
1813
  NAPI_THROW_IF_FAILED(env, status, ArrayBuffer());
@@ -1808,12 +1816,10 @@ inline ArrayBuffer ArrayBuffer::New(napi_env env,
1808
1816
  return ArrayBuffer(env, value);
1809
1817
  }
1810
1818
 
1811
- inline ArrayBuffer::ArrayBuffer() : Object() {
1812
- }
1819
+ inline ArrayBuffer::ArrayBuffer() : Object() {}
1813
1820
 
1814
1821
  inline ArrayBuffer::ArrayBuffer(napi_env env, napi_value value)
1815
- : Object(env, value) {
1816
- }
1822
+ : Object(env, value) {}
1817
1823
 
1818
1824
  inline void* ArrayBuffer::Data() {
1819
1825
  void* data;
@@ -1824,7 +1830,8 @@ inline void* ArrayBuffer::Data() {
1824
1830
 
1825
1831
  inline size_t ArrayBuffer::ByteLength() {
1826
1832
  size_t length;
1827
- napi_status status = napi_get_arraybuffer_info(_env, _value, nullptr, &length);
1833
+ napi_status status =
1834
+ napi_get_arraybuffer_info(_env, _value, nullptr, &length);
1828
1835
  NAPI_THROW_IF_FAILED(_env, status, 0);
1829
1836
  return length;
1830
1837
  }
@@ -1846,8 +1853,7 @@ inline void ArrayBuffer::Detach() {
1846
1853
  ////////////////////////////////////////////////////////////////////////////////
1847
1854
  // DataView class
1848
1855
  ////////////////////////////////////////////////////////////////////////////////
1849
- inline DataView DataView::New(napi_env env,
1850
- Napi::ArrayBuffer arrayBuffer) {
1856
+ inline DataView DataView::New(napi_env env, Napi::ArrayBuffer arrayBuffer) {
1851
1857
  return New(env, arrayBuffer, 0, arrayBuffer.ByteLength());
1852
1858
  }
1853
1859
 
@@ -1855,12 +1861,12 @@ inline DataView DataView::New(napi_env env,
1855
1861
  Napi::ArrayBuffer arrayBuffer,
1856
1862
  size_t byteOffset) {
1857
1863
  if (byteOffset > arrayBuffer.ByteLength()) {
1858
- NAPI_THROW(RangeError::New(env,
1859
- "Start offset is outside the bounds of the buffer"),
1860
- DataView());
1864
+ NAPI_THROW(RangeError::New(
1865
+ env, "Start offset is outside the bounds of the buffer"),
1866
+ DataView());
1861
1867
  }
1862
- return New(env, arrayBuffer, byteOffset,
1863
- arrayBuffer.ByteLength() - byteOffset);
1868
+ return New(
1869
+ env, arrayBuffer, byteOffset, arrayBuffer.ByteLength() - byteOffset);
1864
1870
  }
1865
1871
 
1866
1872
  inline DataView DataView::New(napi_env env,
@@ -1868,52 +1874,47 @@ inline DataView DataView::New(napi_env env,
1868
1874
  size_t byteOffset,
1869
1875
  size_t byteLength) {
1870
1876
  if (byteOffset + byteLength > arrayBuffer.ByteLength()) {
1871
- NAPI_THROW(RangeError::New(env, "Invalid DataView length"),
1872
- DataView());
1877
+ NAPI_THROW(RangeError::New(env, "Invalid DataView length"), DataView());
1873
1878
  }
1874
1879
  napi_value value;
1875
- napi_status status = napi_create_dataview(
1876
- env, byteLength, arrayBuffer, byteOffset, &value);
1880
+ napi_status status =
1881
+ napi_create_dataview(env, byteLength, arrayBuffer, byteOffset, &value);
1877
1882
  NAPI_THROW_IF_FAILED(env, status, DataView());
1878
1883
  return DataView(env, value);
1879
1884
  }
1880
1885
 
1881
- inline DataView::DataView() : Object() {
1882
- }
1886
+ inline DataView::DataView() : Object() {}
1883
1887
 
1884
1888
  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 */);
1889
+ napi_status status = napi_get_dataview_info(_env,
1890
+ _value /* dataView */,
1891
+ &_length /* byteLength */,
1892
+ &_data /* data */,
1893
+ nullptr /* arrayBuffer */,
1894
+ nullptr /* byteOffset */);
1892
1895
  NAPI_THROW_IF_FAILED_VOID(_env, status);
1893
1896
  }
1894
1897
 
1895
1898
  inline Napi::ArrayBuffer DataView::ArrayBuffer() const {
1896
1899
  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 */);
1900
+ napi_status status = napi_get_dataview_info(_env,
1901
+ _value /* dataView */,
1902
+ nullptr /* byteLength */,
1903
+ nullptr /* data */,
1904
+ &arrayBuffer /* arrayBuffer */,
1905
+ nullptr /* byteOffset */);
1904
1906
  NAPI_THROW_IF_FAILED(_env, status, Napi::ArrayBuffer());
1905
1907
  return Napi::ArrayBuffer(_env, arrayBuffer);
1906
1908
  }
1907
1909
 
1908
1910
  inline size_t DataView::ByteOffset() const {
1909
1911
  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 */);
1912
+ napi_status status = napi_get_dataview_info(_env,
1913
+ _value /* dataView */,
1914
+ nullptr /* byteLength */,
1915
+ nullptr /* data */,
1916
+ nullptr /* arrayBuffer */,
1917
+ &byteOffset /* byteOffset */);
1917
1918
  NAPI_THROW_IF_FAILED(_env, status, 0);
1918
1919
  return byteOffset;
1919
1920
  }
@@ -1994,8 +1995,9 @@ template <typename T>
1994
1995
  inline T DataView::ReadData(size_t byteOffset) const {
1995
1996
  if (byteOffset + sizeof(T) > _length ||
1996
1997
  byteOffset + sizeof(T) < byteOffset) { // overflow
1997
- NAPI_THROW(RangeError::New(_env,
1998
- "Offset is outside the bounds of the DataView"), 0);
1998
+ NAPI_THROW(
1999
+ RangeError::New(_env, "Offset is outside the bounds of the DataView"),
2000
+ 0);
1999
2001
  }
2000
2002
 
2001
2003
  return *reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset);
@@ -2005,8 +2007,8 @@ template <typename T>
2005
2007
  inline void DataView::WriteData(size_t byteOffset, T value) const {
2006
2008
  if (byteOffset + sizeof(T) > _length ||
2007
2009
  byteOffset + sizeof(T) < byteOffset) { // overflow
2008
- NAPI_THROW_VOID(RangeError::New(_env,
2009
- "Offset is outside the bounds of the DataView"));
2010
+ NAPI_THROW_VOID(
2011
+ RangeError::New(_env, "Offset is outside the bounds of the DataView"));
2010
2012
  }
2011
2013
 
2012
2014
  *reinterpret_cast<T*>(static_cast<uint8_t*>(_data) + byteOffset) = value;
@@ -2017,33 +2019,37 @@ inline void DataView::WriteData(size_t byteOffset, T value) const {
2017
2019
  ////////////////////////////////////////////////////////////////////////////////
2018
2020
 
2019
2021
  inline TypedArray::TypedArray()
2020
- : Object(), _type(TypedArray::unknown_array_type), _length(0) {
2021
- }
2022
+ : Object(), _type(napi_typedarray_type::napi_int8_array), _length(0) {}
2022
2023
 
2023
2024
  inline TypedArray::TypedArray(napi_env env, napi_value value)
2024
- : Object(env, value), _type(TypedArray::unknown_array_type), _length(0) {
2025
+ : Object(env, value),
2026
+ _type(napi_typedarray_type::napi_int8_array),
2027
+ _length(0) {
2028
+ if (value != nullptr) {
2029
+ napi_status status =
2030
+ napi_get_typedarray_info(_env,
2031
+ _value,
2032
+ &const_cast<TypedArray*>(this)->_type,
2033
+ &const_cast<TypedArray*>(this)->_length,
2034
+ nullptr,
2035
+ nullptr,
2036
+ nullptr);
2037
+ NAPI_THROW_IF_FAILED_VOID(_env, status);
2038
+ }
2025
2039
  }
2026
2040
 
2027
2041
  inline TypedArray::TypedArray(napi_env env,
2028
2042
  napi_value value,
2029
2043
  napi_typedarray_type type,
2030
2044
  size_t length)
2031
- : Object(env, value), _type(type), _length(length) {
2032
- }
2045
+ : Object(env, value), _type(type), _length(length) {}
2033
2046
 
2034
2047
  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
2048
  return _type;
2043
2049
  }
2044
2050
 
2045
2051
  inline uint8_t TypedArray::ElementSize() const {
2046
- switch (TypedArrayType()) {
2052
+ switch (_type) {
2047
2053
  case napi_int8_array:
2048
2054
  case napi_uint8_array:
2049
2055
  case napi_uint8_clamped_array:
@@ -2067,20 +2073,13 @@ inline uint8_t TypedArray::ElementSize() const {
2067
2073
  }
2068
2074
 
2069
2075
  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
2076
  return _length;
2078
2077
  }
2079
2078
 
2080
2079
  inline size_t TypedArray::ByteOffset() const {
2081
2080
  size_t byteOffset;
2082
2081
  napi_status status = napi_get_typedarray_info(
2083
- _env, _value, nullptr, nullptr, nullptr, nullptr, &byteOffset);
2082
+ _env, _value, nullptr, nullptr, nullptr, nullptr, &byteOffset);
2084
2083
  NAPI_THROW_IF_FAILED(_env, status, 0);
2085
2084
  return byteOffset;
2086
2085
  }
@@ -2092,7 +2091,7 @@ inline size_t TypedArray::ByteLength() const {
2092
2091
  inline Napi::ArrayBuffer TypedArray::ArrayBuffer() const {
2093
2092
  napi_value arrayBuffer;
2094
2093
  napi_status status = napi_get_typedarray_info(
2095
- _env, _value, nullptr, nullptr, nullptr, &arrayBuffer, nullptr);
2094
+ _env, _value, nullptr, nullptr, nullptr, &arrayBuffer, nullptr);
2096
2095
  NAPI_THROW_IF_FAILED(_env, status, Napi::ArrayBuffer());
2097
2096
  return Napi::ArrayBuffer(_env, arrayBuffer);
2098
2097
  }
@@ -2105,7 +2104,8 @@ template <typename T>
2105
2104
  inline TypedArrayOf<T> TypedArrayOf<T>::New(napi_env env,
2106
2105
  size_t elementLength,
2107
2106
  napi_typedarray_type type) {
2108
- Napi::ArrayBuffer arrayBuffer = Napi::ArrayBuffer::New(env, elementLength * sizeof (T));
2107
+ Napi::ArrayBuffer arrayBuffer =
2108
+ Napi::ArrayBuffer::New(env, elementLength * sizeof(T));
2109
2109
  return New(env, elementLength, arrayBuffer, 0, type);
2110
2110
  }
2111
2111
 
@@ -2117,21 +2117,24 @@ inline TypedArrayOf<T> TypedArrayOf<T>::New(napi_env env,
2117
2117
  napi_typedarray_type type) {
2118
2118
  napi_value value;
2119
2119
  napi_status status = napi_create_typedarray(
2120
- env, type, elementLength, arrayBuffer, bufferOffset, &value);
2120
+ env, type, elementLength, arrayBuffer, bufferOffset, &value);
2121
2121
  NAPI_THROW_IF_FAILED(env, status, TypedArrayOf<T>());
2122
2122
 
2123
2123
  return TypedArrayOf<T>(
2124
- env, value, type, elementLength,
2125
- reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(arrayBuffer.Data()) + bufferOffset));
2124
+ env,
2125
+ value,
2126
+ type,
2127
+ elementLength,
2128
+ reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(arrayBuffer.Data()) +
2129
+ bufferOffset));
2126
2130
  }
2127
2131
 
2128
2132
  template <typename T>
2129
- inline TypedArrayOf<T>::TypedArrayOf() : TypedArray(), _data(nullptr) {
2130
- }
2133
+ inline TypedArrayOf<T>::TypedArrayOf() : TypedArray(), _data(nullptr) {}
2131
2134
 
2132
2135
  template <typename T>
2133
2136
  inline TypedArrayOf<T>::TypedArrayOf(napi_env env, napi_value value)
2134
- : TypedArray(env, value), _data(nullptr) {
2137
+ : TypedArray(env, value), _data(nullptr) {
2135
2138
  napi_status status = napi_ok;
2136
2139
  if (value != nullptr) {
2137
2140
  void* data = nullptr;
@@ -2151,21 +2154,24 @@ inline TypedArrayOf<T>::TypedArrayOf(napi_env env,
2151
2154
  napi_typedarray_type type,
2152
2155
  size_t length,
2153
2156
  T* data)
2154
- : TypedArray(env, value, type, length), _data(data) {
2157
+ : TypedArray(env, value, type, length), _data(data) {
2155
2158
  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.)"));
2159
+ (type == napi_uint8_clamped_array &&
2160
+ std::is_same<T, uint8_t>::value))) {
2161
+ NAPI_THROW_VOID(TypeError::New(
2162
+ env,
2163
+ "Array type must match the template parameter. "
2164
+ "(Uint8 arrays may optionally have the \"clamped\" array type.)"));
2159
2165
  }
2160
2166
  }
2161
2167
 
2162
2168
  template <typename T>
2163
- inline T& TypedArrayOf<T>::operator [](size_t index) {
2169
+ inline T& TypedArrayOf<T>::operator[](size_t index) {
2164
2170
  return _data[index];
2165
2171
  }
2166
2172
 
2167
2173
  template <typename T>
2168
- inline const T& TypedArrayOf<T>::operator [](size_t index) const {
2174
+ inline const T& TypedArrayOf<T>::operator[](size_t index) const {
2169
2175
  return _data[index];
2170
2176
  }
2171
2177
 
@@ -2184,12 +2190,11 @@ inline const T* TypedArrayOf<T>::Data() const {
2184
2190
  ////////////////////////////////////////////////////////////////////////////////
2185
2191
 
2186
2192
  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) {
2193
+ inline napi_status CreateFunction(napi_env env,
2194
+ const char* utf8name,
2195
+ napi_callback cb,
2196
+ CbData* data,
2197
+ napi_value* result) {
2193
2198
  napi_status status =
2194
2199
  napi_create_function(env, utf8name, NAPI_AUTO_LENGTH, cb, data, result);
2195
2200
  if (status == napi_ok) {
@@ -2249,11 +2254,8 @@ inline Function Function::New(napi_env env,
2249
2254
  auto callbackData = new CbData{std::move(cb), data};
2250
2255
 
2251
2256
  napi_value value;
2252
- napi_status status = CreateFunction(env,
2253
- utf8name,
2254
- CbData::Wrapper,
2255
- callbackData,
2256
- &value);
2257
+ napi_status status =
2258
+ CreateFunction(env, utf8name, CbData::Wrapper, callbackData, &value);
2257
2259
  if (status != napi_ok) {
2258
2260
  delete callbackData;
2259
2261
  NAPI_THROW_IF_FAILED(env, status, Function());
@@ -2270,11 +2272,10 @@ inline Function Function::New(napi_env env,
2270
2272
  return New(env, cb, utf8name.c_str(), data);
2271
2273
  }
2272
2274
 
2273
- inline Function::Function() : Object() {
2274
- }
2275
+ inline Function::Function() : Object() {}
2275
2276
 
2276
- inline Function::Function(napi_env env, napi_value value) : Object(env, value) {
2277
- }
2277
+ inline Function::Function(napi_env env, napi_value value)
2278
+ : Object(env, value) {}
2278
2279
 
2279
2280
  inline MaybeOrValue<Value> Function::operator()(
2280
2281
  const std::initializer_list<napi_value>& args) const {
@@ -2336,8 +2337,8 @@ inline MaybeOrValue<Value> Function::Call(napi_value recv,
2336
2337
  size_t argc,
2337
2338
  const napi_value* args) const {
2338
2339
  napi_value result;
2339
- napi_status status = napi_call_function(
2340
- _env, recv, _value, argc, args, &result);
2340
+ napi_status status =
2341
+ napi_call_function(_env, recv, _value, argc, args, &result);
2341
2342
  NAPI_RETURN_OR_THROW_IF_FAILED(
2342
2343
  _env, status, Napi::Value(_env, result), Napi::Value);
2343
2344
  }
@@ -2362,8 +2363,8 @@ inline MaybeOrValue<Value> Function::MakeCallback(
2362
2363
  const napi_value* args,
2363
2364
  napi_async_context context) const {
2364
2365
  napi_value result;
2365
- napi_status status = napi_make_callback(
2366
- _env, context, recv, _value, argc, args, &result);
2366
+ napi_status status =
2367
+ napi_make_callback(_env, context, recv, _value, argc, args, &result);
2367
2368
  NAPI_RETURN_OR_THROW_IF_FAILED(
2368
2369
  _env, status, Napi::Value(_env, result), Napi::Value);
2369
2370
  }
@@ -2381,8 +2382,7 @@ inline MaybeOrValue<Object> Function::New(
2381
2382
  inline MaybeOrValue<Object> Function::New(size_t argc,
2382
2383
  const napi_value* args) const {
2383
2384
  napi_value result;
2384
- napi_status status = napi_new_instance(
2385
- _env, _value, argc, args, &result);
2385
+ napi_status status = napi_new_instance(_env, _value, argc, args, &result);
2386
2386
  NAPI_RETURN_OR_THROW_IF_FAILED(
2387
2387
  _env, status, Napi::Object(_env, result), Napi::Object);
2388
2388
  }
@@ -2418,8 +2418,7 @@ inline void Promise::Deferred::Reject(napi_value value) const {
2418
2418
  NAPI_THROW_IF_FAILED_VOID(_env, status);
2419
2419
  }
2420
2420
 
2421
- inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {
2422
- }
2421
+ inline Promise::Promise(napi_env env, napi_value value) : Object(env, value) {}
2423
2422
 
2424
2423
  ////////////////////////////////////////////////////////////////////////////////
2425
2424
  // Buffer<T> class
@@ -2429,7 +2428,8 @@ template <typename T>
2429
2428
  inline Buffer<T> Buffer<T>::New(napi_env env, size_t length) {
2430
2429
  napi_value value;
2431
2430
  void* data;
2432
- napi_status status = napi_create_buffer(env, length * sizeof (T), &data, &value);
2431
+ napi_status status =
2432
+ napi_create_buffer(env, length * sizeof(T), &data, &value);
2433
2433
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2434
2434
  return Buffer(env, value, length, static_cast<T*>(data));
2435
2435
  }
@@ -2438,7 +2438,7 @@ template <typename T>
2438
2438
  inline Buffer<T> Buffer<T>::New(napi_env env, T* data, size_t length) {
2439
2439
  napi_value value;
2440
2440
  napi_status status = napi_create_external_buffer(
2441
- env, length * sizeof (T), data, nullptr, nullptr, &value);
2441
+ env, length * sizeof(T), data, nullptr, nullptr, &value);
2442
2442
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2443
2443
  return Buffer(env, value, length, data);
2444
2444
  }
@@ -2453,13 +2453,13 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
2453
2453
  details::FinalizeData<T, Finalizer>* finalizeData =
2454
2454
  new details::FinalizeData<T, Finalizer>(
2455
2455
  {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);
2456
+ napi_status status =
2457
+ napi_create_external_buffer(env,
2458
+ length * sizeof(T),
2459
+ data,
2460
+ details::FinalizeData<T, Finalizer>::Wrapper,
2461
+ finalizeData,
2462
+ &value);
2463
2463
  if (status != napi_ok) {
2464
2464
  delete finalizeData;
2465
2465
  NAPI_THROW_IF_FAILED(env, status, Buffer());
@@ -2479,12 +2479,12 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
2479
2479
  new details::FinalizeData<T, Finalizer, Hint>(
2480
2480
  {std::move(finalizeCallback), finalizeHint});
2481
2481
  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);
2482
+ env,
2483
+ length * sizeof(T),
2484
+ data,
2485
+ details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
2486
+ finalizeData,
2487
+ &value);
2488
2488
  if (status != napi_ok) {
2489
2489
  delete finalizeData;
2490
2490
  NAPI_THROW_IF_FAILED(env, status, Buffer());
@@ -2495,25 +2495,22 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
2495
2495
  template <typename T>
2496
2496
  inline Buffer<T> Buffer<T>::Copy(napi_env env, const T* data, size_t length) {
2497
2497
  napi_value value;
2498
- napi_status status = napi_create_buffer_copy(
2499
- env, length * sizeof (T), data, nullptr, &value);
2498
+ napi_status status =
2499
+ napi_create_buffer_copy(env, length * sizeof(T), data, nullptr, &value);
2500
2500
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2501
2501
  return Buffer<T>(env, value);
2502
2502
  }
2503
2503
 
2504
2504
  template <typename T>
2505
- inline Buffer<T>::Buffer() : Uint8Array(), _length(0), _data(nullptr) {
2506
- }
2505
+ inline Buffer<T>::Buffer() : Uint8Array(), _length(0), _data(nullptr) {}
2507
2506
 
2508
2507
  template <typename T>
2509
2508
  inline Buffer<T>::Buffer(napi_env env, napi_value value)
2510
- : Uint8Array(env, value), _length(0), _data(nullptr) {
2511
- }
2509
+ : Uint8Array(env, value), _length(0), _data(nullptr) {}
2512
2510
 
2513
2511
  template <typename T>
2514
2512
  inline Buffer<T>::Buffer(napi_env env, napi_value value, size_t length, T* data)
2515
- : Uint8Array(env, value), _length(length), _data(data) {
2516
- }
2513
+ : Uint8Array(env, value), _length(length), _data(data) {}
2517
2514
 
2518
2515
  template <typename T>
2519
2516
  inline size_t Buffer<T>::Length() const {
@@ -2535,9 +2532,10 @@ inline void Buffer<T>::EnsureInfo() const {
2535
2532
  if (_data == nullptr) {
2536
2533
  size_t byteLength;
2537
2534
  void* voidData;
2538
- napi_status status = napi_get_buffer_info(_env, _value, &voidData, &byteLength);
2535
+ napi_status status =
2536
+ napi_get_buffer_info(_env, _value, &voidData, &byteLength);
2539
2537
  NAPI_THROW_IF_FAILED_VOID(_env, status);
2540
- _length = byteLength / sizeof (T);
2538
+ _length = byteLength / sizeof(T);
2541
2539
  _data = static_cast<T*>(voidData);
2542
2540
  }
2543
2541
  }
@@ -2574,19 +2572,16 @@ inline Error Error::New(napi_env env) {
2574
2572
  // A pending exception takes precedence over any internal error status.
2575
2573
  if (is_exception_pending) {
2576
2574
  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 {
2575
+ NAPI_FATAL_IF_FAILED(
2576
+ status, "Error::New", "napi_get_and_clear_last_exception");
2577
+ } else {
2580
2578
  const char* error_message = last_error_info_copy.error_message != nullptr
2581
2579
  ? last_error_info_copy.error_message
2582
2580
  : "Error in native callback";
2583
2581
 
2584
2582
  napi_value message;
2585
2583
  status = napi_create_string_utf8(
2586
- env,
2587
- error_message,
2588
- std::strlen(error_message),
2589
- &message);
2584
+ env, error_message, std::strlen(error_message), &message);
2590
2585
  NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_create_string_utf8");
2591
2586
 
2592
2587
  switch (last_error_info_copy.error_code) {
@@ -2607,21 +2602,24 @@ inline Error Error::New(napi_env env) {
2607
2602
  }
2608
2603
 
2609
2604
  inline Error Error::New(napi_env env, const char* message) {
2610
- return Error::New<Error>(env, message, std::strlen(message), napi_create_error);
2605
+ return Error::New<Error>(
2606
+ env, message, std::strlen(message), napi_create_error);
2611
2607
  }
2612
2608
 
2613
2609
  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);
2610
+ return Error::New<Error>(
2611
+ env, message.c_str(), message.size(), napi_create_error);
2615
2612
  }
2616
2613
 
2617
- inline NAPI_NO_RETURN void Error::Fatal(const char* location, const char* message) {
2614
+ inline NAPI_NO_RETURN void Error::Fatal(const char* location,
2615
+ const char* message) {
2618
2616
  napi_fatal_error(location, NAPI_AUTO_LENGTH, message, NAPI_AUTO_LENGTH);
2619
2617
  }
2620
2618
 
2621
- inline Error::Error() : ObjectReference() {
2622
- }
2619
+ inline Error::Error() : ObjectReference() {}
2623
2620
 
2624
- inline Error::Error(napi_env env, napi_value value) : ObjectReference(env, nullptr) {
2621
+ inline Error::Error(napi_env env, napi_value value)
2622
+ : ObjectReference(env, nullptr) {
2625
2623
  if (value != nullptr) {
2626
2624
  // Attempting to create a reference on the error object.
2627
2625
  // If it's not a Object/Function/Symbol, this call will return an error
@@ -2699,18 +2697,16 @@ inline Object Error::Value() const {
2699
2697
  return Object(_env, refValue);
2700
2698
  }
2701
2699
 
2702
- inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {
2703
- }
2700
+ inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {}
2704
2701
 
2705
- inline Error& Error::operator =(Error&& other) {
2702
+ inline Error& Error::operator=(Error&& other) {
2706
2703
  static_cast<Reference<Object>*>(this)->operator=(std::move(other));
2707
2704
  return *this;
2708
2705
  }
2709
2706
 
2710
- inline Error::Error(const Error& other) : ObjectReference(other) {
2711
- }
2707
+ inline Error::Error(const Error& other) : ObjectReference(other) {}
2712
2708
 
2713
- inline Error& Error::operator =(const Error& other) {
2709
+ inline Error& Error::operator=(const Error& other) {
2714
2710
  Reset();
2715
2711
 
2716
2712
  _env = other.Env();
@@ -2730,12 +2726,11 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
2730
2726
  #ifdef NAPI_CPP_EXCEPTIONS
2731
2727
  try {
2732
2728
  _message = Get("message").As<String>();
2733
- }
2734
- catch (...) {
2729
+ } catch (...) {
2735
2730
  // Catch all errors here, to include e.g. a std::bad_alloc from
2736
2731
  // the std::string::operator=, because this method may not throw.
2737
2732
  }
2738
- #else // NAPI_CPP_EXCEPTIONS
2733
+ #else // NAPI_CPP_EXCEPTIONS
2739
2734
  #if defined(NODE_ADDON_API_ENABLE_MAYBE)
2740
2735
  Napi::Value message_val;
2741
2736
  if (Get("message").UnwrapTo(&message_val)) {
@@ -2744,7 +2739,7 @@ inline const std::string& Error::Message() const NAPI_NOEXCEPT {
2744
2739
  #else
2745
2740
  _message = Get("message").As<String>();
2746
2741
  #endif
2747
- #endif // NAPI_CPP_EXCEPTIONS
2742
+ #endif // NAPI_CPP_EXCEPTIONS
2748
2743
  }
2749
2744
  return _message;
2750
2745
  }
@@ -2790,9 +2785,10 @@ inline void Error::ThrowAsJavaScriptException() const {
2790
2785
  if (status != napi_ok) {
2791
2786
  throw Error::New(_env);
2792
2787
  }
2793
- #else // NAPI_CPP_EXCEPTIONS
2794
- NAPI_FATAL_IF_FAILED(status, "Error::ThrowAsJavaScriptException", "napi_throw");
2795
- #endif // NAPI_CPP_EXCEPTIONS
2788
+ #else // NAPI_CPP_EXCEPTIONS
2789
+ NAPI_FATAL_IF_FAILED(
2790
+ status, "Error::ThrowAsJavaScriptException", "napi_throw");
2791
+ #endif // NAPI_CPP_EXCEPTIONS
2796
2792
  }
2797
2793
  }
2798
2794
 
@@ -2802,7 +2798,7 @@ inline const char* Error::what() const NAPI_NOEXCEPT {
2802
2798
  return Message().c_str();
2803
2799
  }
2804
2800
 
2805
- #endif // NAPI_CPP_EXCEPTIONS
2801
+ #endif // NAPI_CPP_EXCEPTIONS
2806
2802
 
2807
2803
  inline const char* Error::ERROR_WRAP_VALUE() NAPI_NOEXCEPT {
2808
2804
  return "4bda9e7e-4913-4dbc-95de-891cbf66598e-errorVal";
@@ -2825,39 +2821,42 @@ inline TError Error::New(napi_env env,
2825
2821
  }
2826
2822
 
2827
2823
  inline TypeError TypeError::New(napi_env env, const char* message) {
2828
- return Error::New<TypeError>(env, message, std::strlen(message), napi_create_type_error);
2824
+ return Error::New<TypeError>(
2825
+ env, message, std::strlen(message), napi_create_type_error);
2829
2826
  }
2830
2827
 
2831
2828
  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);
2829
+ return Error::New<TypeError>(
2830
+ env, message.c_str(), message.size(), napi_create_type_error);
2833
2831
  }
2834
2832
 
2835
- inline TypeError::TypeError() : Error() {
2836
- }
2833
+ inline TypeError::TypeError() : Error() {}
2837
2834
 
2838
- inline TypeError::TypeError(napi_env env, napi_value value) : Error(env, value) {
2839
- }
2835
+ inline TypeError::TypeError(napi_env env, napi_value value)
2836
+ : Error(env, value) {}
2840
2837
 
2841
2838
  inline RangeError RangeError::New(napi_env env, const char* message) {
2842
- return Error::New<RangeError>(env, message, std::strlen(message), napi_create_range_error);
2839
+ return Error::New<RangeError>(
2840
+ env, message, std::strlen(message), napi_create_range_error);
2843
2841
  }
2844
2842
 
2845
2843
  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);
2844
+ return Error::New<RangeError>(
2845
+ env, message.c_str(), message.size(), napi_create_range_error);
2847
2846
  }
2848
2847
 
2849
- inline RangeError::RangeError() : Error() {
2850
- }
2848
+ inline RangeError::RangeError() : Error() {}
2851
2849
 
2852
- inline RangeError::RangeError(napi_env env, napi_value value) : Error(env, value) {
2853
- }
2850
+ inline RangeError::RangeError(napi_env env, napi_value value)
2851
+ : Error(env, value) {}
2854
2852
 
2855
2853
  ////////////////////////////////////////////////////////////////////////////////
2856
2854
  // Reference<T> class
2857
2855
  ////////////////////////////////////////////////////////////////////////////////
2858
2856
 
2859
2857
  template <typename T>
2860
- inline Reference<T> Reference<T>::New(const T& value, uint32_t initialRefcount) {
2858
+ inline Reference<T> Reference<T>::New(const T& value,
2859
+ uint32_t initialRefcount) {
2861
2860
  napi_env env = value.Env();
2862
2861
  napi_value val = value;
2863
2862
 
@@ -2872,15 +2871,13 @@ inline Reference<T> Reference<T>::New(const T& value, uint32_t initialRefcount)
2872
2871
  return Reference<T>(env, ref);
2873
2872
  }
2874
2873
 
2875
-
2876
2874
  template <typename T>
2877
- inline Reference<T>::Reference() : _env(nullptr), _ref(nullptr), _suppressDestruct(false) {
2878
- }
2875
+ inline Reference<T>::Reference()
2876
+ : _env(nullptr), _ref(nullptr), _suppressDestruct(false) {}
2879
2877
 
2880
2878
  template <typename T>
2881
2879
  inline Reference<T>::Reference(napi_env env, napi_ref ref)
2882
- : _env(env), _ref(ref), _suppressDestruct(false) {
2883
- }
2880
+ : _env(env), _ref(ref), _suppressDestruct(false) {}
2884
2881
 
2885
2882
  template <typename T>
2886
2883
  inline Reference<T>::~Reference() {
@@ -2895,14 +2892,16 @@ inline Reference<T>::~Reference() {
2895
2892
 
2896
2893
  template <typename T>
2897
2894
  inline Reference<T>::Reference(Reference<T>&& other)
2898
- : _env(other._env), _ref(other._ref), _suppressDestruct(other._suppressDestruct) {
2895
+ : _env(other._env),
2896
+ _ref(other._ref),
2897
+ _suppressDestruct(other._suppressDestruct) {
2899
2898
  other._env = nullptr;
2900
2899
  other._ref = nullptr;
2901
2900
  other._suppressDestruct = false;
2902
2901
  }
2903
2902
 
2904
2903
  template <typename T>
2905
- inline Reference<T>& Reference<T>::operator =(Reference<T>&& other) {
2904
+ inline Reference<T>& Reference<T>::operator=(Reference<T>&& other) {
2906
2905
  Reset();
2907
2906
  _env = other._env;
2908
2907
  _ref = other._ref;
@@ -2915,15 +2914,17 @@ inline Reference<T>& Reference<T>::operator =(Reference<T>&& other) {
2915
2914
 
2916
2915
  template <typename T>
2917
2916
  inline Reference<T>::Reference(const Reference<T>& other)
2918
- : _env(other._env), _ref(nullptr), _suppressDestruct(false) {
2917
+ : _env(other._env), _ref(nullptr), _suppressDestruct(false) {
2919
2918
  HandleScope scope(_env);
2920
2919
 
2921
2920
  napi_value value = other.Value();
2922
2921
  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.
2922
+ // Copying is a limited scenario (currently only used for Error object) and
2923
+ // always creates a strong reference to the given value even if the incoming
2924
+ // reference is weak.
2925
2925
  napi_status status = napi_create_reference(_env, value, 1, &_ref);
2926
- NAPI_FATAL_IF_FAILED(status, "Reference<T>::Reference", "napi_create_reference");
2926
+ NAPI_FATAL_IF_FAILED(
2927
+ status, "Reference<T>::Reference", "napi_create_reference");
2927
2928
  }
2928
2929
  }
2929
2930
 
@@ -2933,14 +2934,14 @@ inline Reference<T>::operator napi_ref() const {
2933
2934
  }
2934
2935
 
2935
2936
  template <typename T>
2936
- inline bool Reference<T>::operator ==(const Reference<T> &other) const {
2937
+ inline bool Reference<T>::operator==(const Reference<T>& other) const {
2937
2938
  HandleScope scope(_env);
2938
2939
  return this->Value().StrictEquals(other.Value());
2939
2940
  }
2940
2941
 
2941
2942
  template <typename T>
2942
- inline bool Reference<T>::operator !=(const Reference<T> &other) const {
2943
- return !this->operator ==(other);
2943
+ inline bool Reference<T>::operator!=(const Reference<T>& other) const {
2944
+ return !this->operator==(other);
2944
2945
  }
2945
2946
 
2946
2947
  template <typename T>
@@ -3037,33 +3038,29 @@ inline FunctionReference Persistent(Function value) {
3037
3038
  // ObjectReference class
3038
3039
  ////////////////////////////////////////////////////////////////////////////////
3039
3040
 
3040
- inline ObjectReference::ObjectReference(): Reference<Object>() {
3041
- }
3041
+ inline ObjectReference::ObjectReference() : Reference<Object>() {}
3042
3042
 
3043
- inline ObjectReference::ObjectReference(napi_env env, napi_ref ref): Reference<Object>(env, ref) {
3044
- }
3043
+ inline ObjectReference::ObjectReference(napi_env env, napi_ref ref)
3044
+ : Reference<Object>(env, ref) {}
3045
3045
 
3046
3046
  inline ObjectReference::ObjectReference(Reference<Object>&& other)
3047
- : Reference<Object>(std::move(other)) {
3048
- }
3047
+ : Reference<Object>(std::move(other)) {}
3049
3048
 
3050
- inline ObjectReference& ObjectReference::operator =(Reference<Object>&& other) {
3049
+ inline ObjectReference& ObjectReference::operator=(Reference<Object>&& other) {
3051
3050
  static_cast<Reference<Object>*>(this)->operator=(std::move(other));
3052
3051
  return *this;
3053
3052
  }
3054
3053
 
3055
3054
  inline ObjectReference::ObjectReference(ObjectReference&& other)
3056
- : Reference<Object>(std::move(other)) {
3057
- }
3055
+ : Reference<Object>(std::move(other)) {}
3058
3056
 
3059
- inline ObjectReference& ObjectReference::operator =(ObjectReference&& other) {
3057
+ inline ObjectReference& ObjectReference::operator=(ObjectReference&& other) {
3060
3058
  static_cast<Reference<Object>*>(this)->operator=(std::move(other));
3061
3059
  return *this;
3062
3060
  }
3063
3061
 
3064
3062
  inline ObjectReference::ObjectReference(const ObjectReference& other)
3065
- : Reference<Object>(other) {
3066
- }
3063
+ : Reference<Object>(other) {}
3067
3064
 
3068
3065
  inline MaybeOrValue<Napi::Value> ObjectReference::Get(
3069
3066
  const char* utf8name) const {
@@ -3215,27 +3212,25 @@ inline MaybeOrValue<bool> ObjectReference::Set(uint32_t index,
3215
3212
  // FunctionReference class
3216
3213
  ////////////////////////////////////////////////////////////////////////////////
3217
3214
 
3218
- inline FunctionReference::FunctionReference(): Reference<Function>() {
3219
- }
3215
+ inline FunctionReference::FunctionReference() : Reference<Function>() {}
3220
3216
 
3221
3217
  inline FunctionReference::FunctionReference(napi_env env, napi_ref ref)
3222
- : Reference<Function>(env, ref) {
3223
- }
3218
+ : Reference<Function>(env, ref) {}
3224
3219
 
3225
3220
  inline FunctionReference::FunctionReference(Reference<Function>&& other)
3226
- : Reference<Function>(std::move(other)) {
3227
- }
3221
+ : Reference<Function>(std::move(other)) {}
3228
3222
 
3229
- inline FunctionReference& FunctionReference::operator =(Reference<Function>&& other) {
3223
+ inline FunctionReference& FunctionReference::operator=(
3224
+ Reference<Function>&& other) {
3230
3225
  static_cast<Reference<Function>*>(this)->operator=(std::move(other));
3231
3226
  return *this;
3232
3227
  }
3233
3228
 
3234
3229
  inline FunctionReference::FunctionReference(FunctionReference&& other)
3235
- : Reference<Function>(std::move(other)) {
3236
- }
3230
+ : Reference<Function>(std::move(other)) {}
3237
3231
 
3238
- inline FunctionReference& FunctionReference::operator =(FunctionReference&& other) {
3232
+ inline FunctionReference& FunctionReference::operator=(
3233
+ FunctionReference&& other) {
3239
3234
  static_cast<Reference<Function>*>(this)->operator=(std::move(other));
3240
3235
  return *this;
3241
3236
  }
@@ -3441,10 +3436,15 @@ inline MaybeOrValue<Object> FunctionReference::New(
3441
3436
  ////////////////////////////////////////////////////////////////////////////////
3442
3437
 
3443
3438
  inline CallbackInfo::CallbackInfo(napi_env env, napi_callback_info info)
3444
- : _env(env), _info(info), _this(nullptr), _dynamicArgs(nullptr), _data(nullptr) {
3439
+ : _env(env),
3440
+ _info(info),
3441
+ _this(nullptr),
3442
+ _dynamicArgs(nullptr),
3443
+ _data(nullptr) {
3445
3444
  _argc = _staticArgCount;
3446
3445
  _argv = _staticArgs;
3447
- napi_status status = napi_get_cb_info(env, info, &_argc, _argv, &_this, &_data);
3446
+ napi_status status =
3447
+ napi_get_cb_info(env, info, &_argc, _argv, &_this, &_data);
3448
3448
  NAPI_THROW_IF_FAILED_VOID(_env, status);
3449
3449
 
3450
3450
  if (_argc > _staticArgCount) {
@@ -3464,6 +3464,10 @@ inline CallbackInfo::~CallbackInfo() {
3464
3464
  }
3465
3465
  }
3466
3466
 
3467
+ inline CallbackInfo::operator napi_callback_info() const {
3468
+ return _info;
3469
+ }
3470
+
3467
3471
  inline Value CallbackInfo::NewTarget() const {
3468
3472
  napi_value newTarget;
3469
3473
  napi_status status = napi_get_new_target(_env, _info, &newTarget);
@@ -3483,7 +3487,7 @@ inline size_t CallbackInfo::Length() const {
3483
3487
  return _argc;
3484
3488
  }
3485
3489
 
3486
- inline const Value CallbackInfo::operator [](size_t index) const {
3490
+ inline const Value CallbackInfo::operator[](size_t index) const {
3487
3491
  return index < _argc ? Value(_env, _argv[index]) : Env().Undefined();
3488
3492
  }
3489
3493
 
@@ -3507,10 +3511,8 @@ inline void CallbackInfo::SetData(void* data) {
3507
3511
  ////////////////////////////////////////////////////////////////////////////////
3508
3512
 
3509
3513
  template <typename PropertyDescriptor::GetterCallback Getter>
3510
- PropertyDescriptor
3511
- PropertyDescriptor::Accessor(const char* utf8name,
3512
- napi_property_attributes attributes,
3513
- void* data) {
3514
+ PropertyDescriptor PropertyDescriptor::Accessor(
3515
+ const char* utf8name, napi_property_attributes attributes, void* data) {
3514
3516
  napi_property_descriptor desc = napi_property_descriptor();
3515
3517
 
3516
3518
  desc.utf8name = utf8name;
@@ -3522,18 +3524,16 @@ PropertyDescriptor::Accessor(const char* utf8name,
3522
3524
  }
3523
3525
 
3524
3526
  template <typename PropertyDescriptor::GetterCallback Getter>
3525
- PropertyDescriptor
3526
- PropertyDescriptor::Accessor(const std::string& utf8name,
3527
- napi_property_attributes attributes,
3528
- void* data) {
3527
+ PropertyDescriptor PropertyDescriptor::Accessor(
3528
+ const std::string& utf8name,
3529
+ napi_property_attributes attributes,
3530
+ void* data) {
3529
3531
  return Accessor<Getter>(utf8name.c_str(), attributes, data);
3530
3532
  }
3531
3533
 
3532
3534
  template <typename PropertyDescriptor::GetterCallback Getter>
3533
- PropertyDescriptor
3534
- PropertyDescriptor::Accessor(Name name,
3535
- napi_property_attributes attributes,
3536
- void* data) {
3535
+ PropertyDescriptor PropertyDescriptor::Accessor(
3536
+ Name name, napi_property_attributes attributes, void* data) {
3537
3537
  napi_property_descriptor desc = napi_property_descriptor();
3538
3538
 
3539
3539
  desc.name = name;
@@ -3544,14 +3544,10 @@ PropertyDescriptor::Accessor(Name name,
3544
3544
  return desc;
3545
3545
  }
3546
3546
 
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
-
3547
+ template <typename PropertyDescriptor::GetterCallback Getter,
3548
+ typename PropertyDescriptor::SetterCallback Setter>
3549
+ PropertyDescriptor PropertyDescriptor::Accessor(
3550
+ const char* utf8name, napi_property_attributes attributes, void* data) {
3555
3551
  napi_property_descriptor desc = napi_property_descriptor();
3556
3552
 
3557
3553
  desc.utf8name = utf8name;
@@ -3563,23 +3559,19 @@ PropertyDescriptor::Accessor(const char* utf8name,
3563
3559
  return desc;
3564
3560
  }
3565
3561
 
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) {
3562
+ template <typename PropertyDescriptor::GetterCallback Getter,
3563
+ typename PropertyDescriptor::SetterCallback Setter>
3564
+ PropertyDescriptor PropertyDescriptor::Accessor(
3565
+ const std::string& utf8name,
3566
+ napi_property_attributes attributes,
3567
+ void* data) {
3573
3568
  return Accessor<Getter, Setter>(utf8name.c_str(), attributes, data);
3574
3569
  }
3575
3570
 
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) {
3571
+ template <typename PropertyDescriptor::GetterCallback Getter,
3572
+ typename PropertyDescriptor::SetterCallback Setter>
3573
+ PropertyDescriptor PropertyDescriptor::Accessor(
3574
+ Name name, napi_property_attributes attributes, void* data) {
3583
3575
  napi_property_descriptor desc = napi_property_descriptor();
3584
3576
 
3585
3577
  desc.name = name;
@@ -3592,15 +3584,15 @@ PropertyDescriptor::Accessor(Name name,
3592
3584
  }
3593
3585
 
3594
3586
  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) {
3587
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3588
+ Napi::Env env,
3589
+ Napi::Object object,
3590
+ const char* utf8name,
3591
+ Getter getter,
3592
+ napi_property_attributes attributes,
3593
+ void* data) {
3602
3594
  using CbData = details::CallbackData<Getter, Napi::Value>;
3603
- auto callbackData = new CbData({ getter, data });
3595
+ auto callbackData = new CbData({getter, data});
3604
3596
 
3605
3597
  napi_status status = AttachData(env, object, callbackData);
3606
3598
  if (status != napi_ok) {
@@ -3608,37 +3600,37 @@ PropertyDescriptor::Accessor(Napi::Env env,
3608
3600
  NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
3609
3601
  }
3610
3602
 
3611
- return PropertyDescriptor({
3612
- utf8name,
3613
- nullptr,
3614
- nullptr,
3615
- CbData::Wrapper,
3616
- nullptr,
3617
- nullptr,
3618
- attributes,
3619
- callbackData
3620
- });
3603
+ return PropertyDescriptor({utf8name,
3604
+ nullptr,
3605
+ nullptr,
3606
+ CbData::Wrapper,
3607
+ nullptr,
3608
+ nullptr,
3609
+ attributes,
3610
+ callbackData});
3621
3611
  }
3622
3612
 
3623
3613
  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) {
3614
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3615
+ Napi::Env env,
3616
+ Napi::Object object,
3617
+ const std::string& utf8name,
3618
+ Getter getter,
3619
+ napi_property_attributes attributes,
3620
+ void* data) {
3630
3621
  return Accessor(env, object, utf8name.c_str(), getter, attributes, data);
3631
3622
  }
3632
3623
 
3633
3624
  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) {
3625
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3626
+ Napi::Env env,
3627
+ Napi::Object object,
3628
+ Name name,
3629
+ Getter getter,
3630
+ napi_property_attributes attributes,
3631
+ void* data) {
3640
3632
  using CbData = details::CallbackData<Getter, Napi::Value>;
3641
- auto callbackData = new CbData({ getter, data });
3633
+ auto callbackData = new CbData({getter, data});
3642
3634
 
3643
3635
  napi_status status = AttachData(env, object, callbackData);
3644
3636
  if (status != napi_ok) {
@@ -3646,28 +3638,27 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
3646
3638
  NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
3647
3639
  }
3648
3640
 
3649
- return PropertyDescriptor({
3650
- nullptr,
3651
- name,
3652
- nullptr,
3653
- CbData::Wrapper,
3654
- nullptr,
3655
- nullptr,
3656
- attributes,
3657
- callbackData
3658
- });
3641
+ return PropertyDescriptor({nullptr,
3642
+ name,
3643
+ nullptr,
3644
+ CbData::Wrapper,
3645
+ nullptr,
3646
+ nullptr,
3647
+ attributes,
3648
+ callbackData});
3659
3649
  }
3660
3650
 
3661
3651
  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) {
3652
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3653
+ Napi::Env env,
3654
+ Napi::Object object,
3655
+ const char* utf8name,
3656
+ Getter getter,
3657
+ Setter setter,
3658
+ napi_property_attributes attributes,
3659
+ void* data) {
3669
3660
  using CbData = details::AccessorCallbackData<Getter, Setter>;
3670
- auto callbackData = new CbData({ getter, setter, data });
3661
+ auto callbackData = new CbData({getter, setter, data});
3671
3662
 
3672
3663
  napi_status status = AttachData(env, object, callbackData);
3673
3664
  if (status != napi_ok) {
@@ -3675,39 +3666,40 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
3675
3666
  NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
3676
3667
  }
3677
3668
 
3678
- return PropertyDescriptor({
3679
- utf8name,
3680
- nullptr,
3681
- nullptr,
3682
- CbData::GetterWrapper,
3683
- CbData::SetterWrapper,
3684
- nullptr,
3685
- attributes,
3686
- callbackData
3687
- });
3669
+ return PropertyDescriptor({utf8name,
3670
+ nullptr,
3671
+ nullptr,
3672
+ CbData::GetterWrapper,
3673
+ CbData::SetterWrapper,
3674
+ nullptr,
3675
+ attributes,
3676
+ callbackData});
3688
3677
  }
3689
3678
 
3690
3679
  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);
3680
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3681
+ Napi::Env env,
3682
+ Napi::Object object,
3683
+ const std::string& utf8name,
3684
+ Getter getter,
3685
+ Setter setter,
3686
+ napi_property_attributes attributes,
3687
+ void* data) {
3688
+ return Accessor(
3689
+ env, object, utf8name.c_str(), getter, setter, attributes, data);
3699
3690
  }
3700
3691
 
3701
3692
  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) {
3693
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
3694
+ Napi::Env env,
3695
+ Napi::Object object,
3696
+ Name name,
3697
+ Getter getter,
3698
+ Setter setter,
3699
+ napi_property_attributes attributes,
3700
+ void* data) {
3709
3701
  using CbData = details::AccessorCallbackData<Getter, Setter>;
3710
- auto callbackData = new CbData({ getter, setter, data });
3702
+ auto callbackData = new CbData({getter, setter, data});
3711
3703
 
3712
3704
  napi_status status = AttachData(env, object, callbackData);
3713
3705
  if (status != napi_ok) {
@@ -3715,99 +3707,99 @@ inline PropertyDescriptor PropertyDescriptor::Accessor(Napi::Env env,
3715
3707
  NAPI_THROW_IF_FAILED(env, status, napi_property_descriptor());
3716
3708
  }
3717
3709
 
3718
- return PropertyDescriptor({
3719
- nullptr,
3720
- name,
3721
- nullptr,
3722
- CbData::GetterWrapper,
3723
- CbData::SetterWrapper,
3724
- nullptr,
3725
- attributes,
3726
- callbackData
3727
- });
3710
+ return PropertyDescriptor({nullptr,
3711
+ name,
3712
+ nullptr,
3713
+ CbData::GetterWrapper,
3714
+ CbData::SetterWrapper,
3715
+ nullptr,
3716
+ attributes,
3717
+ callbackData});
3728
3718
  }
3729
3719
 
3730
3720
  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
- });
3721
+ inline PropertyDescriptor PropertyDescriptor::Function(
3722
+ Napi::Env env,
3723
+ Napi::Object /*object*/,
3724
+ const char* utf8name,
3725
+ Callable cb,
3726
+ napi_property_attributes attributes,
3727
+ void* data) {
3728
+ return PropertyDescriptor({utf8name,
3729
+ nullptr,
3730
+ nullptr,
3731
+ nullptr,
3732
+ nullptr,
3733
+ Napi::Function::New(env, cb, utf8name, data),
3734
+ attributes,
3735
+ nullptr});
3747
3736
  }
3748
3737
 
3749
3738
  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) {
3739
+ inline PropertyDescriptor PropertyDescriptor::Function(
3740
+ Napi::Env env,
3741
+ Napi::Object object,
3742
+ const std::string& utf8name,
3743
+ Callable cb,
3744
+ napi_property_attributes attributes,
3745
+ void* data) {
3756
3746
  return Function(env, object, utf8name.c_str(), cb, attributes, data);
3757
3747
  }
3758
3748
 
3759
3749
  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
- });
3750
+ inline PropertyDescriptor PropertyDescriptor::Function(
3751
+ Napi::Env env,
3752
+ Napi::Object /*object*/,
3753
+ Name name,
3754
+ Callable cb,
3755
+ napi_property_attributes attributes,
3756
+ void* data) {
3757
+ return PropertyDescriptor({nullptr,
3758
+ name,
3759
+ nullptr,
3760
+ nullptr,
3761
+ nullptr,
3762
+ Napi::Function::New(env, cb, nullptr, data),
3763
+ attributes,
3764
+ nullptr});
3784
3765
  }
3785
3766
 
3786
- inline PropertyDescriptor PropertyDescriptor::Value(const std::string& utf8name,
3787
- napi_value value,
3788
- napi_property_attributes attributes) {
3767
+ inline PropertyDescriptor PropertyDescriptor::Value(
3768
+ const char* utf8name,
3769
+ napi_value value,
3770
+ napi_property_attributes attributes) {
3771
+ return PropertyDescriptor({utf8name,
3772
+ nullptr,
3773
+ nullptr,
3774
+ nullptr,
3775
+ nullptr,
3776
+ value,
3777
+ attributes,
3778
+ nullptr});
3779
+ }
3780
+
3781
+ inline PropertyDescriptor PropertyDescriptor::Value(
3782
+ const std::string& utf8name,
3783
+ napi_value value,
3784
+ napi_property_attributes attributes) {
3789
3785
  return Value(utf8name.c_str(), value, attributes);
3790
3786
  }
3791
3787
 
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
- });
3788
+ inline PropertyDescriptor PropertyDescriptor::Value(
3789
+ napi_value name, napi_value value, napi_property_attributes attributes) {
3790
+ return PropertyDescriptor(
3791
+ {nullptr, name, nullptr, nullptr, nullptr, value, attributes, nullptr});
3798
3792
  }
3799
3793
 
3800
- inline PropertyDescriptor PropertyDescriptor::Value(Name name,
3801
- Napi::Value value,
3802
- napi_property_attributes attributes) {
3794
+ inline PropertyDescriptor PropertyDescriptor::Value(
3795
+ Name name, Napi::Value value, napi_property_attributes attributes) {
3803
3796
  napi_value nameValue = name;
3804
3797
  napi_value valueValue = value;
3805
3798
  return PropertyDescriptor::Value(nameValue, valueValue, attributes);
3806
3799
  }
3807
3800
 
3808
3801
  inline PropertyDescriptor::PropertyDescriptor(napi_property_descriptor desc)
3809
- : _desc(desc) {
3810
- }
3802
+ : _desc(desc) {}
3811
3803
 
3812
3804
  inline PropertyDescriptor::operator napi_property_descriptor&() {
3813
3805
  return _desc;
@@ -3822,26 +3814,22 @@ inline PropertyDescriptor::operator const napi_property_descriptor&() const {
3822
3814
  ////////////////////////////////////////////////////////////////////////////////
3823
3815
 
3824
3816
  template <typename T>
3825
- inline void InstanceWrap<T>::AttachPropData(napi_env env,
3826
- napi_value value,
3827
- const napi_property_descriptor* prop) {
3817
+ inline void InstanceWrap<T>::AttachPropData(
3818
+ napi_env env, napi_value value, const napi_property_descriptor* prop) {
3828
3819
  napi_status status;
3829
3820
  if (!(prop->attributes & napi_static)) {
3830
3821
  if (prop->method == T::InstanceVoidMethodCallbackWrapper) {
3831
- status = Napi::details::AttachData(env,
3832
- value,
3833
- static_cast<InstanceVoidMethodCallbackData*>(prop->data));
3822
+ status = Napi::details::AttachData(
3823
+ env, value, static_cast<InstanceVoidMethodCallbackData*>(prop->data));
3834
3824
  NAPI_THROW_IF_FAILED_VOID(env, status);
3835
3825
  } else if (prop->method == T::InstanceMethodCallbackWrapper) {
3836
- status = Napi::details::AttachData(env,
3837
- value,
3838
- static_cast<InstanceMethodCallbackData*>(prop->data));
3826
+ status = Napi::details::AttachData(
3827
+ env, value, static_cast<InstanceMethodCallbackData*>(prop->data));
3839
3828
  NAPI_THROW_IF_FAILED_VOID(env, status);
3840
3829
  } 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));
3830
+ prop->setter == T::InstanceSetterCallbackWrapper) {
3831
+ status = Napi::details::AttachData(
3832
+ env, value, static_cast<InstanceAccessorCallbackData*>(prop->data));
3845
3833
  NAPI_THROW_IF_FAILED_VOID(env, status);
3846
3834
  }
3847
3835
  }
@@ -3854,7 +3842,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3854
3842
  napi_property_attributes attributes,
3855
3843
  void* data) {
3856
3844
  InstanceVoidMethodCallbackData* callbackData =
3857
- new InstanceVoidMethodCallbackData({ method, data});
3845
+ new InstanceVoidMethodCallbackData({method, data});
3858
3846
 
3859
3847
  napi_property_descriptor desc = napi_property_descriptor();
3860
3848
  desc.utf8name = utf8name;
@@ -3870,7 +3858,8 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3870
3858
  InstanceMethodCallback method,
3871
3859
  napi_property_attributes attributes,
3872
3860
  void* data) {
3873
- InstanceMethodCallbackData* callbackData = new InstanceMethodCallbackData({ method, data });
3861
+ InstanceMethodCallbackData* callbackData =
3862
+ new InstanceMethodCallbackData({method, data});
3874
3863
 
3875
3864
  napi_property_descriptor desc = napi_property_descriptor();
3876
3865
  desc.utf8name = utf8name;
@@ -3887,7 +3876,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3887
3876
  napi_property_attributes attributes,
3888
3877
  void* data) {
3889
3878
  InstanceVoidMethodCallbackData* callbackData =
3890
- new InstanceVoidMethodCallbackData({ method, data});
3879
+ new InstanceVoidMethodCallbackData({method, data});
3891
3880
 
3892
3881
  napi_property_descriptor desc = napi_property_descriptor();
3893
3882
  desc.name = name;
@@ -3903,7 +3892,8 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3903
3892
  InstanceMethodCallback method,
3904
3893
  napi_property_attributes attributes,
3905
3894
  void* data) {
3906
- InstanceMethodCallbackData* callbackData = new InstanceMethodCallbackData({ method, data });
3895
+ InstanceMethodCallbackData* callbackData =
3896
+ new InstanceMethodCallbackData({method, data});
3907
3897
 
3908
3898
  napi_property_descriptor desc = napi_property_descriptor();
3909
3899
  desc.name = name;
@@ -3916,9 +3906,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3916
3906
  template <typename T>
3917
3907
  template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
3918
3908
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3919
- const char* utf8name,
3920
- napi_property_attributes attributes,
3921
- void* data) {
3909
+ const char* utf8name, napi_property_attributes attributes, void* data) {
3922
3910
  napi_property_descriptor desc = napi_property_descriptor();
3923
3911
  desc.utf8name = utf8name;
3924
3912
  desc.method = details::TemplatedInstanceVoidCallback<T, method>;
@@ -3930,9 +3918,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3930
3918
  template <typename T>
3931
3919
  template <typename InstanceWrap<T>::InstanceMethodCallback method>
3932
3920
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3933
- const char* utf8name,
3934
- napi_property_attributes attributes,
3935
- void* data) {
3921
+ const char* utf8name, napi_property_attributes attributes, void* data) {
3936
3922
  napi_property_descriptor desc = napi_property_descriptor();
3937
3923
  desc.utf8name = utf8name;
3938
3924
  desc.method = details::TemplatedInstanceCallback<T, method>;
@@ -3944,9 +3930,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3944
3930
  template <typename T>
3945
3931
  template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
3946
3932
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3947
- Symbol name,
3948
- napi_property_attributes attributes,
3949
- void* data) {
3933
+ Symbol name, napi_property_attributes attributes, void* data) {
3950
3934
  napi_property_descriptor desc = napi_property_descriptor();
3951
3935
  desc.name = name;
3952
3936
  desc.method = details::TemplatedInstanceVoidCallback<T, method>;
@@ -3958,9 +3942,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3958
3942
  template <typename T>
3959
3943
  template <typename InstanceWrap<T>::InstanceMethodCallback method>
3960
3944
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceMethod(
3961
- Symbol name,
3962
- napi_property_attributes attributes,
3963
- void* data) {
3945
+ Symbol name, napi_property_attributes attributes, void* data) {
3964
3946
  napi_property_descriptor desc = napi_property_descriptor();
3965
3947
  desc.name = name;
3966
3948
  desc.method = details::TemplatedInstanceCallback<T, method>;
@@ -3977,7 +3959,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
3977
3959
  napi_property_attributes attributes,
3978
3960
  void* data) {
3979
3961
  InstanceAccessorCallbackData* callbackData =
3980
- new InstanceAccessorCallbackData({ getter, setter, data });
3962
+ new InstanceAccessorCallbackData({getter, setter, data});
3981
3963
 
3982
3964
  napi_property_descriptor desc = napi_property_descriptor();
3983
3965
  desc.utf8name = utf8name;
@@ -3996,7 +3978,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
3996
3978
  napi_property_attributes attributes,
3997
3979
  void* data) {
3998
3980
  InstanceAccessorCallbackData* callbackData =
3999
- new InstanceAccessorCallbackData({ getter, setter, data });
3981
+ new InstanceAccessorCallbackData({getter, setter, data});
4000
3982
 
4001
3983
  napi_property_descriptor desc = napi_property_descriptor();
4002
3984
  desc.name = name;
@@ -4011,9 +3993,7 @@ template <typename T>
4011
3993
  template <typename InstanceWrap<T>::InstanceGetterCallback getter,
4012
3994
  typename InstanceWrap<T>::InstanceSetterCallback setter>
4013
3995
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
4014
- const char* utf8name,
4015
- napi_property_attributes attributes,
4016
- void* data) {
3996
+ const char* utf8name, napi_property_attributes attributes, void* data) {
4017
3997
  napi_property_descriptor desc = napi_property_descriptor();
4018
3998
  desc.utf8name = utf8name;
4019
3999
  desc.getter = details::TemplatedInstanceCallback<T, getter>;
@@ -4027,9 +4007,7 @@ template <typename T>
4027
4007
  template <typename InstanceWrap<T>::InstanceGetterCallback getter,
4028
4008
  typename InstanceWrap<T>::InstanceSetterCallback setter>
4029
4009
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceAccessor(
4030
- Symbol name,
4031
- napi_property_attributes attributes,
4032
- void* data) {
4010
+ Symbol name, napi_property_attributes attributes, void* data) {
4033
4011
  napi_property_descriptor desc = napi_property_descriptor();
4034
4012
  desc.name = name;
4035
4013
  desc.getter = details::TemplatedInstanceCallback<T, getter>;
@@ -4053,9 +4031,7 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
4053
4031
 
4054
4032
  template <typename T>
4055
4033
  inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
4056
- Symbol name,
4057
- Napi::Value value,
4058
- napi_property_attributes attributes) {
4034
+ Symbol name, Napi::Value value, napi_property_attributes attributes) {
4059
4035
  napi_property_descriptor desc = napi_property_descriptor();
4060
4036
  desc.name = name;
4061
4037
  desc.value = value;
@@ -4065,12 +4041,11 @@ inline ClassPropertyDescriptor<T> InstanceWrap<T>::InstanceValue(
4065
4041
 
4066
4042
  template <typename T>
4067
4043
  inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
4068
- napi_env env,
4069
- napi_callback_info info) {
4044
+ napi_env env, napi_callback_info info) {
4070
4045
  return details::WrapCallback([&] {
4071
4046
  CallbackInfo callbackInfo(env, info);
4072
4047
  InstanceVoidMethodCallbackData* callbackData =
4073
- reinterpret_cast<InstanceVoidMethodCallbackData*>(callbackInfo.Data());
4048
+ reinterpret_cast<InstanceVoidMethodCallbackData*>(callbackInfo.Data());
4074
4049
  callbackInfo.SetData(callbackData->data);
4075
4050
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4076
4051
  auto cb = callbackData->callback;
@@ -4081,12 +4056,11 @@ inline napi_value InstanceWrap<T>::InstanceVoidMethodCallbackWrapper(
4081
4056
 
4082
4057
  template <typename T>
4083
4058
  inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
4084
- napi_env env,
4085
- napi_callback_info info) {
4059
+ napi_env env, napi_callback_info info) {
4086
4060
  return details::WrapCallback([&] {
4087
4061
  CallbackInfo callbackInfo(env, info);
4088
4062
  InstanceMethodCallbackData* callbackData =
4089
- reinterpret_cast<InstanceMethodCallbackData*>(callbackInfo.Data());
4063
+ reinterpret_cast<InstanceMethodCallbackData*>(callbackInfo.Data());
4090
4064
  callbackInfo.SetData(callbackData->data);
4091
4065
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4092
4066
  auto cb = callbackData->callback;
@@ -4096,12 +4070,11 @@ inline napi_value InstanceWrap<T>::InstanceMethodCallbackWrapper(
4096
4070
 
4097
4071
  template <typename T>
4098
4072
  inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
4099
- napi_env env,
4100
- napi_callback_info info) {
4073
+ napi_env env, napi_callback_info info) {
4101
4074
  return details::WrapCallback([&] {
4102
4075
  CallbackInfo callbackInfo(env, info);
4103
4076
  InstanceAccessorCallbackData* callbackData =
4104
- reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
4077
+ reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
4105
4078
  callbackInfo.SetData(callbackData->data);
4106
4079
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4107
4080
  auto cb = callbackData->getterCallback;
@@ -4111,12 +4084,11 @@ inline napi_value InstanceWrap<T>::InstanceGetterCallbackWrapper(
4111
4084
 
4112
4085
  template <typename T>
4113
4086
  inline napi_value InstanceWrap<T>::InstanceSetterCallbackWrapper(
4114
- napi_env env,
4115
- napi_callback_info info) {
4087
+ napi_env env, napi_callback_info info) {
4116
4088
  return details::WrapCallback([&] {
4117
4089
  CallbackInfo callbackInfo(env, info);
4118
4090
  InstanceAccessorCallbackData* callbackData =
4119
- reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
4091
+ reinterpret_cast<InstanceAccessorCallbackData*>(callbackInfo.Data());
4120
4092
  callbackInfo.SetData(callbackData->data);
4121
4093
  T* instance = T::Unwrap(callbackInfo.This().As<Object>());
4122
4094
  auto cb = callbackData->setterCallback;
@@ -4169,7 +4141,7 @@ inline ObjectWrap<T>::~ObjectWrap() {
4169
4141
  }
4170
4142
  }
4171
4143
 
4172
- template<typename T>
4144
+ template <typename T>
4173
4145
  inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
4174
4146
  void* unwrapped;
4175
4147
  napi_status status = napi_unwrap(wrapper.Env(), wrapper, &unwrapped);
@@ -4178,12 +4150,12 @@ inline T* ObjectWrap<T>::Unwrap(Object wrapper) {
4178
4150
  }
4179
4151
 
4180
4152
  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) {
4153
+ inline Function ObjectWrap<T>::DefineClass(
4154
+ Napi::Env env,
4155
+ const char* utf8name,
4156
+ const size_t props_count,
4157
+ const napi_property_descriptor* descriptors,
4158
+ void* data) {
4187
4159
  napi_status status;
4188
4160
  std::vector<napi_property_descriptor> props(props_count);
4189
4161
 
@@ -4199,16 +4171,18 @@ ObjectWrap<T>::DefineClass(Napi::Env env,
4199
4171
  props[index] = descriptors[index];
4200
4172
  napi_property_descriptor* prop = &props[index];
4201
4173
  if (prop->method == T::StaticMethodCallbackWrapper) {
4202
- status = CreateFunction(env,
4203
- utf8name,
4204
- prop->method,
4205
- static_cast<StaticMethodCallbackData*>(prop->data),
4206
- &(prop->value));
4174
+ status =
4175
+ CreateFunction(env,
4176
+ utf8name,
4177
+ prop->method,
4178
+ static_cast<StaticMethodCallbackData*>(prop->data),
4179
+ &(prop->value));
4207
4180
  NAPI_THROW_IF_FAILED(env, status, Function());
4208
4181
  prop->method = nullptr;
4209
4182
  prop->data = nullptr;
4210
4183
  } else if (prop->method == T::StaticVoidMethodCallbackWrapper) {
4211
- status = CreateFunction(env,
4184
+ status =
4185
+ CreateFunction(env,
4212
4186
  utf8name,
4213
4187
  prop->method,
4214
4188
  static_cast<StaticVoidMethodCallbackData*>(prop->data),
@@ -4238,9 +4212,8 @@ ObjectWrap<T>::DefineClass(Napi::Env env,
4238
4212
 
4239
4213
  if (prop->getter == T::StaticGetterCallbackWrapper ||
4240
4214
  prop->setter == T::StaticSetterCallbackWrapper) {
4241
- status = Napi::details::AttachData(env,
4242
- value,
4243
- static_cast<StaticAccessorCallbackData*>(prop->data));
4215
+ status = Napi::details::AttachData(
4216
+ env, value, static_cast<StaticAccessorCallbackData*>(prop->data));
4244
4217
  NAPI_THROW_IF_FAILED(env, status, Function());
4245
4218
  } else {
4246
4219
  // InstanceWrap<T>::AttachPropData is responsible for attaching the data
@@ -4258,11 +4231,12 @@ inline Function ObjectWrap<T>::DefineClass(
4258
4231
  const char* utf8name,
4259
4232
  const std::initializer_list<ClassPropertyDescriptor<T>>& properties,
4260
4233
  void* data) {
4261
- return DefineClass(env,
4262
- utf8name,
4263
- properties.size(),
4264
- reinterpret_cast<const napi_property_descriptor*>(properties.begin()),
4265
- data);
4234
+ return DefineClass(
4235
+ env,
4236
+ utf8name,
4237
+ properties.size(),
4238
+ reinterpret_cast<const napi_property_descriptor*>(properties.begin()),
4239
+ data);
4266
4240
  }
4267
4241
 
4268
4242
  template <typename T>
@@ -4271,11 +4245,12 @@ inline Function ObjectWrap<T>::DefineClass(
4271
4245
  const char* utf8name,
4272
4246
  const std::vector<ClassPropertyDescriptor<T>>& properties,
4273
4247
  void* data) {
4274
- return DefineClass(env,
4275
- utf8name,
4276
- properties.size(),
4277
- reinterpret_cast<const napi_property_descriptor*>(properties.data()),
4278
- data);
4248
+ return DefineClass(
4249
+ env,
4250
+ utf8name,
4251
+ properties.size(),
4252
+ reinterpret_cast<const napi_property_descriptor*>(properties.data()),
4253
+ data);
4279
4254
  }
4280
4255
 
4281
4256
  template <typename T>
@@ -4284,13 +4259,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4284
4259
  StaticVoidMethodCallback method,
4285
4260
  napi_property_attributes attributes,
4286
4261
  void* data) {
4287
- StaticVoidMethodCallbackData* callbackData = new StaticVoidMethodCallbackData({ method, data });
4262
+ StaticVoidMethodCallbackData* callbackData =
4263
+ new StaticVoidMethodCallbackData({method, data});
4288
4264
 
4289
4265
  napi_property_descriptor desc = napi_property_descriptor();
4290
4266
  desc.utf8name = utf8name;
4291
4267
  desc.method = T::StaticVoidMethodCallbackWrapper;
4292
4268
  desc.data = callbackData;
4293
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4269
+ desc.attributes =
4270
+ static_cast<napi_property_attributes>(attributes | napi_static);
4294
4271
  return desc;
4295
4272
  }
4296
4273
 
@@ -4300,13 +4277,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4300
4277
  StaticMethodCallback method,
4301
4278
  napi_property_attributes attributes,
4302
4279
  void* data) {
4303
- StaticMethodCallbackData* callbackData = new StaticMethodCallbackData({ method, data });
4280
+ StaticMethodCallbackData* callbackData =
4281
+ new StaticMethodCallbackData({method, data});
4304
4282
 
4305
4283
  napi_property_descriptor desc = napi_property_descriptor();
4306
4284
  desc.utf8name = utf8name;
4307
4285
  desc.method = T::StaticMethodCallbackWrapper;
4308
4286
  desc.data = callbackData;
4309
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4287
+ desc.attributes =
4288
+ static_cast<napi_property_attributes>(attributes | napi_static);
4310
4289
  return desc;
4311
4290
  }
4312
4291
 
@@ -4316,13 +4295,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4316
4295
  StaticVoidMethodCallback method,
4317
4296
  napi_property_attributes attributes,
4318
4297
  void* data) {
4319
- StaticVoidMethodCallbackData* callbackData = new StaticVoidMethodCallbackData({ method, data });
4298
+ StaticVoidMethodCallbackData* callbackData =
4299
+ new StaticVoidMethodCallbackData({method, data});
4320
4300
 
4321
4301
  napi_property_descriptor desc = napi_property_descriptor();
4322
4302
  desc.name = name;
4323
4303
  desc.method = T::StaticVoidMethodCallbackWrapper;
4324
4304
  desc.data = callbackData;
4325
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4305
+ desc.attributes =
4306
+ static_cast<napi_property_attributes>(attributes | napi_static);
4326
4307
  return desc;
4327
4308
  }
4328
4309
 
@@ -4332,69 +4313,67 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4332
4313
  StaticMethodCallback method,
4333
4314
  napi_property_attributes attributes,
4334
4315
  void* data) {
4335
- StaticMethodCallbackData* callbackData = new StaticMethodCallbackData({ method, data });
4316
+ StaticMethodCallbackData* callbackData =
4317
+ new StaticMethodCallbackData({method, data});
4336
4318
 
4337
4319
  napi_property_descriptor desc = napi_property_descriptor();
4338
4320
  desc.name = name;
4339
4321
  desc.method = T::StaticMethodCallbackWrapper;
4340
4322
  desc.data = callbackData;
4341
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4323
+ desc.attributes =
4324
+ static_cast<napi_property_attributes>(attributes | napi_static);
4342
4325
  return desc;
4343
4326
  }
4344
4327
 
4345
4328
  template <typename T>
4346
4329
  template <typename ObjectWrap<T>::StaticVoidMethodCallback method>
4347
4330
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4348
- const char* utf8name,
4349
- napi_property_attributes attributes,
4350
- void* data) {
4331
+ const char* utf8name, napi_property_attributes attributes, void* data) {
4351
4332
  napi_property_descriptor desc = napi_property_descriptor();
4352
4333
  desc.utf8name = utf8name;
4353
4334
  desc.method = details::TemplatedVoidCallback<method>;
4354
4335
  desc.data = data;
4355
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4336
+ desc.attributes =
4337
+ static_cast<napi_property_attributes>(attributes | napi_static);
4356
4338
  return desc;
4357
4339
  }
4358
4340
 
4359
4341
  template <typename T>
4360
4342
  template <typename ObjectWrap<T>::StaticVoidMethodCallback method>
4361
4343
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4362
- Symbol name,
4363
- napi_property_attributes attributes,
4364
- void* data) {
4344
+ Symbol name, napi_property_attributes attributes, void* data) {
4365
4345
  napi_property_descriptor desc = napi_property_descriptor();
4366
4346
  desc.name = name;
4367
4347
  desc.method = details::TemplatedVoidCallback<method>;
4368
4348
  desc.data = data;
4369
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4349
+ desc.attributes =
4350
+ static_cast<napi_property_attributes>(attributes | napi_static);
4370
4351
  return desc;
4371
4352
  }
4372
4353
 
4373
4354
  template <typename T>
4374
4355
  template <typename ObjectWrap<T>::StaticMethodCallback method>
4375
4356
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4376
- const char* utf8name,
4377
- napi_property_attributes attributes,
4378
- void* data) {
4357
+ const char* utf8name, napi_property_attributes attributes, void* data) {
4379
4358
  napi_property_descriptor desc = napi_property_descriptor();
4380
4359
  desc.utf8name = utf8name;
4381
4360
  desc.method = details::TemplatedCallback<method>;
4382
4361
  desc.data = data;
4383
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4362
+ desc.attributes =
4363
+ static_cast<napi_property_attributes>(attributes | napi_static);
4384
4364
  return desc;
4385
4365
  }
4386
4366
 
4387
4367
  template <typename T>
4388
4368
  template <typename ObjectWrap<T>::StaticMethodCallback method>
4389
4369
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticMethod(
4390
- Symbol name,
4391
- napi_property_attributes attributes,
4392
- void* data) {
4370
+ Symbol name, napi_property_attributes attributes, void* data) {
4393
4371
  napi_property_descriptor desc = napi_property_descriptor();
4394
4372
  desc.name = name;
4395
4373
  desc.method = details::TemplatedCallback<method>;
4396
4374
  desc.data = data;
4397
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4375
+ desc.attributes =
4376
+ static_cast<napi_property_attributes>(attributes | napi_static);
4398
4377
  return desc;
4399
4378
  }
4400
4379
 
@@ -4406,14 +4385,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
4406
4385
  napi_property_attributes attributes,
4407
4386
  void* data) {
4408
4387
  StaticAccessorCallbackData* callbackData =
4409
- new StaticAccessorCallbackData({ getter, setter, data });
4388
+ new StaticAccessorCallbackData({getter, setter, data});
4410
4389
 
4411
4390
  napi_property_descriptor desc = napi_property_descriptor();
4412
4391
  desc.utf8name = utf8name;
4413
4392
  desc.getter = getter != nullptr ? T::StaticGetterCallbackWrapper : nullptr;
4414
4393
  desc.setter = setter != nullptr ? T::StaticSetterCallbackWrapper : nullptr;
4415
4394
  desc.data = callbackData;
4416
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4395
+ desc.attributes =
4396
+ static_cast<napi_property_attributes>(attributes | napi_static);
4417
4397
  return desc;
4418
4398
  }
4419
4399
 
@@ -4425,14 +4405,15 @@ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
4425
4405
  napi_property_attributes attributes,
4426
4406
  void* data) {
4427
4407
  StaticAccessorCallbackData* callbackData =
4428
- new StaticAccessorCallbackData({ getter, setter, data });
4408
+ new StaticAccessorCallbackData({getter, setter, data});
4429
4409
 
4430
4410
  napi_property_descriptor desc = napi_property_descriptor();
4431
4411
  desc.name = name;
4432
4412
  desc.getter = getter != nullptr ? T::StaticGetterCallbackWrapper : nullptr;
4433
4413
  desc.setter = setter != nullptr ? T::StaticSetterCallbackWrapper : nullptr;
4434
4414
  desc.data = callbackData;
4435
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4415
+ desc.attributes =
4416
+ static_cast<napi_property_attributes>(attributes | napi_static);
4436
4417
  return desc;
4437
4418
  }
4438
4419
 
@@ -4440,15 +4421,14 @@ template <typename T>
4440
4421
  template <typename ObjectWrap<T>::StaticGetterCallback getter,
4441
4422
  typename ObjectWrap<T>::StaticSetterCallback setter>
4442
4423
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
4443
- const char* utf8name,
4444
- napi_property_attributes attributes,
4445
- void* data) {
4424
+ const char* utf8name, napi_property_attributes attributes, void* data) {
4446
4425
  napi_property_descriptor desc = napi_property_descriptor();
4447
4426
  desc.utf8name = utf8name;
4448
4427
  desc.getter = details::TemplatedCallback<getter>;
4449
4428
  desc.setter = This::WrapStaticSetter(This::StaticSetterTag<setter>());
4450
4429
  desc.data = data;
4451
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4430
+ desc.attributes =
4431
+ static_cast<napi_property_attributes>(attributes | napi_static);
4452
4432
  return desc;
4453
4433
  }
4454
4434
 
@@ -4456,35 +4436,38 @@ template <typename T>
4456
4436
  template <typename ObjectWrap<T>::StaticGetterCallback getter,
4457
4437
  typename ObjectWrap<T>::StaticSetterCallback setter>
4458
4438
  inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticAccessor(
4459
- Symbol name,
4460
- napi_property_attributes attributes,
4461
- void* data) {
4439
+ Symbol name, napi_property_attributes attributes, void* data) {
4462
4440
  napi_property_descriptor desc = napi_property_descriptor();
4463
4441
  desc.name = name;
4464
4442
  desc.getter = details::TemplatedCallback<getter>;
4465
4443
  desc.setter = This::WrapStaticSetter(This::StaticSetterTag<setter>());
4466
4444
  desc.data = data;
4467
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4445
+ desc.attributes =
4446
+ static_cast<napi_property_attributes>(attributes | napi_static);
4468
4447
  return desc;
4469
4448
  }
4470
4449
 
4471
4450
  template <typename T>
4472
- inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(const char* utf8name,
4473
- Napi::Value value, napi_property_attributes attributes) {
4451
+ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
4452
+ const char* utf8name,
4453
+ Napi::Value value,
4454
+ napi_property_attributes attributes) {
4474
4455
  napi_property_descriptor desc = napi_property_descriptor();
4475
4456
  desc.utf8name = utf8name;
4476
4457
  desc.value = value;
4477
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4458
+ desc.attributes =
4459
+ static_cast<napi_property_attributes>(attributes | napi_static);
4478
4460
  return desc;
4479
4461
  }
4480
4462
 
4481
4463
  template <typename T>
4482
- inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(Symbol name,
4483
- Napi::Value value, napi_property_attributes attributes) {
4464
+ inline ClassPropertyDescriptor<T> ObjectWrap<T>::StaticValue(
4465
+ Symbol name, Napi::Value value, napi_property_attributes attributes) {
4484
4466
  napi_property_descriptor desc = napi_property_descriptor();
4485
4467
  desc.name = name;
4486
4468
  desc.value = value;
4487
- desc.attributes = static_cast<napi_property_attributes>(attributes | napi_static);
4469
+ desc.attributes =
4470
+ static_cast<napi_property_attributes>(attributes | napi_static);
4488
4471
  return desc;
4489
4472
  }
4490
4473
 
@@ -4502,8 +4485,7 @@ inline void ObjectWrap<T>::Finalize(Napi::Env /*env*/) {}
4502
4485
 
4503
4486
  template <typename T>
4504
4487
  inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
4505
- napi_env env,
4506
- napi_callback_info info) {
4488
+ napi_env env, napi_callback_info info) {
4507
4489
  napi_value new_target;
4508
4490
  napi_status status = napi_get_new_target(env, info, &new_target);
4509
4491
  if (status != napi_ok) return nullptr;
@@ -4528,7 +4510,7 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
4528
4510
  } else {
4529
4511
  instance->_construction_failed = false;
4530
4512
  }
4531
- # endif // NAPI_CPP_EXCEPTIONS
4513
+ #endif // NAPI_CPP_EXCEPTIONS
4532
4514
  return callbackInfo.This();
4533
4515
  });
4534
4516
 
@@ -4537,12 +4519,11 @@ inline napi_value ObjectWrap<T>::ConstructorCallbackWrapper(
4537
4519
 
4538
4520
  template <typename T>
4539
4521
  inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
4540
- napi_env env,
4541
- napi_callback_info info) {
4522
+ napi_env env, napi_callback_info info) {
4542
4523
  return details::WrapCallback([&] {
4543
4524
  CallbackInfo callbackInfo(env, info);
4544
4525
  StaticVoidMethodCallbackData* callbackData =
4545
- reinterpret_cast<StaticVoidMethodCallbackData*>(callbackInfo.Data());
4526
+ reinterpret_cast<StaticVoidMethodCallbackData*>(callbackInfo.Data());
4546
4527
  callbackInfo.SetData(callbackData->data);
4547
4528
  callbackData->callback(callbackInfo);
4548
4529
  return nullptr;
@@ -4551,12 +4532,11 @@ inline napi_value ObjectWrap<T>::StaticVoidMethodCallbackWrapper(
4551
4532
 
4552
4533
  template <typename T>
4553
4534
  inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
4554
- napi_env env,
4555
- napi_callback_info info) {
4535
+ napi_env env, napi_callback_info info) {
4556
4536
  return details::WrapCallback([&] {
4557
4537
  CallbackInfo callbackInfo(env, info);
4558
4538
  StaticMethodCallbackData* callbackData =
4559
- reinterpret_cast<StaticMethodCallbackData*>(callbackInfo.Data());
4539
+ reinterpret_cast<StaticMethodCallbackData*>(callbackInfo.Data());
4560
4540
  callbackInfo.SetData(callbackData->data);
4561
4541
  return callbackData->callback(callbackInfo);
4562
4542
  });
@@ -4564,12 +4544,11 @@ inline napi_value ObjectWrap<T>::StaticMethodCallbackWrapper(
4564
4544
 
4565
4545
  template <typename T>
4566
4546
  inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
4567
- napi_env env,
4568
- napi_callback_info info) {
4547
+ napi_env env, napi_callback_info info) {
4569
4548
  return details::WrapCallback([&] {
4570
4549
  CallbackInfo callbackInfo(env, info);
4571
4550
  StaticAccessorCallbackData* callbackData =
4572
- reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
4551
+ reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
4573
4552
  callbackInfo.SetData(callbackData->data);
4574
4553
  return callbackData->getterCallback(callbackInfo);
4575
4554
  });
@@ -4577,12 +4556,11 @@ inline napi_value ObjectWrap<T>::StaticGetterCallbackWrapper(
4577
4556
 
4578
4557
  template <typename T>
4579
4558
  inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
4580
- napi_env env,
4581
- napi_callback_info info) {
4559
+ napi_env env, napi_callback_info info) {
4582
4560
  return details::WrapCallback([&] {
4583
4561
  CallbackInfo callbackInfo(env, info);
4584
4562
  StaticAccessorCallbackData* callbackData =
4585
- reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
4563
+ reinterpret_cast<StaticAccessorCallbackData*>(callbackInfo.Data());
4586
4564
  callbackInfo.SetData(callbackData->data);
4587
4565
  callbackData->setterCallback(callbackInfo, callbackInfo[0]);
4588
4566
  return nullptr;
@@ -4590,7 +4568,9 @@ inline napi_value ObjectWrap<T>::StaticSetterCallbackWrapper(
4590
4568
  }
4591
4569
 
4592
4570
  template <typename T>
4593
- inline void ObjectWrap<T>::FinalizeCallback(napi_env env, void* data, void* /*hint*/) {
4571
+ inline void ObjectWrap<T>::FinalizeCallback(napi_env env,
4572
+ void* data,
4573
+ void* /*hint*/) {
4594
4574
  HandleScope scope(env);
4595
4575
  T* instance = static_cast<T*>(data);
4596
4576
  instance->Finalize(Napi::Env(env));
@@ -4613,8 +4593,7 @@ inline napi_value ObjectWrap<T>::WrappedMethod(
4613
4593
  ////////////////////////////////////////////////////////////////////////////////
4614
4594
 
4615
4595
  inline HandleScope::HandleScope(napi_env env, napi_handle_scope scope)
4616
- : _env(env), _scope(scope) {
4617
- }
4596
+ : _env(env), _scope(scope) {}
4618
4597
 
4619
4598
  inline HandleScope::HandleScope(Napi::Env env) : _env(env) {
4620
4599
  napi_status status = napi_open_handle_scope(_env, &_scope);
@@ -4623,9 +4602,8 @@ inline HandleScope::HandleScope(Napi::Env env) : _env(env) {
4623
4602
 
4624
4603
  inline HandleScope::~HandleScope() {
4625
4604
  napi_status status = napi_close_handle_scope(_env, _scope);
4626
- NAPI_FATAL_IF_FAILED(status,
4627
- "HandleScope::~HandleScope",
4628
- "napi_close_handle_scope");
4605
+ NAPI_FATAL_IF_FAILED(
4606
+ status, "HandleScope::~HandleScope", "napi_close_handle_scope");
4629
4607
  }
4630
4608
 
4631
4609
  inline HandleScope::operator napi_handle_scope() const {
@@ -4641,8 +4619,8 @@ inline Napi::Env HandleScope::Env() const {
4641
4619
  ////////////////////////////////////////////////////////////////////////////////
4642
4620
 
4643
4621
  inline EscapableHandleScope::EscapableHandleScope(
4644
- napi_env env, napi_escapable_handle_scope scope) : _env(env), _scope(scope) {
4645
- }
4622
+ napi_env env, napi_escapable_handle_scope scope)
4623
+ : _env(env), _scope(scope) {}
4646
4624
 
4647
4625
  inline EscapableHandleScope::EscapableHandleScope(Napi::Env env) : _env(env) {
4648
4626
  napi_status status = napi_open_escapable_handle_scope(_env, &_scope);
@@ -4671,28 +4649,25 @@ inline Value EscapableHandleScope::Escape(napi_value escapee) {
4671
4649
  return Value(_env, result);
4672
4650
  }
4673
4651
 
4674
-
4675
4652
  #if (NAPI_VERSION > 2)
4676
4653
  ////////////////////////////////////////////////////////////////////////////////
4677
4654
  // CallbackScope class
4678
4655
  ////////////////////////////////////////////////////////////////////////////////
4679
4656
 
4680
- inline CallbackScope::CallbackScope(
4681
- napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
4682
- }
4657
+ inline CallbackScope::CallbackScope(napi_env env, napi_callback_scope scope)
4658
+ : _env(env), _scope(scope) {}
4683
4659
 
4684
4660
  inline CallbackScope::CallbackScope(napi_env env, napi_async_context context)
4685
4661
  : _env(env) {
4686
- napi_status status = napi_open_callback_scope(
4687
- _env, Object::New(env), context, &_scope);
4662
+ napi_status status =
4663
+ napi_open_callback_scope(_env, Object::New(env), context, &_scope);
4688
4664
  NAPI_THROW_IF_FAILED_VOID(_env, status);
4689
4665
  }
4690
4666
 
4691
4667
  inline CallbackScope::~CallbackScope() {
4692
4668
  napi_status status = napi_close_callback_scope(_env, _scope);
4693
- NAPI_FATAL_IF_FAILED(status,
4694
- "CallbackScope::~CallbackScope",
4695
- "napi_close_callback_scope");
4669
+ NAPI_FATAL_IF_FAILED(
4670
+ status, "CallbackScope::~CallbackScope", "napi_close_callback_scope");
4696
4671
  }
4697
4672
 
4698
4673
  inline CallbackScope::operator napi_callback_scope() const {
@@ -4709,8 +4684,7 @@ inline Napi::Env CallbackScope::Env() const {
4709
4684
  ////////////////////////////////////////////////////////////////////////////////
4710
4685
 
4711
4686
  inline AsyncContext::AsyncContext(napi_env env, const char* resource_name)
4712
- : AsyncContext(env, resource_name, Object::New(env)) {
4713
- }
4687
+ : AsyncContext(env, resource_name, Object::New(env)) {}
4714
4688
 
4715
4689
  inline AsyncContext::AsyncContext(napi_env env,
4716
4690
  const char* resource_name,
@@ -4739,7 +4713,7 @@ inline AsyncContext::AsyncContext(AsyncContext&& other) {
4739
4713
  other._context = nullptr;
4740
4714
  }
4741
4715
 
4742
- inline AsyncContext& AsyncContext::operator =(AsyncContext&& other) {
4716
+ inline AsyncContext& AsyncContext::operator=(AsyncContext&& other) {
4743
4717
  _env = other._env;
4744
4718
  other._env = nullptr;
4745
4719
  _context = other._context;
@@ -4760,78 +4734,72 @@ inline Napi::Env AsyncContext::Env() const {
4760
4734
  ////////////////////////////////////////////////////////////////////////////////
4761
4735
 
4762
4736
  inline AsyncWorker::AsyncWorker(const Function& callback)
4763
- : AsyncWorker(callback, "generic") {
4764
- }
4737
+ : AsyncWorker(callback, "generic") {}
4765
4738
 
4766
4739
  inline AsyncWorker::AsyncWorker(const Function& callback,
4767
4740
  const char* resource_name)
4768
- : AsyncWorker(callback, resource_name, Object::New(callback.Env())) {
4769
- }
4741
+ : AsyncWorker(callback, resource_name, Object::New(callback.Env())) {}
4770
4742
 
4771
4743
  inline AsyncWorker::AsyncWorker(const Function& callback,
4772
4744
  const char* resource_name,
4773
4745
  const Object& resource)
4774
- : AsyncWorker(Object::New(callback.Env()),
4775
- callback,
4776
- resource_name,
4777
- resource) {
4778
- }
4746
+ : AsyncWorker(
4747
+ Object::New(callback.Env()), callback, resource_name, resource) {}
4779
4748
 
4780
4749
  inline AsyncWorker::AsyncWorker(const Object& receiver,
4781
4750
  const Function& callback)
4782
- : AsyncWorker(receiver, callback, "generic") {
4783
- }
4751
+ : AsyncWorker(receiver, callback, "generic") {}
4784
4752
 
4785
4753
  inline AsyncWorker::AsyncWorker(const Object& receiver,
4786
4754
  const Function& callback,
4787
4755
  const char* resource_name)
4788
- : AsyncWorker(receiver,
4789
- callback,
4790
- resource_name,
4791
- Object::New(callback.Env())) {
4792
- }
4756
+ : AsyncWorker(
4757
+ receiver, callback, resource_name, Object::New(callback.Env())) {}
4793
4758
 
4794
4759
  inline AsyncWorker::AsyncWorker(const Object& receiver,
4795
4760
  const Function& callback,
4796
4761
  const char* resource_name,
4797
4762
  const Object& resource)
4798
- : _env(callback.Env()),
4799
- _receiver(Napi::Persistent(receiver)),
4800
- _callback(Napi::Persistent(callback)),
4801
- _suppress_destruct(false) {
4763
+ : _env(callback.Env()),
4764
+ _receiver(Napi::Persistent(receiver)),
4765
+ _callback(Napi::Persistent(callback)),
4766
+ _suppress_destruct(false) {
4802
4767
  napi_value resource_id;
4803
4768
  napi_status status = napi_create_string_latin1(
4804
4769
  _env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4805
4770
  NAPI_THROW_IF_FAILED_VOID(_env, status);
4806
4771
 
4807
- status = napi_create_async_work(_env, resource, resource_id, OnAsyncWorkExecute,
4808
- OnAsyncWorkComplete, this, &_work);
4772
+ status = napi_create_async_work(_env,
4773
+ resource,
4774
+ resource_id,
4775
+ OnAsyncWorkExecute,
4776
+ OnAsyncWorkComplete,
4777
+ this,
4778
+ &_work);
4809
4779
  NAPI_THROW_IF_FAILED_VOID(_env, status);
4810
4780
  }
4811
4781
 
4812
- inline AsyncWorker::AsyncWorker(Napi::Env env)
4813
- : AsyncWorker(env, "generic") {
4814
- }
4782
+ inline AsyncWorker::AsyncWorker(Napi::Env env) : AsyncWorker(env, "generic") {}
4815
4783
 
4816
- inline AsyncWorker::AsyncWorker(Napi::Env env,
4817
- const char* resource_name)
4818
- : AsyncWorker(env, resource_name, Object::New(env)) {
4819
- }
4784
+ inline AsyncWorker::AsyncWorker(Napi::Env env, const char* resource_name)
4785
+ : AsyncWorker(env, resource_name, Object::New(env)) {}
4820
4786
 
4821
4787
  inline AsyncWorker::AsyncWorker(Napi::Env env,
4822
4788
  const char* resource_name,
4823
4789
  const Object& resource)
4824
- : _env(env),
4825
- _receiver(),
4826
- _callback(),
4827
- _suppress_destruct(false) {
4790
+ : _env(env), _receiver(), _callback(), _suppress_destruct(false) {
4828
4791
  napi_value resource_id;
4829
4792
  napi_status status = napi_create_string_latin1(
4830
4793
  _env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4831
4794
  NAPI_THROW_IF_FAILED_VOID(_env, status);
4832
4795
 
4833
- status = napi_create_async_work(_env, resource, resource_id, OnAsyncWorkExecute,
4834
- OnAsyncWorkComplete, this, &_work);
4796
+ status = napi_create_async_work(_env,
4797
+ resource,
4798
+ resource_id,
4799
+ OnAsyncWorkExecute,
4800
+ OnAsyncWorkComplete,
4801
+ this,
4802
+ &_work);
4835
4803
  NAPI_THROW_IF_FAILED_VOID(_env, status);
4836
4804
  }
4837
4805
 
@@ -4846,29 +4814,6 @@ inline void AsyncWorker::Destroy() {
4846
4814
  delete this;
4847
4815
  }
4848
4816
 
4849
- inline AsyncWorker::AsyncWorker(AsyncWorker&& other) {
4850
- _env = other._env;
4851
- other._env = nullptr;
4852
- _work = other._work;
4853
- other._work = nullptr;
4854
- _receiver = std::move(other._receiver);
4855
- _callback = std::move(other._callback);
4856
- _error = std::move(other._error);
4857
- _suppress_destruct = other._suppress_destruct;
4858
- }
4859
-
4860
- inline AsyncWorker& AsyncWorker::operator =(AsyncWorker&& other) {
4861
- _env = other._env;
4862
- other._env = nullptr;
4863
- _work = other._work;
4864
- other._work = nullptr;
4865
- _receiver = std::move(other._receiver);
4866
- _callback = std::move(other._callback);
4867
- _error = std::move(other._error);
4868
- _suppress_destruct = other._suppress_destruct;
4869
- return *this;
4870
- }
4871
-
4872
4817
  inline AsyncWorker::operator napi_async_work() const {
4873
4818
  return _work;
4874
4819
  }
@@ -4907,7 +4852,8 @@ inline void AsyncWorker::OnOK() {
4907
4852
 
4908
4853
  inline void AsyncWorker::OnError(const Error& e) {
4909
4854
  if (!_callback.IsEmpty()) {
4910
- _callback.Call(_receiver.Value(), std::initializer_list<napi_value>{ e.Value() });
4855
+ _callback.Call(_receiver.Value(),
4856
+ std::initializer_list<napi_value>{e.Value()});
4911
4857
  }
4912
4858
  }
4913
4859
 
@@ -4937,9 +4883,9 @@ inline void AsyncWorker::OnExecute(Napi::Env /*DO_NOT_USE*/) {
4937
4883
  } catch (const std::exception& e) {
4938
4884
  SetError(e.what());
4939
4885
  }
4940
- #else // NAPI_CPP_EXCEPTIONS
4886
+ #else // NAPI_CPP_EXCEPTIONS
4941
4887
  Execute();
4942
- #endif // NAPI_CPP_EXCEPTIONS
4888
+ #endif // NAPI_CPP_EXCEPTIONS
4943
4889
  }
4944
4890
 
4945
4891
  inline void AsyncWorker::OnAsyncWorkComplete(napi_env env,
@@ -4954,8 +4900,7 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env /*env*/, napi_status status) {
4954
4900
  details::WrapCallback([&] {
4955
4901
  if (_error.size() == 0) {
4956
4902
  OnOK();
4957
- }
4958
- else {
4903
+ } else {
4959
4904
  OnError(Error::New(_env, _error));
4960
4905
  }
4961
4906
  return nullptr;
@@ -5458,68 +5403,93 @@ TypedThreadSafeFunction<ContextType, DataType, CallJs>::FunctionOrEmpty(
5458
5403
  // static
5459
5404
  template <typename ResourceString>
5460
5405
  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);
5406
+ const Function& callback,
5407
+ ResourceString resourceName,
5408
+ size_t maxQueueSize,
5409
+ size_t initialThreadCount) {
5410
+ return New(
5411
+ env, callback, Object(), resourceName, maxQueueSize, initialThreadCount);
5467
5412
  }
5468
5413
 
5469
5414
  // static
5470
5415
  template <typename ResourceString, typename ContextType>
5471
5416
  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);
5417
+ const Function& callback,
5418
+ ResourceString resourceName,
5419
+ size_t maxQueueSize,
5420
+ size_t initialThreadCount,
5421
+ ContextType* context) {
5422
+ return New(env,
5423
+ callback,
5424
+ Object(),
5425
+ resourceName,
5426
+ maxQueueSize,
5427
+ initialThreadCount,
5428
+ context);
5479
5429
  }
5480
5430
 
5481
5431
  // static
5482
5432
  template <typename ResourceString, typename Finalizer>
5483
5433
  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);
5434
+ const Function& callback,
5435
+ ResourceString resourceName,
5436
+ size_t maxQueueSize,
5437
+ size_t initialThreadCount,
5438
+ Finalizer finalizeCallback) {
5439
+ return New(env,
5440
+ callback,
5441
+ Object(),
5442
+ resourceName,
5443
+ maxQueueSize,
5444
+ initialThreadCount,
5445
+ finalizeCallback);
5491
5446
  }
5492
5447
 
5493
5448
  // static
5494
- template <typename ResourceString, typename Finalizer,
5449
+ template <typename ResourceString,
5450
+ typename Finalizer,
5495
5451
  typename FinalizerDataType>
5496
5452
  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);
5453
+ const Function& callback,
5454
+ ResourceString resourceName,
5455
+ size_t maxQueueSize,
5456
+ size_t initialThreadCount,
5457
+ Finalizer finalizeCallback,
5458
+ FinalizerDataType* data) {
5459
+ return New(env,
5460
+ callback,
5461
+ Object(),
5462
+ resourceName,
5463
+ maxQueueSize,
5464
+ initialThreadCount,
5465
+ finalizeCallback,
5466
+ data);
5505
5467
  }
5506
5468
 
5507
5469
  // static
5508
5470
  template <typename ResourceString, typename ContextType, typename Finalizer>
5509
5471
  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);
5472
+ const Function& callback,
5473
+ ResourceString resourceName,
5474
+ size_t maxQueueSize,
5475
+ size_t initialThreadCount,
5476
+ ContextType* context,
5477
+ Finalizer finalizeCallback) {
5478
+ return New(env,
5479
+ callback,
5480
+ Object(),
5481
+ resourceName,
5482
+ maxQueueSize,
5483
+ initialThreadCount,
5484
+ context,
5485
+ finalizeCallback);
5518
5486
  }
5519
5487
 
5520
5488
  // static
5521
- template <typename ResourceString, typename ContextType,
5522
- typename Finalizer, typename FinalizerDataType>
5489
+ template <typename ResourceString,
5490
+ typename ContextType,
5491
+ typename Finalizer,
5492
+ typename FinalizerDataType>
5523
5493
  inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5524
5494
  const Function& callback,
5525
5495
  ResourceString resourceName,
@@ -5528,89 +5498,128 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5528
5498
  ContextType* context,
5529
5499
  Finalizer finalizeCallback,
5530
5500
  FinalizerDataType* data) {
5531
- return New(env, callback, Object(), resourceName, maxQueueSize,
5532
- initialThreadCount, context, finalizeCallback, data);
5501
+ return New(env,
5502
+ callback,
5503
+ Object(),
5504
+ resourceName,
5505
+ maxQueueSize,
5506
+ initialThreadCount,
5507
+ context,
5508
+ finalizeCallback,
5509
+ data);
5533
5510
  }
5534
5511
 
5535
5512
  // static
5536
5513
  template <typename ResourceString>
5537
5514
  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 */);
5515
+ const Function& callback,
5516
+ const Object& resource,
5517
+ ResourceString resourceName,
5518
+ size_t maxQueueSize,
5519
+ size_t initialThreadCount) {
5520
+ return New(env,
5521
+ callback,
5522
+ resource,
5523
+ resourceName,
5524
+ maxQueueSize,
5525
+ initialThreadCount,
5526
+ static_cast<void*>(nullptr) /* context */);
5545
5527
  }
5546
5528
 
5547
5529
  // static
5548
5530
  template <typename ResourceString, typename ContextType>
5549
5531
  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,
5532
+ const Function& callback,
5533
+ const Object& resource,
5534
+ ResourceString resourceName,
5535
+ size_t maxQueueSize,
5536
+ size_t initialThreadCount,
5537
+ ContextType* context) {
5538
+ return New(env,
5539
+ callback,
5540
+ resource,
5541
+ resourceName,
5542
+ maxQueueSize,
5543
+ initialThreadCount,
5544
+ context,
5558
5545
  [](Env, ContextType*) {} /* empty finalizer */);
5559
5546
  }
5560
5547
 
5561
5548
  // static
5562
5549
  template <typename ResourceString, typename Finalizer>
5563
5550
  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 */,
5551
+ const Function& callback,
5552
+ const Object& resource,
5553
+ ResourceString resourceName,
5554
+ size_t maxQueueSize,
5555
+ size_t initialThreadCount,
5556
+ Finalizer finalizeCallback) {
5557
+ return New(env,
5558
+ callback,
5559
+ resource,
5560
+ resourceName,
5561
+ maxQueueSize,
5562
+ initialThreadCount,
5563
+ static_cast<void*>(nullptr) /* context */,
5564
+ finalizeCallback,
5565
+ static_cast<void*>(nullptr) /* data */,
5573
5566
  details::ThreadSafeFinalize<void, Finalizer>::Wrapper);
5574
5567
  }
5575
5568
 
5576
5569
  // static
5577
- template <typename ResourceString, typename Finalizer,
5570
+ template <typename ResourceString,
5571
+ typename Finalizer,
5578
5572
  typename FinalizerDataType>
5579
5573
  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);
5574
+ const Function& callback,
5575
+ const Object& resource,
5576
+ ResourceString resourceName,
5577
+ size_t maxQueueSize,
5578
+ size_t initialThreadCount,
5579
+ Finalizer finalizeCallback,
5580
+ FinalizerDataType* data) {
5581
+ return New(env,
5582
+ callback,
5583
+ resource,
5584
+ resourceName,
5585
+ maxQueueSize,
5586
+ initialThreadCount,
5587
+ static_cast<void*>(nullptr) /* context */,
5588
+ finalizeCallback,
5589
+ data,
5590
+ details::ThreadSafeFinalize<void, Finalizer, FinalizerDataType>::
5591
+ FinalizeWrapperWithData);
5592
5592
  }
5593
5593
 
5594
5594
  // static
5595
5595
  template <typename ResourceString, typename ContextType, typename Finalizer>
5596
5596
  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);
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(
5605
+ env,
5606
+ callback,
5607
+ resource,
5608
+ resourceName,
5609
+ maxQueueSize,
5610
+ initialThreadCount,
5611
+ context,
5612
+ finalizeCallback,
5613
+ static_cast<void*>(nullptr) /* data */,
5614
+ details::ThreadSafeFinalize<ContextType,
5615
+ Finalizer>::FinalizeWrapperWithContext);
5609
5616
  }
5610
5617
 
5611
5618
  // static
5612
- template <typename ResourceString, typename ContextType,
5613
- typename Finalizer, typename FinalizerDataType>
5619
+ template <typename ResourceString,
5620
+ typename ContextType,
5621
+ typename Finalizer,
5622
+ typename FinalizerDataType>
5614
5623
  inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5615
5624
  const Function& callback,
5616
5625
  const Object& resource,
@@ -5620,20 +5629,24 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5620
5629
  ContextType* context,
5621
5630
  Finalizer finalizeCallback,
5622
5631
  FinalizerDataType* data) {
5623
- return New(env, callback, resource, resourceName, maxQueueSize,
5624
- initialThreadCount, context, finalizeCallback, data,
5625
- details::ThreadSafeFinalize<ContextType, Finalizer,
5626
- FinalizerDataType>::FinalizeFinalizeWrapperWithDataAndContext);
5632
+ return New(
5633
+ env,
5634
+ callback,
5635
+ resource,
5636
+ resourceName,
5637
+ maxQueueSize,
5638
+ initialThreadCount,
5639
+ context,
5640
+ finalizeCallback,
5641
+ data,
5642
+ details::ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>::
5643
+ FinalizeFinalizeWrapperWithDataAndContext);
5627
5644
  }
5628
5645
 
5629
- inline ThreadSafeFunction::ThreadSafeFunction()
5630
- : _tsfn() {
5631
- }
5646
+ inline ThreadSafeFunction::ThreadSafeFunction() : _tsfn() {}
5632
5647
 
5633
- inline ThreadSafeFunction::ThreadSafeFunction(
5634
- napi_threadsafe_function tsfn)
5635
- : _tsfn(tsfn) {
5636
- }
5648
+ inline ThreadSafeFunction::ThreadSafeFunction(napi_threadsafe_function tsfn)
5649
+ : _tsfn(tsfn) {}
5637
5650
 
5638
5651
  inline ThreadSafeFunction::operator napi_threadsafe_function() const {
5639
5652
  return _tsfn;
@@ -5644,20 +5657,18 @@ inline napi_status ThreadSafeFunction::BlockingCall() const {
5644
5657
  }
5645
5658
 
5646
5659
  template <>
5647
- inline napi_status ThreadSafeFunction::BlockingCall(
5648
- void* data) const {
5660
+ inline napi_status ThreadSafeFunction::BlockingCall(void* data) const {
5649
5661
  return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_blocking);
5650
5662
  }
5651
5663
 
5652
5664
  template <typename Callback>
5653
- inline napi_status ThreadSafeFunction::BlockingCall(
5654
- Callback callback) const {
5665
+ inline napi_status ThreadSafeFunction::BlockingCall(Callback callback) const {
5655
5666
  return CallInternal(new CallbackWrapper(callback), napi_tsfn_blocking);
5656
5667
  }
5657
5668
 
5658
5669
  template <typename DataType, typename Callback>
5659
- inline napi_status ThreadSafeFunction::BlockingCall(
5660
- DataType* data, Callback callback) const {
5670
+ inline napi_status ThreadSafeFunction::BlockingCall(DataType* data,
5671
+ Callback callback) const {
5661
5672
  auto wrapper = [data, callback](Env env, Function jsCallback) {
5662
5673
  callback(env, jsCallback, data);
5663
5674
  };
@@ -5669,8 +5680,7 @@ inline napi_status ThreadSafeFunction::NonBlockingCall() const {
5669
5680
  }
5670
5681
 
5671
5682
  template <>
5672
- inline napi_status ThreadSafeFunction::NonBlockingCall(
5673
- void* data) const {
5683
+ inline napi_status ThreadSafeFunction::NonBlockingCall(void* data) const {
5674
5684
  return napi_call_threadsafe_function(_tsfn, data, napi_tsfn_nonblocking);
5675
5685
  }
5676
5686
 
@@ -5715,17 +5725,21 @@ inline napi_status ThreadSafeFunction::Abort() const {
5715
5725
  return napi_release_threadsafe_function(_tsfn, napi_tsfn_abort);
5716
5726
  }
5717
5727
 
5718
- inline ThreadSafeFunction::ConvertibleContext
5719
- ThreadSafeFunction::GetContext() const {
5728
+ inline ThreadSafeFunction::ConvertibleContext ThreadSafeFunction::GetContext()
5729
+ const {
5720
5730
  void* context;
5721
5731
  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 });
5732
+ NAPI_FATAL_IF_FAILED(status,
5733
+ "ThreadSafeFunction::GetContext",
5734
+ "napi_get_threadsafe_function_context");
5735
+ return ConvertibleContext({context});
5724
5736
  }
5725
5737
 
5726
5738
  // static
5727
- template <typename ResourceString, typename ContextType,
5728
- typename Finalizer, typename FinalizerDataType>
5739
+ template <typename ResourceString,
5740
+ typename ContextType,
5741
+ typename Finalizer,
5742
+ typename FinalizerDataType>
5729
5743
  inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5730
5744
  const Function& callback,
5731
5745
  const Object& resource,
@@ -5736,16 +5750,26 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5736
5750
  Finalizer finalizeCallback,
5737
5751
  FinalizerDataType* data,
5738
5752
  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");
5753
+ static_assert(details::can_make_string<ResourceString>::value ||
5754
+ std::is_convertible<ResourceString, napi_value>::value,
5755
+ "Resource name should be convertible to the string type");
5742
5756
 
5743
5757
  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);
5758
+ auto* finalizeData = new details::
5759
+ ThreadSafeFinalize<ContextType, Finalizer, FinalizerDataType>(
5760
+ {data, finalizeCallback});
5761
+ napi_status status =
5762
+ napi_create_threadsafe_function(env,
5763
+ callback,
5764
+ resource,
5765
+ Value::From(env, resourceName),
5766
+ maxQueueSize,
5767
+ initialThreadCount,
5768
+ finalizeData,
5769
+ wrapper,
5770
+ context,
5771
+ CallJS,
5772
+ &tsfn._tsfn);
5749
5773
  if (status != napi_ok) {
5750
5774
  delete finalizeData;
5751
5775
  NAPI_THROW_IF_FAILED(env, status, ThreadSafeFunction());
@@ -5757,8 +5781,8 @@ inline ThreadSafeFunction ThreadSafeFunction::New(napi_env env,
5757
5781
  inline napi_status ThreadSafeFunction::CallInternal(
5758
5782
  CallbackWrapper* callbackWrapper,
5759
5783
  napi_threadsafe_function_call_mode mode) const {
5760
- napi_status status = napi_call_threadsafe_function(
5761
- _tsfn, callbackWrapper, mode);
5784
+ napi_status status =
5785
+ napi_call_threadsafe_function(_tsfn, callbackWrapper, mode);
5762
5786
  if (status != napi_ok && callbackWrapper != nullptr) {
5763
5787
  delete callbackWrapper;
5764
5788
  }
@@ -5788,13 +5812,15 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
5788
5812
  // Async Progress Worker Base class
5789
5813
  ////////////////////////////////////////////////////////////////////////////////
5790
5814
  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.
5815
+ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
5816
+ const Object& receiver,
5817
+ const Function& callback,
5818
+ const char* resource_name,
5819
+ const Object& resource,
5820
+ size_t queue_size)
5821
+ : AsyncWorker(receiver, callback, resource_name, resource) {
5822
+ // Fill all possible arguments to work around ambiguous
5823
+ // ThreadSafeFunction::New signatures.
5798
5824
  _tsfn = ThreadSafeFunction::New(callback.Env(),
5799
5825
  callback,
5800
5826
  resource,
@@ -5808,15 +5834,18 @@ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(const Object&
5808
5834
 
5809
5835
  #if NAPI_VERSION > 4
5810
5836
  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) {
5837
+ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(
5838
+ Napi::Env env,
5839
+ const char* resource_name,
5840
+ const Object& resource,
5841
+ size_t queue_size)
5842
+ : AsyncWorker(env, resource_name, resource) {
5816
5843
  // 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.
5844
+ // functions are available on all versions we can remove the dummy Function
5845
+ // here.
5818
5846
  Function callback;
5819
- // Fill all possible arguments to work around ambiguous ThreadSafeFunction::New signatures.
5847
+ // Fill all possible arguments to work around ambiguous
5848
+ // ThreadSafeFunction::New signatures.
5820
5849
  _tsfn = ThreadSafeFunction::New(env,
5821
5850
  callback,
5822
5851
  resource,
@@ -5829,38 +5858,45 @@ inline AsyncProgressWorkerBase<DataType>::AsyncProgressWorkerBase(Napi::Env env,
5829
5858
  }
5830
5859
  #endif
5831
5860
 
5832
- template<typename DataType>
5861
+ template <typename DataType>
5833
5862
  inline AsyncProgressWorkerBase<DataType>::~AsyncProgressWorkerBase() {
5834
5863
  // Abort pending tsfn call.
5835
5864
  // Don't send progress events after we've already completed.
5836
- // It's ok to call ThreadSafeFunction::Abort and ThreadSafeFunction::Release duplicated.
5865
+ // It's ok to call ThreadSafeFunction::Abort and ThreadSafeFunction::Release
5866
+ // duplicated.
5837
5867
  _tsfn.Abort();
5838
5868
  }
5839
5869
 
5840
5870
  template <typename DataType>
5841
- inline void AsyncProgressWorkerBase<DataType>::OnAsyncWorkProgress(Napi::Env /* env */,
5842
- Napi::Function /* jsCallback */,
5843
- void* data) {
5871
+ inline void AsyncProgressWorkerBase<DataType>::OnAsyncWorkProgress(
5872
+ Napi::Env /* env */, Napi::Function /* jsCallback */, void* data) {
5844
5873
  ThreadSafeData* tsd = static_cast<ThreadSafeData*>(data);
5845
5874
  tsd->asyncprogressworker()->OnWorkProgress(tsd->data());
5846
5875
  delete tsd;
5847
5876
  }
5848
5877
 
5849
5878
  template <typename DataType>
5850
- inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(DataType* data) {
5879
+ inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(
5880
+ DataType* data) {
5851
5881
  auto tsd = new AsyncProgressWorkerBase::ThreadSafeData(this, data);
5852
- return _tsfn.NonBlockingCall(tsd, OnAsyncWorkProgress);
5882
+ auto ret = _tsfn.NonBlockingCall(tsd, OnAsyncWorkProgress);
5883
+ if (ret != napi_ok) {
5884
+ delete tsd;
5885
+ }
5886
+ return ret;
5853
5887
  }
5854
5888
 
5855
5889
  template <typename DataType>
5856
- inline void AsyncProgressWorkerBase<DataType>::OnWorkComplete(Napi::Env /* env */, napi_status status) {
5890
+ inline void AsyncProgressWorkerBase<DataType>::OnWorkComplete(
5891
+ Napi::Env /* env */, napi_status status) {
5857
5892
  _work_completed = true;
5858
5893
  _complete_status = status;
5859
5894
  _tsfn.Release();
5860
5895
  }
5861
5896
 
5862
5897
  template <typename DataType>
5863
- inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(Napi::Env env, void* /* data */, AsyncProgressWorkerBase* context) {
5898
+ inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(
5899
+ Napi::Env env, void* /* data */, AsyncProgressWorkerBase* context) {
5864
5900
  if (context->_work_completed) {
5865
5901
  context->AsyncWorker::OnWorkComplete(env, context->_complete_status);
5866
5902
  }
@@ -5869,76 +5905,65 @@ inline void AsyncProgressWorkerBase<DataType>::OnThreadSafeFunctionFinalize(Napi
5869
5905
  ////////////////////////////////////////////////////////////////////////////////
5870
5906
  // Async Progress Worker class
5871
5907
  ////////////////////////////////////////////////////////////////////////////////
5872
- template<class T>
5908
+ template <class T>
5873
5909
  inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback)
5874
- : AsyncProgressWorker(callback, "generic") {
5875
- }
5910
+ : AsyncProgressWorker(callback, "generic") {}
5876
5911
 
5877
- template<class T>
5912
+ template <class T>
5878
5913
  inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback,
5879
- const char* resource_name)
5880
- : AsyncProgressWorker(callback, resource_name, Object::New(callback.Env())) {
5881
- }
5914
+ const char* resource_name)
5915
+ : AsyncProgressWorker(
5916
+ callback, resource_name, Object::New(callback.Env())) {}
5882
5917
 
5883
- template<class T>
5918
+ template <class T>
5884
5919
  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
- }
5920
+ const char* resource_name,
5921
+ const Object& resource)
5922
+ : AsyncProgressWorker(
5923
+ Object::New(callback.Env()), callback, resource_name, resource) {}
5892
5924
 
5893
- template<class T>
5925
+ template <class T>
5894
5926
  inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
5895
5927
  const Function& callback)
5896
- : AsyncProgressWorker(receiver, callback, "generic") {
5897
- }
5928
+ : AsyncProgressWorker(receiver, callback, "generic") {}
5898
5929
 
5899
- template<class T>
5930
+ template <class T>
5900
5931
  inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
5901
5932
  const Function& callback,
5902
5933
  const char* resource_name)
5903
- : AsyncProgressWorker(receiver,
5904
- callback,
5905
- resource_name,
5906
- Object::New(callback.Env())) {
5907
- }
5934
+ : AsyncProgressWorker(
5935
+ receiver, callback, resource_name, Object::New(callback.Env())) {}
5908
5936
 
5909
- template<class T>
5937
+ template <class T>
5910
5938
  inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
5911
5939
  const Function& callback,
5912
5940
  const char* resource_name,
5913
5941
  const Object& resource)
5914
- : AsyncProgressWorkerBase(receiver, callback, resource_name, resource),
5915
- _asyncdata(nullptr),
5916
- _asyncsize(0) {
5917
- }
5942
+ : AsyncProgressWorkerBase(receiver, callback, resource_name, resource),
5943
+ _asyncdata(nullptr),
5944
+ _asyncsize(0),
5945
+ _signaled(false) {}
5918
5946
 
5919
5947
  #if NAPI_VERSION > 4
5920
- template<class T>
5948
+ template <class T>
5921
5949
  inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env)
5922
- : AsyncProgressWorker(env, "generic") {
5923
- }
5950
+ : AsyncProgressWorker(env, "generic") {}
5924
5951
 
5925
- template<class T>
5952
+ template <class T>
5926
5953
  inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
5927
5954
  const char* resource_name)
5928
- : AsyncProgressWorker(env, resource_name, Object::New(env)) {
5929
- }
5955
+ : AsyncProgressWorker(env, resource_name, Object::New(env)) {}
5930
5956
 
5931
- template<class T>
5957
+ template <class T>
5932
5958
  inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
5933
5959
  const char* resource_name,
5934
5960
  const Object& resource)
5935
- : AsyncProgressWorkerBase(env, resource_name, resource),
5936
- _asyncdata(nullptr),
5937
- _asyncsize(0) {
5938
- }
5961
+ : AsyncProgressWorkerBase(env, resource_name, resource),
5962
+ _asyncdata(nullptr),
5963
+ _asyncsize(0) {}
5939
5964
  #endif
5940
5965
 
5941
- template<class T>
5966
+ template <class T>
5942
5967
  inline AsyncProgressWorker<T>::~AsyncProgressWorker() {
5943
5968
  {
5944
5969
  std::lock_guard<std::mutex> lock(this->_mutex);
@@ -5947,22 +5972,25 @@ inline AsyncProgressWorker<T>::~AsyncProgressWorker() {
5947
5972
  }
5948
5973
  }
5949
5974
 
5950
- template<class T>
5975
+ template <class T>
5951
5976
  inline void AsyncProgressWorker<T>::Execute() {
5952
5977
  ExecutionProgress progress(this);
5953
5978
  Execute(progress);
5954
5979
  }
5955
5980
 
5956
- template<class T>
5981
+ template <class T>
5957
5982
  inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
5958
5983
  T* data;
5959
5984
  size_t size;
5985
+ bool signaled;
5960
5986
  {
5961
5987
  std::lock_guard<std::mutex> lock(this->_mutex);
5962
5988
  data = this->_asyncdata;
5963
5989
  size = this->_asyncsize;
5990
+ signaled = this->_signaled;
5964
5991
  this->_asyncdata = nullptr;
5965
5992
  this->_asyncsize = 0;
5993
+ this->_signaled = false;
5966
5994
  }
5967
5995
 
5968
5996
  /**
@@ -5972,7 +6000,7 @@ inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
5972
6000
  * the deferring the signal of uv_async_t is been sent again, i.e. potential
5973
6001
  * not coalesced two calls of the TSFN callback.
5974
6002
  */
5975
- if (data == nullptr) {
6003
+ if (data == nullptr && !signaled) {
5976
6004
  return;
5977
6005
  }
5978
6006
 
@@ -5980,119 +6008,119 @@ inline void AsyncProgressWorker<T>::OnWorkProgress(void*) {
5980
6008
  delete[] data;
5981
6009
  }
5982
6010
 
5983
- template<class T>
6011
+ template <class T>
5984
6012
  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);
6013
+ T* new_data = new T[count];
6014
+ std::copy(data, data + count, new_data);
6015
+
6016
+ T* old_data;
6017
+ {
6018
+ std::lock_guard<std::mutex> lock(this->_mutex);
6019
+ old_data = _asyncdata;
6020
+ _asyncdata = new_data;
6021
+ _asyncsize = count;
6022
+ _signaled = false;
6023
+ }
6024
+ this->NonBlockingCall(nullptr);
5996
6025
 
5997
- delete[] old_data;
6026
+ delete[] old_data;
5998
6027
  }
5999
6028
 
6000
- template<class T>
6001
- inline void AsyncProgressWorker<T>::Signal() const {
6029
+ template <class T>
6030
+ inline void AsyncProgressWorker<T>::Signal() {
6031
+ {
6032
+ std::lock_guard<std::mutex> lock(this->_mutex);
6033
+ _signaled = true;
6034
+ }
6002
6035
  this->NonBlockingCall(static_cast<T*>(nullptr));
6003
6036
  }
6004
6037
 
6005
- template<class T>
6038
+ template <class T>
6006
6039
  inline void AsyncProgressWorker<T>::ExecutionProgress::Signal() const {
6007
- _worker->Signal();
6040
+ this->_worker->Signal();
6008
6041
  }
6009
6042
 
6010
- template<class T>
6011
- inline void AsyncProgressWorker<T>::ExecutionProgress::Send(const T* data, size_t count) const {
6043
+ template <class T>
6044
+ inline void AsyncProgressWorker<T>::ExecutionProgress::Send(
6045
+ const T* data, size_t count) const {
6012
6046
  _worker->SendProgress_(data, count);
6013
6047
  }
6014
6048
 
6015
6049
  ////////////////////////////////////////////////////////////////////////////////
6016
6050
  // Async Progress Queue Worker class
6017
6051
  ////////////////////////////////////////////////////////////////////////////////
6018
- template<class T>
6019
- inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(const Function& callback)
6020
- : AsyncProgressQueueWorker(callback, "generic") {
6021
- }
6052
+ template <class T>
6053
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6054
+ const Function& callback)
6055
+ : AsyncProgressQueueWorker(callback, "generic") {}
6022
6056
 
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
- }
6057
+ template <class T>
6058
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6059
+ const Function& callback, const char* resource_name)
6060
+ : AsyncProgressQueueWorker(
6061
+ callback, resource_name, Object::New(callback.Env())) {}
6028
6062
 
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
- }
6063
+ template <class T>
6064
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6065
+ const Function& callback, const char* resource_name, const Object& resource)
6066
+ : AsyncProgressQueueWorker(
6067
+ Object::New(callback.Env()), callback, resource_name, resource) {}
6038
6068
 
6039
- template<class T>
6040
- inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(const Object& receiver,
6041
- const Function& callback)
6042
- : AsyncProgressQueueWorker(receiver, callback, "generic") {
6043
- }
6069
+ template <class T>
6070
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6071
+ const Object& receiver, const Function& callback)
6072
+ : AsyncProgressQueueWorker(receiver, callback, "generic") {}
6044
6073
 
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
- }
6074
+ template <class T>
6075
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6076
+ const Object& receiver, const Function& callback, const char* resource_name)
6077
+ : AsyncProgressQueueWorker(
6078
+ receiver, callback, resource_name, Object::New(callback.Env())) {}
6054
6079
 
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
- }
6080
+ template <class T>
6081
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6082
+ const Object& receiver,
6083
+ const Function& callback,
6084
+ const char* resource_name,
6085
+ const Object& resource)
6086
+ : AsyncProgressWorkerBase<std::pair<T*, size_t>>(
6087
+ receiver,
6088
+ callback,
6089
+ resource_name,
6090
+ resource,
6091
+ /** unlimited queue size */ 0) {}
6062
6092
 
6063
6093
  #if NAPI_VERSION > 4
6064
- template<class T>
6094
+ template <class T>
6065
6095
  inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(Napi::Env env)
6066
- : AsyncProgressQueueWorker(env, "generic") {
6067
- }
6096
+ : AsyncProgressQueueWorker(env, "generic") {}
6068
6097
 
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
- }
6098
+ template <class T>
6099
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6100
+ Napi::Env env, const char* resource_name)
6101
+ : AsyncProgressQueueWorker(env, resource_name, Object::New(env)) {}
6074
6102
 
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
- }
6103
+ template <class T>
6104
+ inline AsyncProgressQueueWorker<T>::AsyncProgressQueueWorker(
6105
+ Napi::Env env, const char* resource_name, const Object& resource)
6106
+ : AsyncProgressWorkerBase<std::pair<T*, size_t>>(
6107
+ env, resource_name, resource, /** unlimited queue size */ 0) {}
6081
6108
  #endif
6082
6109
 
6083
- template<class T>
6110
+ template <class T>
6084
6111
  inline void AsyncProgressQueueWorker<T>::Execute() {
6085
6112
  ExecutionProgress progress(this);
6086
6113
  Execute(progress);
6087
6114
  }
6088
6115
 
6089
- template<class T>
6090
- inline void AsyncProgressQueueWorker<T>::OnWorkProgress(std::pair<T*, size_t>* datapair) {
6116
+ template <class T>
6117
+ inline void AsyncProgressQueueWorker<T>::OnWorkProgress(
6118
+ std::pair<T*, size_t>* datapair) {
6091
6119
  if (datapair == nullptr) {
6092
6120
  return;
6093
6121
  }
6094
6122
 
6095
- T *data = datapair->first;
6123
+ T* data = datapair->first;
6096
6124
  size_t size = datapair->second;
6097
6125
 
6098
6126
  this->OnProgress(data, size);
@@ -6100,33 +6128,36 @@ inline void AsyncProgressQueueWorker<T>::OnWorkProgress(std::pair<T*, size_t>* d
6100
6128
  delete[] data;
6101
6129
  }
6102
6130
 
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);
6131
+ template <class T>
6132
+ inline void AsyncProgressQueueWorker<T>::SendProgress_(const T* data,
6133
+ size_t count) {
6134
+ T* new_data = new T[count];
6135
+ std::copy(data, data + count, new_data);
6107
6136
 
6108
- auto pair = new std::pair<T*, size_t>(new_data, count);
6109
- this->NonBlockingCall(pair);
6137
+ auto pair = new std::pair<T*, size_t>(new_data, count);
6138
+ this->NonBlockingCall(pair);
6110
6139
  }
6111
6140
 
6112
- template<class T>
6141
+ template <class T>
6113
6142
  inline void AsyncProgressQueueWorker<T>::Signal() const {
6114
- this->NonBlockingCall(nullptr);
6143
+ this->SendProgress_(static_cast<T*>(nullptr), 0);
6115
6144
  }
6116
6145
 
6117
- template<class T>
6118
- inline void AsyncProgressQueueWorker<T>::OnWorkComplete(Napi::Env env, napi_status status) {
6146
+ template <class T>
6147
+ inline void AsyncProgressQueueWorker<T>::OnWorkComplete(Napi::Env env,
6148
+ napi_status status) {
6119
6149
  // Draining queued items in TSFN.
6120
6150
  AsyncProgressWorkerBase<std::pair<T*, size_t>>::OnWorkComplete(env, status);
6121
6151
  }
6122
6152
 
6123
- template<class T>
6153
+ template <class T>
6124
6154
  inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Signal() const {
6125
- _worker->Signal();
6155
+ _worker->SendProgress_(static_cast<T*>(nullptr), 0);
6126
6156
  }
6127
6157
 
6128
- template<class T>
6129
- inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(const T* data, size_t count) const {
6158
+ template <class T>
6159
+ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(
6160
+ const T* data, size_t count) const {
6130
6161
  _worker->SendProgress_(data, count);
6131
6162
  }
6132
6163
  #endif // NAPI_VERSION > 3 && !defined(__wasm32__)
@@ -6135,9 +6166,11 @@ inline void AsyncProgressQueueWorker<T>::ExecutionProgress::Send(const T* data,
6135
6166
  // Memory Management class
6136
6167
  ////////////////////////////////////////////////////////////////////////////////
6137
6168
 
6138
- inline int64_t MemoryManagement::AdjustExternalMemory(Env env, int64_t change_in_bytes) {
6169
+ inline int64_t MemoryManagement::AdjustExternalMemory(Env env,
6170
+ int64_t change_in_bytes) {
6139
6171
  int64_t result;
6140
- napi_status status = napi_adjust_external_memory(env, change_in_bytes, &result);
6172
+ napi_status status =
6173
+ napi_adjust_external_memory(env, change_in_bytes, &result);
6141
6174
  NAPI_THROW_IF_FAILED(env, status, 0);
6142
6175
  return result;
6143
6176
  }
@@ -6178,24 +6211,20 @@ inline T* Addon<T>::Unwrap(Object wrapper) {
6178
6211
  }
6179
6212
 
6180
6213
  template <typename T>
6181
- inline void
6182
- Addon<T>::DefineAddon(Object exports,
6183
- const std::initializer_list<AddonProp>& props) {
6214
+ inline void Addon<T>::DefineAddon(
6215
+ Object exports, const std::initializer_list<AddonProp>& props) {
6184
6216
  DefineProperties(exports, props);
6185
6217
  entry_point_ = exports;
6186
6218
  }
6187
6219
 
6188
6220
  template <typename T>
6189
- inline Napi::Object
6190
- Addon<T>::DefineProperties(Object object,
6191
- const std::initializer_list<AddonProp>& props) {
6221
+ inline Napi::Object Addon<T>::DefineProperties(
6222
+ Object object, const std::initializer_list<AddonProp>& props) {
6192
6223
  const napi_property_descriptor* properties =
6193
- reinterpret_cast<const napi_property_descriptor*>(props.begin());
6224
+ reinterpret_cast<const napi_property_descriptor*>(props.begin());
6194
6225
  size_t size = props.size();
6195
- napi_status status = napi_define_properties(object.Env(),
6196
- object,
6197
- size,
6198
- properties);
6226
+ napi_status status =
6227
+ napi_define_properties(object.Env(), object, size, properties);
6199
6228
  NAPI_THROW_IF_FAILED(object.Env(), status, object);
6200
6229
  for (size_t idx = 0; idx < size; idx++)
6201
6230
  T::AttachPropData(object.Env(), object, &properties[idx]);
@@ -6214,6 +6243,11 @@ Env::CleanupHook<Hook> Env::AddCleanupHook(Hook hook) {
6214
6243
  return CleanupHook<Hook>(*this, hook);
6215
6244
  }
6216
6245
 
6246
+ template <typename Hook, typename Arg>
6247
+ Env::CleanupHook<Hook, Arg>::CleanupHook() {
6248
+ data = nullptr;
6249
+ }
6250
+
6217
6251
  template <typename Hook, typename Arg>
6218
6252
  Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::Env env, Hook hook)
6219
6253
  : wrapper(Env::CleanupHook<Hook, Arg>::Wrapper) {
@@ -6254,6 +6288,6 @@ bool Env::CleanupHook<Hook, Arg>::IsEmpty() const {
6254
6288
  } // namespace NAPI_CPP_CUSTOM_NAMESPACE
6255
6289
  #endif
6256
6290
 
6257
- } // namespace Napi
6291
+ } // namespace Napi
6258
6292
 
6259
- #endif // SRC_NAPI_INL_H_
6293
+ #endif // SRC_NAPI_INL_H_