koffi 1.0.5 → 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +46 -21
  2. package/build/qemu/1.1.0-beta.0/koffi_darwin_x64.tar.gz +0 -0
  3. package/build/qemu/1.1.0-beta.0/koffi_freebsd_arm64.tar.gz +0 -0
  4. package/build/qemu/1.1.0-beta.0/koffi_freebsd_ia32.tar.gz +0 -0
  5. package/build/qemu/1.1.0-beta.0/koffi_freebsd_x64.tar.gz +0 -0
  6. package/build/qemu/1.1.0-beta.0/koffi_linux_arm.tar.gz +0 -0
  7. package/build/qemu/1.1.0-beta.0/koffi_linux_arm64.tar.gz +0 -0
  8. package/build/qemu/1.1.0-beta.0/koffi_linux_ia32.tar.gz +0 -0
  9. package/build/qemu/1.1.0-beta.0/koffi_linux_x64.tar.gz +0 -0
  10. package/build/qemu/1.1.0-beta.0/koffi_win32_ia32.tar.gz +0 -0
  11. package/build/qemu/1.1.0-beta.0/koffi_win32_x64.tar.gz +0 -0
  12. package/package.json +1 -1
  13. package/qemu/qemu.js +11 -5
  14. package/qemu/registry/machines.json +20 -10
  15. package/src/abi_arm32.cc +13 -6
  16. package/src/abi_arm64.cc +13 -6
  17. package/src/abi_x64_sysv.cc +13 -6
  18. package/src/abi_x64_win.cc +13 -6
  19. package/src/abi_x86.cc +13 -6
  20. package/src/call.cc +25 -26
  21. package/src/call.hh +27 -41
  22. package/src/ffi.cc +152 -17
  23. package/src/ffi.hh +24 -10
  24. package/test/misc.c +2 -2
  25. package/build/qemu/1.0.5/koffi_darwin_x64.tar.gz +0 -0
  26. package/build/qemu/1.0.5/koffi_freebsd_arm64.tar.gz +0 -0
  27. package/build/qemu/1.0.5/koffi_freebsd_ia32.tar.gz +0 -0
  28. package/build/qemu/1.0.5/koffi_freebsd_x64.tar.gz +0 -0
  29. package/build/qemu/1.0.5/koffi_linux_arm.tar.gz +0 -0
  30. package/build/qemu/1.0.5/koffi_linux_arm64.tar.gz +0 -0
  31. package/build/qemu/1.0.5/koffi_linux_ia32.tar.gz +0 -0
  32. package/build/qemu/1.0.5/koffi_linux_x64.tar.gz +0 -0
  33. package/build/qemu/1.0.5/koffi_win32_ia32.tar.gz +0 -0
  34. package/build/qemu/1.0.5/koffi_win32_x64.tar.gz +0 -0
  35. package/test/misc.js +0 -227
  36. package/vendor/node-addon-api/CODE_OF_CONDUCT.md +0 -4
  37. package/vendor/node-addon-api/CONTRIBUTING.md +0 -93
  38. package/vendor/node-addon-api/appveyor.yml +0 -37
  39. package/vendor/node-addon-api/benchmark/README.md +0 -47
  40. package/vendor/node-addon-api/benchmark/binding.gyp +0 -25
  41. package/vendor/node-addon-api/benchmark/function_args.cc +0 -217
  42. package/vendor/node-addon-api/benchmark/function_args.js +0 -60
  43. package/vendor/node-addon-api/benchmark/index.js +0 -34
  44. package/vendor/node-addon-api/benchmark/property_descriptor.cc +0 -91
  45. package/vendor/node-addon-api/benchmark/property_descriptor.js +0 -37
  46. package/vendor/node-addon-api/doc/addon.md +0 -163
  47. package/vendor/node-addon-api/doc/array.md +0 -81
  48. package/vendor/node-addon-api/doc/array_buffer.md +0 -155
  49. package/vendor/node-addon-api/doc/async_context.md +0 -86
  50. package/vendor/node-addon-api/doc/async_operations.md +0 -31
  51. package/vendor/node-addon-api/doc/async_worker.md +0 -427
  52. package/vendor/node-addon-api/doc/async_worker_variants.md +0 -557
  53. package/vendor/node-addon-api/doc/bigint.md +0 -97
  54. package/vendor/node-addon-api/doc/boolean.md +0 -68
  55. package/vendor/node-addon-api/doc/buffer.md +0 -150
  56. package/vendor/node-addon-api/doc/callback_scope.md +0 -54
  57. package/vendor/node-addon-api/doc/callbackinfo.md +0 -97
  58. package/vendor/node-addon-api/doc/checker-tool.md +0 -32
  59. package/vendor/node-addon-api/doc/class_property_descriptor.md +0 -123
  60. package/vendor/node-addon-api/doc/cmake-js.md +0 -68
  61. package/vendor/node-addon-api/doc/conversion-tool.md +0 -28
  62. package/vendor/node-addon-api/doc/creating_a_release.md +0 -62
  63. package/vendor/node-addon-api/doc/dataview.md +0 -248
  64. package/vendor/node-addon-api/doc/date.md +0 -68
  65. package/vendor/node-addon-api/doc/env.md +0 -196
  66. package/vendor/node-addon-api/doc/error.md +0 -120
  67. package/vendor/node-addon-api/doc/error_handling.md +0 -254
  68. package/vendor/node-addon-api/doc/escapable_handle_scope.md +0 -80
  69. package/vendor/node-addon-api/doc/external.md +0 -63
  70. package/vendor/node-addon-api/doc/function.md +0 -402
  71. package/vendor/node-addon-api/doc/function_reference.md +0 -238
  72. package/vendor/node-addon-api/doc/generator.md +0 -13
  73. package/vendor/node-addon-api/doc/handle_scope.md +0 -63
  74. package/vendor/node-addon-api/doc/hierarchy.md +0 -91
  75. package/vendor/node-addon-api/doc/instance_wrap.md +0 -408
  76. package/vendor/node-addon-api/doc/maybe.md +0 -76
  77. package/vendor/node-addon-api/doc/memory_management.md +0 -27
  78. package/vendor/node-addon-api/doc/name.md +0 -29
  79. package/vendor/node-addon-api/doc/node-gyp.md +0 -82
  80. package/vendor/node-addon-api/doc/number.md +0 -163
  81. package/vendor/node-addon-api/doc/object.md +0 -411
  82. package/vendor/node-addon-api/doc/object_lifetime_management.md +0 -83
  83. package/vendor/node-addon-api/doc/object_reference.md +0 -117
  84. package/vendor/node-addon-api/doc/object_wrap.md +0 -588
  85. package/vendor/node-addon-api/doc/prebuild_tools.md +0 -16
  86. package/vendor/node-addon-api/doc/promises.md +0 -79
  87. package/vendor/node-addon-api/doc/property_descriptor.md +0 -286
  88. package/vendor/node-addon-api/doc/propertylvalue.md +0 -50
  89. package/vendor/node-addon-api/doc/range_error.md +0 -59
  90. package/vendor/node-addon-api/doc/reference.md +0 -113
  91. package/vendor/node-addon-api/doc/setup.md +0 -110
  92. package/vendor/node-addon-api/doc/string.md +0 -93
  93. package/vendor/node-addon-api/doc/symbol.md +0 -61
  94. package/vendor/node-addon-api/doc/threadsafe.md +0 -121
  95. package/vendor/node-addon-api/doc/threadsafe_function.md +0 -290
  96. package/vendor/node-addon-api/doc/type_error.md +0 -59
  97. package/vendor/node-addon-api/doc/typed_array.md +0 -78
  98. package/vendor/node-addon-api/doc/typed_array_of.md +0 -137
  99. package/vendor/node-addon-api/doc/typed_threadsafe_function.md +0 -306
  100. package/vendor/node-addon-api/doc/value.md +0 -340
  101. package/vendor/node-addon-api/doc/version_management.md +0 -43
  102. package/vendor/node-addon-api/package.json +0 -415
  103. package/vendor/node-addon-api/test/README.md +0 -91
  104. package/vendor/node-addon-api/test/addon.cc +0 -36
  105. package/vendor/node-addon-api/test/addon.js +0 -11
  106. package/vendor/node-addon-api/test/addon_build/index.js +0 -49
  107. package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +0 -17
  108. package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +0 -62
  109. package/vendor/node-addon-api/test/addon_build/tpl/index.js +0 -9
  110. package/vendor/node-addon-api/test/addon_build/tpl/package.json +0 -11
  111. package/vendor/node-addon-api/test/addon_data.cc +0 -99
  112. package/vendor/node-addon-api/test/addon_data.js +0 -46
  113. package/vendor/node-addon-api/test/array_buffer.cc +0 -243
  114. package/vendor/node-addon-api/test/array_buffer.js +0 -69
  115. package/vendor/node-addon-api/test/async_context.cc +0 -36
  116. package/vendor/node-addon-api/test/async_context.js +0 -122
  117. package/vendor/node-addon-api/test/async_progress_queue_worker.cc +0 -83
  118. package/vendor/node-addon-api/test/async_progress_queue_worker.js +0 -46
  119. package/vendor/node-addon-api/test/async_progress_worker.cc +0 -134
  120. package/vendor/node-addon-api/test/async_progress_worker.js +0 -61
  121. package/vendor/node-addon-api/test/async_worker.cc +0 -106
  122. package/vendor/node-addon-api/test/async_worker.js +0 -179
  123. package/vendor/node-addon-api/test/async_worker_nocallback.js +0 -13
  124. package/vendor/node-addon-api/test/async_worker_persistent.cc +0 -63
  125. package/vendor/node-addon-api/test/async_worker_persistent.js +0 -24
  126. package/vendor/node-addon-api/test/basic_types/array.cc +0 -40
  127. package/vendor/node-addon-api/test/basic_types/array.js +0 -35
  128. package/vendor/node-addon-api/test/basic_types/boolean.cc +0 -38
  129. package/vendor/node-addon-api/test/basic_types/boolean.js +0 -35
  130. package/vendor/node-addon-api/test/basic_types/number.cc +0 -99
  131. package/vendor/node-addon-api/test/basic_types/number.js +0 -114
  132. package/vendor/node-addon-api/test/basic_types/value.cc +0 -120
  133. package/vendor/node-addon-api/test/basic_types/value.js +0 -133
  134. package/vendor/node-addon-api/test/bigint.cc +0 -91
  135. package/vendor/node-addon-api/test/bigint.js +0 -53
  136. package/vendor/node-addon-api/test/binding-swallowexcept.cc +0 -12
  137. package/vendor/node-addon-api/test/binding.cc +0 -173
  138. package/vendor/node-addon-api/test/binding.gyp +0 -124
  139. package/vendor/node-addon-api/test/buffer.cc +0 -183
  140. package/vendor/node-addon-api/test/buffer.js +0 -69
  141. package/vendor/node-addon-api/test/callbackscope.cc +0 -22
  142. package/vendor/node-addon-api/test/callbackscope.js +0 -49
  143. package/vendor/node-addon-api/test/common/index.js +0 -114
  144. package/vendor/node-addon-api/test/common/test_helper.h +0 -71
  145. package/vendor/node-addon-api/test/dataview/dataview.cc +0 -48
  146. package/vendor/node-addon-api/test/dataview/dataview.js +0 -35
  147. package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +0 -115
  148. package/vendor/node-addon-api/test/dataview/dataview_read_write.js +0 -90
  149. package/vendor/node-addon-api/test/date.cc +0 -44
  150. package/vendor/node-addon-api/test/date.js +0 -18
  151. package/vendor/node-addon-api/test/env_cleanup.cc +0 -88
  152. package/vendor/node-addon-api/test/env_cleanup.js +0 -56
  153. package/vendor/node-addon-api/test/error.cc +0 -287
  154. package/vendor/node-addon-api/test/error.js +0 -81
  155. package/vendor/node-addon-api/test/error_handling_for_primitives.cc +0 -13
  156. package/vendor/node-addon-api/test/error_handling_for_primitives.js +0 -29
  157. package/vendor/node-addon-api/test/error_terminating_environment.js +0 -95
  158. package/vendor/node-addon-api/test/external.cc +0 -81
  159. package/vendor/node-addon-api/test/external.js +0 -88
  160. package/vendor/node-addon-api/test/function.cc +0 -324
  161. package/vendor/node-addon-api/test/function.js +0 -133
  162. package/vendor/node-addon-api/test/function_reference.cc +0 -202
  163. package/vendor/node-addon-api/test/function_reference.js +0 -157
  164. package/vendor/node-addon-api/test/globalObject/global_object.cc +0 -61
  165. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +0 -31
  166. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +0 -61
  167. package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +0 -40
  168. package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +0 -57
  169. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +0 -28
  170. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +0 -48
  171. package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +0 -31
  172. package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +0 -58
  173. package/vendor/node-addon-api/test/handlescope.cc +0 -60
  174. package/vendor/node-addon-api/test/handlescope.js +0 -14
  175. package/vendor/node-addon-api/test/index.js +0 -159
  176. package/vendor/node-addon-api/test/maybe/check.cc +0 -23
  177. package/vendor/node-addon-api/test/maybe/index.js +0 -38
  178. package/vendor/node-addon-api/test/memory_management.cc +0 -17
  179. package/vendor/node-addon-api/test/memory_management.js +0 -9
  180. package/vendor/node-addon-api/test/movable_callbacks.cc +0 -23
  181. package/vendor/node-addon-api/test/movable_callbacks.js +0 -21
  182. package/vendor/node-addon-api/test/name.cc +0 -108
  183. package/vendor/node-addon-api/test/name.js +0 -59
  184. package/vendor/node-addon-api/test/napi_child.js +0 -14
  185. package/vendor/node-addon-api/test/object/delete_property.cc +0 -38
  186. package/vendor/node-addon-api/test/object/delete_property.js +0 -41
  187. package/vendor/node-addon-api/test/object/finalizer.cc +0 -29
  188. package/vendor/node-addon-api/test/object/finalizer.js +0 -28
  189. package/vendor/node-addon-api/test/object/get_property.cc +0 -34
  190. package/vendor/node-addon-api/test/object/get_property.js +0 -40
  191. package/vendor/node-addon-api/test/object/has_own_property.cc +0 -34
  192. package/vendor/node-addon-api/test/object/has_own_property.js +0 -34
  193. package/vendor/node-addon-api/test/object/has_property.cc +0 -38
  194. package/vendor/node-addon-api/test/object/has_property.js +0 -37
  195. package/vendor/node-addon-api/test/object/object.cc +0 -350
  196. package/vendor/node-addon-api/test/object/object.js +0 -217
  197. package/vendor/node-addon-api/test/object/object_deprecated.cc +0 -66
  198. package/vendor/node-addon-api/test/object/object_deprecated.js +0 -47
  199. package/vendor/node-addon-api/test/object/object_freeze_seal.cc +0 -25
  200. package/vendor/node-addon-api/test/object/object_freeze_seal.js +0 -61
  201. package/vendor/node-addon-api/test/object/set_property.cc +0 -45
  202. package/vendor/node-addon-api/test/object/set_property.js +0 -30
  203. package/vendor/node-addon-api/test/object/subscript_operator.cc +0 -58
  204. package/vendor/node-addon-api/test/object/subscript_operator.js +0 -17
  205. package/vendor/node-addon-api/test/object_reference.cc +0 -219
  206. package/vendor/node-addon-api/test/object_reference.js +0 -259
  207. package/vendor/node-addon-api/test/objectwrap.cc +0 -268
  208. package/vendor/node-addon-api/test/objectwrap.js +0 -284
  209. package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +0 -26
  210. package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +0 -18
  211. package/vendor/node-addon-api/test/objectwrap_function.cc +0 -45
  212. package/vendor/node-addon-api/test/objectwrap_function.js +0 -22
  213. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +0 -30
  214. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +0 -13
  215. package/vendor/node-addon-api/test/objectwrap_removewrap.cc +0 -45
  216. package/vendor/node-addon-api/test/objectwrap_removewrap.js +0 -40
  217. package/vendor/node-addon-api/test/objectwrap_worker_thread.js +0 -19
  218. package/vendor/node-addon-api/test/promise.cc +0 -29
  219. package/vendor/node-addon-api/test/promise.js +0 -18
  220. package/vendor/node-addon-api/test/reference.cc +0 -24
  221. package/vendor/node-addon-api/test/reference.js +0 -14
  222. package/vendor/node-addon-api/test/run_script.cc +0 -56
  223. package/vendor/node-addon-api/test/run_script.js +0 -45
  224. package/vendor/node-addon-api/test/symbol.cc +0 -79
  225. package/vendor/node-addon-api/test/symbol.js +0 -73
  226. package/vendor/node-addon-api/test/testUtil.js +0 -54
  227. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +0 -195
  228. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +0 -188
  229. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +0 -63
  230. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +0 -12
  231. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +0 -115
  232. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +0 -14
  233. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +0 -26
  234. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +0 -7
  235. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +0 -225
  236. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +0 -59
  237. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +0 -42
  238. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +0 -53
  239. package/vendor/node-addon-api/test/thunking_manual.cc +0 -140
  240. package/vendor/node-addon-api/test/thunking_manual.js +0 -17
  241. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +0 -215
  242. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +0 -188
  243. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +0 -68
  244. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +0 -12
  245. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +0 -127
  246. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +0 -14
  247. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +0 -28
  248. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +0 -7
  249. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +0 -237
  250. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +0 -59
  251. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +0 -53
  252. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +0 -53
  253. package/vendor/node-addon-api/test/typedarray-bigint.js +0 -58
  254. package/vendor/node-addon-api/test/typedarray.cc +0 -216
  255. package/vendor/node-addon-api/test/typedarray.js +0 -69
  256. package/vendor/node-addon-api/test/version_management.cc +0 -27
  257. package/vendor/node-addon-api/test/version_management.js +0 -31
  258. package/vendor/node-addon-api/unit-test/README.md +0 -28
  259. package/vendor/node-addon-api/unit-test/binding-file-template.js +0 -39
  260. package/vendor/node-addon-api/unit-test/binding.gyp +0 -72
  261. package/vendor/node-addon-api/unit-test/exceptions.js +0 -32
  262. package/vendor/node-addon-api/unit-test/generate-binding-cc.js +0 -61
  263. package/vendor/node-addon-api/unit-test/injectTestParams.js +0 -101
  264. package/vendor/node-addon-api/unit-test/listOfTestModules.js +0 -88
  265. package/vendor/node-addon-api/unit-test/matchModules.js +0 -65
  266. package/vendor/node-addon-api/unit-test/setup.js +0 -13
  267. package/vendor/node-addon-api/unit-test/spawnTask.js +0 -26
  268. package/vendor/node-addon-api/unit-test/test.js +0 -30
@@ -1,78 +0,0 @@
1
- # TypedArray
2
-
3
- Class `Napi::TypedArray` inherits from class [`Napi::Object`][].
4
-
5
- The `Napi::TypedArray` class corresponds to the
6
- [JavaScript `TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
7
- class.
8
-
9
- ## Methods
10
-
11
- ### Constructor
12
-
13
- Initializes an empty instance of the `Napi::TypedArray` class.
14
-
15
- ```cpp
16
- Napi::TypedArray::TypedArray();
17
- ```
18
-
19
- ### Constructor
20
-
21
- Initializes a wrapper instance of an existing `Napi::TypedArray` instance.
22
-
23
- ```cpp
24
- Napi::TypedArray::TypedArray(napi_env env, napi_value value);
25
- ```
26
-
27
- - `[in] env`: The environment in which to create the `Napi::TypedArray` instance.
28
- - `[in] value`: The `Napi::TypedArray` reference to wrap.
29
-
30
- ### TypedArrayType
31
-
32
- ```cpp
33
- napi_typedarray_type Napi::TypedArray::TypedArrayType() const;
34
- ```
35
-
36
- Returns the type of this instance.
37
-
38
- ### ArrayBuffer
39
-
40
- ```cpp
41
- Napi::ArrayBuffer Napi::TypedArray::ArrayBuffer() const;
42
- ```
43
-
44
- Returns the backing array buffer.
45
-
46
- ### ElementSize
47
-
48
- ```cpp
49
- uint8_t Napi::TypedArray::ElementSize() const;
50
- ```
51
-
52
- Returns the size of one element, in bytes.
53
-
54
- ### ElementLength
55
-
56
- ```cpp
57
- size_t Napi::TypedArray::ElementLength() const;
58
- ```
59
-
60
- Returns the number of elements.
61
-
62
- ### ByteOffset
63
-
64
- ```cpp
65
- size_t Napi::TypedArray::ByteOffset() const;
66
- ```
67
-
68
- Returns the offset into the `Napi::ArrayBuffer` where the array starts, in bytes.
69
-
70
- ### ByteLength
71
-
72
- ```cpp
73
- size_t Napi::TypedArray::ByteLength() const;
74
- ```
75
-
76
- Returns the length of the array, in bytes.
77
-
78
- [`Napi::Object`]: ./object.md
@@ -1,137 +0,0 @@
1
- # TypedArrayOf
2
-
3
- Class `Napi::TypedArrayOf<T>` inherits from class [`Napi::TypedArray`][].
4
-
5
- The `Napi::TypedArrayOf` class corresponds to the various
6
- [JavaScript `TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
7
- classes.
8
-
9
- ## Typedefs
10
-
11
- The common JavaScript `TypedArray` types are pre-defined for each of use:
12
-
13
- ```cpp
14
- using Int8Array = Napi::TypedArrayOf<int8_t>;
15
- using Uint8Array = Napi::TypedArrayOf<uint8_t>;
16
- using Int16Array = Napi::TypedArrayOf<int16_t>;
17
- using Uint16Array = Napi::TypedArrayOf<uint16_t>;
18
- using Int32Array = Napi::TypedArrayOf<int32_t>;
19
- using Uint32Array = Napi::TypedArrayOf<uint32_t>;
20
- using Float32Array = Napi::TypedArrayOf<float>;
21
- using Float64Array = Napi::TypedArrayOf<double>;
22
- ```
23
-
24
- The one exception is the `Uint8ClampedArray` which requires explicit
25
- initialization:
26
-
27
- ```cpp
28
- Uint8Array::New(env, length, napi_uint8_clamped_array)
29
- ```
30
-
31
- Note that while it's possible to create a "clamped" array the _clamping_
32
- behavior is only applied in JavaScript.
33
-
34
- ## Methods
35
-
36
- ### New
37
-
38
- Allocates a new `Napi::TypedArray` instance with a given length. The underlying
39
- `Napi::ArrayBuffer` is allocated automatically to the desired number of elements.
40
-
41
- The array type parameter can normally be omitted (because it is inferred from
42
- the template parameter T), except when creating a "clamped" array.
43
-
44
- ```cpp
45
- static Napi::TypedArrayOf Napi::TypedArrayOf::New(napi_env env,
46
- size_t elementLength,
47
- napi_typedarray_type type);
48
- ```
49
-
50
- - `[in] env`: The environment in which to create the `Napi::TypedArrayOf` instance.
51
- - `[in] elementLength`: The length to be allocated, in elements.
52
- - `[in] type`: The type of array to allocate (optional).
53
-
54
- Returns a new `Napi::TypedArrayOf` instance.
55
-
56
- ### New
57
-
58
- Wraps the provided `Napi::ArrayBuffer` into a new `Napi::TypedArray` instance.
59
-
60
- The array `type` parameter can normally be omitted (because it is inferred from
61
- the template parameter `T`), except when creating a "clamped" array.
62
-
63
- ```cpp
64
- static Napi::TypedArrayOf Napi::TypedArrayOf::New(napi_env env,
65
- size_t elementLength,
66
- Napi::ArrayBuffer arrayBuffer,
67
- size_t bufferOffset,
68
- napi_typedarray_type type);
69
- ```
70
-
71
- - `[in] env`: The environment in which to create the `Napi::TypedArrayOf` instance.
72
- - `[in] elementLength`: The length to array, in elements.
73
- - `[in] arrayBuffer`: The backing `Napi::ArrayBuffer` instance.
74
- - `[in] bufferOffset`: The offset into the `Napi::ArrayBuffer` where the array starts,
75
- in bytes.
76
- - `[in] type`: The type of array to allocate (optional).
77
-
78
- Returns a new `Napi::TypedArrayOf` instance.
79
-
80
- ### Constructor
81
-
82
- Initializes an empty instance of the `Napi::TypedArrayOf` class.
83
-
84
- ```cpp
85
- Napi::TypedArrayOf::TypedArrayOf();
86
- ```
87
-
88
- ### Constructor
89
-
90
- Initializes a wrapper instance of an existing `Napi::TypedArrayOf` object.
91
-
92
- ```cpp
93
- Napi::TypedArrayOf::TypedArrayOf(napi_env env, napi_value value);
94
- ```
95
-
96
- - `[in] env`: The environment in which to create the `Napi::TypedArrayOf` object.
97
- - `[in] value`: The `Napi::TypedArrayOf` reference to wrap.
98
-
99
- ### operator []
100
-
101
- ```cpp
102
- T& Napi::TypedArrayOf::operator [](size_t index);
103
- ```
104
-
105
- - `[in] index: The element index into the array.
106
-
107
- Returns the element found at the given index.
108
-
109
- ### operator []
110
-
111
- ```cpp
112
- const T& Napi::TypedArrayOf::operator [](size_t index) const;
113
- ```
114
-
115
- - `[in] index: The element index into the array.
116
-
117
- Returns the element found at the given index.
118
-
119
- ### Data
120
-
121
- ```cpp
122
- T* Napi::TypedArrayOf::Data() const;
123
- ```
124
-
125
- Returns a pointer into the backing `Napi::ArrayBuffer` which is offset to point to the
126
- start of the array.
127
-
128
- ### Data
129
-
130
- ```cpp
131
- const T* Napi::TypedArrayOf::Data() const
132
- ```
133
-
134
- Returns a pointer into the backing `Napi::ArrayBuffer` which is offset to point to the
135
- start of the array.
136
-
137
- [`Napi::TypedArray`]: ./typed_array.md
@@ -1,306 +0,0 @@
1
- # TypedThreadSafeFunction
2
-
3
- The `Napi::TypedThreadSafeFunction` type provides APIs for threads to
4
- communicate with the addon's main thread to invoke JavaScript functions on their
5
- behalf. The type is a three-argument templated class, each argument representing
6
- the type of:
7
- - `ContextType = std::nullptr_t`: The thread-safe function's context. By
8
- default, a TSFN has no context.
9
- - `DataType = void*`: The data to use in the native callback. By default, a TSFN
10
- can accept any data type.
11
- - `Callback = void(*)(Napi::Env, Napi::Function jsCallback, ContextType*,
12
- DataType*)`: The callback to run for each item added to the queue. If no
13
- `Callback` is given, the API will call the function `jsCallback` with no
14
- arguments.
15
-
16
- Documentation can be found for an [overview of the API](threadsafe.md), as well
17
- as [differences between the two thread-safe function
18
- APIs](threadsafe.md#implementation-differences).
19
-
20
- ## Methods
21
-
22
- ### Constructor
23
-
24
- Creates a new empty instance of `Napi::TypedThreadSafeFunction`.
25
-
26
- ```cpp
27
- Napi::Function::TypedThreadSafeFunction<ContextType, DataType, Callback>::TypedThreadSafeFunction();
28
- ```
29
-
30
- ### Constructor
31
-
32
- Creates a new instance of the `Napi::TypedThreadSafeFunction` object.
33
-
34
- ```cpp
35
- Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::TypedThreadSafeFunction(napi_threadsafe_function tsfn);
36
- ```
37
-
38
- - `tsfn`: The `napi_threadsafe_function` which is a handle for an existing
39
- thread-safe function.
40
-
41
- Returns a non-empty `Napi::TypedThreadSafeFunction` instance. To ensure the API
42
- statically handles the correct return type for `GetContext()` and
43
- `[Non]BlockingCall()`, pass the proper template arguments to
44
- `Napi::TypedThreadSafeFunction`.
45
-
46
- ### New
47
-
48
- Creates a new instance of the `Napi::TypedThreadSafeFunction` object. The `New`
49
- function has several overloads for the various optional parameters: skip the
50
- optional parameter for that specific overload.
51
-
52
- ```cpp
53
- New(napi_env env,
54
- CallbackType callback,
55
- const Object& resource,
56
- ResourceString resourceName,
57
- size_t maxQueueSize,
58
- size_t initialThreadCount,
59
- ContextType* context,
60
- Finalizer finalizeCallback,
61
- FinalizerDataType* data = nullptr);
62
- ```
63
-
64
- - `env`: The `napi_env` environment in which to construct the
65
- `Napi::ThreadSafeFunction` object.
66
- - `[optional] callback`: The `Function` to call from another thread.
67
- - `[optional] resource`: An object associated with the async work that will be
68
- passed to possible async_hooks init hooks.
69
- - `resourceName`: A JavaScript string to provide an identifier for the kind of
70
- resource that is being provided for diagnostic information exposed by the
71
- async_hooks API.
72
- - `maxQueueSize`: Maximum size of the queue. `0` for no limit.
73
- - `initialThreadCount`: The initial number of threads, including the main
74
- thread, which will be making use of this function.
75
- - `[optional] context`: Data to attach to the resulting `ThreadSafeFunction`. It
76
- can be retrieved via `GetContext()`.
77
- - `[optional] finalizeCallback`: Function to call when the
78
- `TypedThreadSafeFunction` is being destroyed. This callback will be invoked
79
- on the main thread when the thread-safe function is about to be destroyed. It
80
- receives the context and the finalize data given during construction (if
81
- given), and provides an opportunity for cleaning up after the threads e.g. by
82
- calling `uv_thread_join()`. It is important that, aside from the main loop
83
- thread, there be no threads left using the thread-safe function after the
84
- finalize callback completes. Must implement `void operator()(Env env,
85
- FinalizerDataType* data, ContextType* hint)`.
86
- - `[optional] data`: Data to be passed to `finalizeCallback`.
87
-
88
- Returns a non-empty `Napi::TypedThreadSafeFunction` instance.
89
-
90
- Depending on the targeted `NAPI_VERSION`, the API has different implementations
91
- for `CallbackType callback`.
92
-
93
- When targeting version 4, `callback` may be:
94
- - of type `const Function&`
95
- - not provided as a parameter, in which case the API creates a new no-op
96
- `Function`
97
-
98
- When targeting version 5+, `callback` may be:
99
- - of type `const Function&`
100
- - of type `std::nullptr_t`
101
- - not provided as a parameter, in which case the API passes `std::nullptr`
102
-
103
- ### Acquire
104
-
105
- Adds a thread to this thread-safe function object, indicating that a new thread
106
- will start making use of the thread-safe function.
107
-
108
- ```cpp
109
- napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Acquire()
110
- ```
111
-
112
- Returns one of:
113
- - `napi_ok`: The thread has successfully acquired the thread-safe function for
114
- its use.
115
- - `napi_closing`: The thread-safe function has been marked as closing via a
116
- previous call to `Abort()`.
117
-
118
- ### Release
119
-
120
- Indicates that an existing thread will stop making use of the thread-safe
121
- function. A thread should call this API when it stops making use of this
122
- thread-safe function. Using any thread-safe APIs after having called this API
123
- has undefined results in the current thread, as the thread-safe function may
124
- have been destroyed.
125
-
126
- ```cpp
127
- napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Release() const
128
- ```
129
-
130
- Returns one of:
131
- - `napi_ok`: The thread-safe function has been successfully released.
132
- - `napi_invalid_arg`: The thread-safe function's thread-count is zero.
133
- - `napi_generic_failure`: A generic error occurred when attempting to release the
134
- thread-safe function.
135
-
136
- ### Abort
137
-
138
- "Aborts" the thread-safe function. This will cause all subsequent APIs
139
- associated with the thread-safe function except `Release()` to return
140
- `napi_closing` even before its reference count reaches zero. In particular,
141
- `BlockingCall` and `NonBlockingCall()` will return `napi_closing`, thus
142
- informing the threads that it is no longer possible to make asynchronous calls
143
- to the thread-safe function. This can be used as a criterion for terminating the
144
- thread. Upon receiving a return value of `napi_closing` from a thread-safe
145
- function call a thread must make no further use of the thread-safe function
146
- because it is no longer guaranteed to be allocated.
147
-
148
- ```cpp
149
- napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::Abort() const
150
- ```
151
-
152
- Returns one of:
153
- - `napi_ok`: The thread-safe function has been successfully aborted.
154
- - `napi_invalid_arg`: The thread-safe function's thread-count is zero.
155
- - `napi_generic_failure`: A generic error occurred when attempting to abort the
156
- thread-safe function.
157
-
158
- ### BlockingCall / NonBlockingCall
159
-
160
- Calls the Javascript function in either a blocking or non-blocking fashion.
161
- - `BlockingCall()`: the API blocks until space becomes available in the queue.
162
- Will never block if the thread-safe function was created with a maximum queue
163
- size of `0`.
164
- - `NonBlockingCall()`: will return `napi_queue_full` if the queue was full,
165
- preventing data from being successfully added to the queue.
166
-
167
- ```cpp
168
- napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::BlockingCall(DataType* data = nullptr) const
169
-
170
- napi_status Napi::TypedThreadSafeFunction<ContextType, DataType, Callback>::NonBlockingCall(DataType* data = nullptr) const
171
- ```
172
-
173
- - `[optional] data`: Data to pass to the callback which was passed to
174
- `TypedThreadSafeFunction::New()`.
175
-
176
- Returns one of:
177
- - `napi_ok`: `data` was successfully added to the queue.
178
- - `napi_queue_full`: The queue was full when trying to call in a non-blocking
179
- method.
180
- - `napi_closing`: The thread-safe function is aborted and no further calls can
181
- be made.
182
- - `napi_invalid_arg`: The thread-safe function is closed.
183
- - `napi_generic_failure`: A generic error occurred when attempting to add to the
184
- queue.
185
-
186
-
187
- ## Example
188
-
189
- ```cpp
190
- #include <chrono>
191
- #include <napi.h>
192
- #include <thread>
193
-
194
- using namespace Napi;
195
-
196
- using Context = Reference<Value>;
197
- using DataType = int;
198
- void CallJs(Napi::Env env, Function callback, Context *context, DataType *data);
199
- using TSFN = TypedThreadSafeFunction<Context, DataType, CallJs>;
200
- using FinalizerDataType = void;
201
-
202
- std::thread nativeThread;
203
- TSFN tsfn;
204
-
205
- Value Start(const CallbackInfo &info) {
206
- Napi::Env env = info.Env();
207
-
208
- if (info.Length() < 2) {
209
- throw TypeError::New(env, "Expected two arguments");
210
- } else if (!info[0].IsFunction()) {
211
- throw TypeError::New(env, "Expected first arg to be function");
212
- } else if (!info[1].IsNumber()) {
213
- throw TypeError::New(env, "Expected second arg to be number");
214
- }
215
-
216
- int count = info[1].As<Number>().Int32Value();
217
-
218
- // Create a new context set to the receiver (ie, `this`) of the function call
219
- Context *context = new Reference<Value>(Persistent(info.This()));
220
-
221
- // Create a ThreadSafeFunction
222
- tsfn = TSFN::New(
223
- env,
224
- info[0].As<Function>(), // JavaScript function called asynchronously
225
- "Resource Name", // Name
226
- 0, // Unlimited queue
227
- 1, // Only one thread will use this initially
228
- context,
229
- [](Napi::Env, FinalizerDataType *,
230
- Context *ctx) { // Finalizer used to clean threads up
231
- nativeThread.join();
232
- delete ctx;
233
- });
234
-
235
- // Create a native thread
236
- nativeThread = std::thread([count] {
237
- for (int i = 0; i < count; i++) {
238
- // Create new data
239
- int *value = new int(clock());
240
-
241
- // Perform a blocking call
242
- napi_status status = tsfn.BlockingCall(value);
243
- if (status != napi_ok) {
244
- // Handle error
245
- break;
246
- }
247
-
248
- std::this_thread::sleep_for(std::chrono::seconds(1));
249
- }
250
-
251
- // Release the thread-safe function
252
- tsfn.Release();
253
- });
254
-
255
- return Boolean::New(env, true);
256
- }
257
-
258
- // Transform native data into JS data, passing it to the provided
259
- // `callback` -- the TSFN's JavaScript function.
260
- void CallJs(Napi::Env env, Function callback, Context *context,
261
- DataType *data) {
262
- // Is the JavaScript environment still available to call into, eg. the TSFN is
263
- // not aborted
264
- if (env != nullptr) {
265
- // On Node-API 5+, the `callback` parameter is optional; however, this example
266
- // does ensure a callback is provided.
267
- if (callback != nullptr) {
268
- callback.Call(context->Value(), {Number::New(env, *data)});
269
- }
270
- }
271
- if (data != nullptr) {
272
- // We're finished with the data.
273
- delete data;
274
- }
275
- }
276
-
277
- Napi::Object Init(Napi::Env env, Object exports) {
278
- exports.Set("start", Function::New(env, Start));
279
- return exports;
280
- }
281
-
282
- NODE_API_MODULE(clock, Init)
283
- ```
284
-
285
- The above code can be used from JavaScript as follows:
286
-
287
- ```js
288
- const { start } = require('bindings')('clock');
289
-
290
- start.call(new Date(), function (clock) {
291
- const context = this;
292
- console.log(context, clock);
293
- }, 5);
294
- ```
295
-
296
- When executed, the output will show the value of `clock()` five times at one
297
- second intervals, prefixed with the TSFN's context -- `start`'s receiver (ie,
298
- `new Date()`):
299
-
300
- ```
301
- 2020-08-18T21:04:25.116Z 49824
302
- 2020-08-18T21:04:25.116Z 62493
303
- 2020-08-18T21:04:25.116Z 62919
304
- 2020-08-18T21:04:25.116Z 63228
305
- 2020-08-18T21:04:25.116Z 63531
306
- ```