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,81 +0,0 @@
1
- #include "napi.h"
2
-
3
- using namespace Napi;
4
-
5
- namespace {
6
-
7
- int testData = 1;
8
- int finalizeCount = 0;
9
-
10
- Value CreateExternal(const CallbackInfo& info) {
11
- finalizeCount = 0;
12
- return External<int>::New(info.Env(), &testData);
13
- }
14
-
15
- Value CreateExternalWithFinalize(const CallbackInfo& info) {
16
- finalizeCount = 0;
17
- return External<int>::New(info.Env(), new int(1),
18
- [](Env /*env*/, int* data) {
19
- delete data;
20
- finalizeCount++;
21
- });
22
- }
23
-
24
- Value CreateExternalWithFinalizeHint(const CallbackInfo& info) {
25
- finalizeCount = 0;
26
- char* hint = nullptr;
27
- return External<int>::New(info.Env(), new int(1),
28
- [](Env /*env*/, int* data, char* /*hint*/) {
29
- delete data;
30
- finalizeCount++;
31
- },
32
- hint);
33
- }
34
-
35
- void CheckExternal(const CallbackInfo& info) {
36
- Value arg = info[0];
37
- if (arg.Type() != napi_external) {
38
- Error::New(info.Env(), "An external argument was expected.").ThrowAsJavaScriptException();
39
- return;
40
- }
41
-
42
- External<int> external = arg.As<External<int>>();
43
- int* externalData = external.Data();
44
- if (externalData == nullptr || *externalData != 1) {
45
- Error::New(info.Env(), "An external value of 1 was expected.").ThrowAsJavaScriptException();
46
- return;
47
- }
48
- }
49
-
50
- Value GetFinalizeCount(const CallbackInfo& info) {
51
- return Number::New(info.Env(), finalizeCount);
52
- }
53
-
54
- Value CreateExternalWithFinalizeException(const CallbackInfo& info) {
55
- return External<int>::New(info.Env(), new int(1),
56
- [](Env env, int* data) {
57
- Error error = Error::New(env, "Finalizer exception");
58
- delete data;
59
- #ifdef NAPI_CPP_EXCEPTIONS
60
- throw error;
61
- #else
62
- error.ThrowAsJavaScriptException();
63
- #endif
64
- });
65
- }
66
-
67
- } // end anonymous namespace
68
-
69
- Object InitExternal(Env env) {
70
- Object exports = Object::New(env);
71
-
72
- exports["createExternal"] = Function::New(env, CreateExternal);
73
- exports["createExternalWithFinalize"] = Function::New(env, CreateExternalWithFinalize);
74
- exports["createExternalWithFinalizeException"] =
75
- Function::New(env, CreateExternalWithFinalizeException);
76
- exports["createExternalWithFinalizeHint"] = Function::New(env, CreateExternalWithFinalizeHint);
77
- exports["checkExternal"] = Function::New(env, CheckExternal);
78
- exports["getFinalizeCount"] = Function::New(env, GetFinalizeCount);
79
-
80
- return exports;
81
- }
@@ -1,88 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { spawnSync } = require('child_process');
5
- const testUtil = require('./testUtil');
6
-
7
- if (process.argv.length === 3) {
8
- let interval;
9
-
10
- // Running as the child process, hook up an `uncaughtException` handler to
11
- // examine the error thrown by the finalizer.
12
- process.on('uncaughtException', (error) => {
13
- // TODO (gabrielschulhof): Use assert.matches() when we drop support for
14
- // Node.js v10.x.
15
- assert(!!error.message.match(/Finalizer exception/));
16
- if (interval) {
17
- clearInterval(interval);
18
- }
19
- process.exit(0);
20
- });
21
-
22
- // Create an external whose finalizer throws.
23
- (() =>
24
- require(process.argv[2]).external.createExternalWithFinalizeException())();
25
-
26
- // gc until the external's finalizer throws or until we give up. Since the
27
- // exception is thrown from a native `SetImmediate()` we cannot catch it
28
- // anywhere except in the process' `uncaughtException` handler.
29
- let maxGCTries = 10;
30
- (function gcInterval() {
31
- global.gc();
32
- if (!interval) {
33
- interval = setInterval(gcInterval, 100);
34
- } else if (--maxGCTries === 0) {
35
- throw new Error('Timed out waiting for the gc to throw');
36
- process.exit(1);
37
- }
38
- })();
39
-
40
- return;
41
- }
42
-
43
- module.exports = require('./common').runTestWithBindingPath(test);
44
-
45
- function test(bindingPath) {
46
- const binding = require(bindingPath);
47
-
48
- const child = spawnSync(process.execPath, [
49
- '--expose-gc', __filename, bindingPath
50
- ], { stdio: 'inherit' });
51
- assert.strictEqual(child.status, 0);
52
- assert.strictEqual(child.signal, null);
53
-
54
- return testUtil.runGCTests([
55
- 'External without finalizer',
56
- () => {
57
- const test = binding.external.createExternal();
58
- assert.strictEqual(typeof test, 'object');
59
- binding.external.checkExternal(test);
60
- assert.strictEqual(0, binding.external.getFinalizeCount());
61
- },
62
- () => {
63
- assert.strictEqual(0, binding.external.getFinalizeCount());
64
- },
65
-
66
- 'External with finalizer',
67
- () => {
68
- const test = binding.external.createExternalWithFinalize();
69
- assert.strictEqual(typeof test, 'object');
70
- binding.external.checkExternal(test);
71
- assert.strictEqual(0, binding.external.getFinalizeCount());
72
- },
73
- () => {
74
- assert.strictEqual(1, binding.external.getFinalizeCount());
75
- },
76
-
77
- 'External with finalizer hint',
78
- () => {
79
- const test = binding.external.createExternalWithFinalizeHint();
80
- assert.strictEqual(typeof test, 'object');
81
- binding.external.checkExternal(test);
82
- assert.strictEqual(0, binding.external.getFinalizeCount());
83
- },
84
- () => {
85
- assert.strictEqual(1, binding.external.getFinalizeCount());
86
- },
87
- ]);
88
- }
@@ -1,324 +0,0 @@
1
- #include <memory>
2
- #include "napi.h"
3
- #include "test_helper.h"
4
-
5
- using namespace Napi;
6
-
7
- namespace {
8
-
9
- int testData = 1;
10
-
11
- Boolean EmptyConstructor(const CallbackInfo& info) {
12
- auto env = info.Env();
13
- bool isEmpty = info[0].As<Boolean>();
14
- Function function = isEmpty ? Function() : Function(env, Object::New(env));
15
- return Boolean::New(env, function.IsEmpty());
16
- }
17
-
18
- void VoidCallback(const CallbackInfo& info) {
19
- auto env = info.Env();
20
- Object obj = info[0].As<Object>();
21
-
22
- obj["foo"] = String::New(env, "bar");
23
- }
24
-
25
- Value ValueCallback(const CallbackInfo& info) {
26
- auto env = info.Env();
27
- Object obj = Object::New(env);
28
-
29
- obj["foo"] = String::New(env, "bar");
30
-
31
- return obj;
32
- }
33
-
34
- void VoidCallbackWithData(const CallbackInfo& info) {
35
- auto env = info.Env();
36
- Object obj = info[0].As<Object>();
37
-
38
- obj["foo"] = String::New(env, "bar");
39
-
40
- int* data = static_cast<int*>(info.Data());
41
- obj["data"] = Number::New(env, *data);
42
- }
43
-
44
- Value ValueCallbackWithData(const CallbackInfo& info) {
45
- auto env = info.Env();
46
- Object obj = Object::New(env);
47
-
48
- obj["foo"] = String::New(env, "bar");
49
-
50
- int* data = static_cast<int*>(info.Data());
51
- obj["data"] = Number::New(env, *data);
52
-
53
- return obj;
54
- }
55
-
56
- Value CallWithArgs(const CallbackInfo& info) {
57
- Function func = info[0].As<Function>();
58
- return MaybeUnwrap(
59
- func.Call(std::initializer_list<napi_value>{info[1], info[2], info[3]}));
60
- }
61
-
62
- Value CallWithVector(const CallbackInfo& info) {
63
- Function func = info[0].As<Function>();
64
- std::vector<napi_value> args;
65
- args.reserve(3);
66
- args.push_back(info[1]);
67
- args.push_back(info[2]);
68
- args.push_back(info[3]);
69
- return MaybeUnwrap(func.Call(args));
70
- }
71
-
72
- Value CallWithVectorUsingCppWrapper(const CallbackInfo& info) {
73
- Function func = info[0].As<Function>();
74
- std::vector<Value> args;
75
- args.reserve(3);
76
- args.push_back(info[1]);
77
- args.push_back(info[2]);
78
- args.push_back(info[3]);
79
- return MaybeUnwrap(func.Call(args));
80
- }
81
-
82
- Value CallWithCStyleArray(const CallbackInfo& info) {
83
- Function func = info[0].As<Function>();
84
- std::vector<napi_value> args;
85
- args.reserve(3);
86
- args.push_back(info[1]);
87
- args.push_back(info[2]);
88
- args.push_back(info[3]);
89
- return MaybeUnwrap(func.Call(args.size(), args.data()));
90
- }
91
-
92
- Value CallWithReceiverAndCStyleArray(const CallbackInfo& info) {
93
- Function func = info[0].As<Function>();
94
- Value receiver = info[1];
95
- std::vector<napi_value> args;
96
- args.reserve(3);
97
- args.push_back(info[2]);
98
- args.push_back(info[3]);
99
- args.push_back(info[4]);
100
- return MaybeUnwrap(func.Call(receiver, args.size(), args.data()));
101
- }
102
-
103
- Value CallWithReceiverAndArgs(const CallbackInfo& info) {
104
- Function func = info[0].As<Function>();
105
- Value receiver = info[1];
106
- return MaybeUnwrap(func.Call(
107
- receiver, std::initializer_list<napi_value>{info[2], info[3], info[4]}));
108
- }
109
-
110
- Value CallWithReceiverAndVector(const CallbackInfo& info) {
111
- Function func = info[0].As<Function>();
112
- Value receiver = info[1];
113
- std::vector<napi_value> args;
114
- args.reserve(3);
115
- args.push_back(info[2]);
116
- args.push_back(info[3]);
117
- args.push_back(info[4]);
118
- return MaybeUnwrap(func.Call(receiver, args));
119
- }
120
-
121
- Value CallWithReceiverAndVectorUsingCppWrapper(const CallbackInfo& info) {
122
- Function func = info[0].As<Function>();
123
- Value receiver = info[1];
124
- std::vector<Value> args;
125
- args.reserve(3);
126
- args.push_back(info[2]);
127
- args.push_back(info[3]);
128
- args.push_back(info[4]);
129
- return MaybeUnwrap(func.Call(receiver, args));
130
- }
131
-
132
- Value CallWithInvalidReceiver(const CallbackInfo& info) {
133
- Function func = info[0].As<Function>();
134
- return MaybeUnwrapOr(func.Call(Value(), std::initializer_list<napi_value>{}),
135
- Value());
136
- }
137
-
138
- Value CallConstructorWithArgs(const CallbackInfo& info) {
139
- Function func = info[0].As<Function>();
140
- return MaybeUnwrap(
141
- func.New(std::initializer_list<napi_value>{info[1], info[2], info[3]}));
142
- }
143
-
144
- Value CallConstructorWithVector(const CallbackInfo& info) {
145
- Function func = info[0].As<Function>();
146
- std::vector<napi_value> args;
147
- args.reserve(3);
148
- args.push_back(info[1]);
149
- args.push_back(info[2]);
150
- args.push_back(info[3]);
151
- return MaybeUnwrap(func.New(args));
152
- }
153
-
154
- Value CallConstructorWithCStyleArray(const CallbackInfo& info) {
155
- Function func = info[0].As<Function>();
156
- std::vector<napi_value> args;
157
- args.reserve(3);
158
- args.push_back(info[1]);
159
- args.push_back(info[2]);
160
- args.push_back(info[3]);
161
- return MaybeUnwrap(func.New(args.size(), args.data()));
162
- }
163
-
164
- void IsConstructCall(const CallbackInfo& info) {
165
- Function callback = info[0].As<Function>();
166
- bool isConstructCall = info.IsConstructCall();
167
- callback({Napi::Boolean::New(info.Env(), isConstructCall)});
168
- }
169
-
170
- void MakeCallbackWithArgs(const CallbackInfo& info) {
171
- Env env = info.Env();
172
- Function callback = info[0].As<Function>();
173
- Object resource = info[1].As<Object>();
174
-
175
- AsyncContext context(env, "function_test_context", resource);
176
-
177
- callback.MakeCallback(
178
- resource,
179
- std::initializer_list<napi_value>{info[2], info[3], info[4]},
180
- context);
181
- }
182
-
183
- void MakeCallbackWithVector(const CallbackInfo& info) {
184
- Env env = info.Env();
185
- Function callback = info[0].As<Function>();
186
- Object resource = info[1].As<Object>();
187
-
188
- AsyncContext context(env, "function_test_context", resource);
189
-
190
- std::vector<napi_value> args;
191
- args.reserve(3);
192
- args.push_back(info[2]);
193
- args.push_back(info[3]);
194
- args.push_back(info[4]);
195
- callback.MakeCallback(resource, args, context);
196
- }
197
-
198
- void MakeCallbackWithCStyleArray(const CallbackInfo& info) {
199
- Env env = info.Env();
200
- Function callback = info[0].As<Function>();
201
- Object resource = info[1].As<Object>();
202
-
203
- AsyncContext context(env, "function_test_context", resource);
204
-
205
- std::vector<napi_value> args;
206
- args.reserve(3);
207
- args.push_back(info[2]);
208
- args.push_back(info[3]);
209
- args.push_back(info[4]);
210
- callback.MakeCallback(resource, args.size(), args.data(), context);
211
- }
212
-
213
- void MakeCallbackWithInvalidReceiver(const CallbackInfo& info) {
214
- Function callback = info[0].As<Function>();
215
- callback.MakeCallback(Value(), std::initializer_list<napi_value>{});
216
- }
217
-
218
- Value CallWithFunctionOperator(const CallbackInfo& info) {
219
- Function func = info[0].As<Function>();
220
- return MaybeUnwrap(func({info[1], info[2], info[3]}));
221
- }
222
-
223
- } // end anonymous namespace
224
-
225
- Object InitFunction(Env env) {
226
- Object result = Object::New(env);
227
- Object exports = Object::New(env);
228
- exports["emptyConstructor"] = Function::New(env, EmptyConstructor);
229
- exports["voidCallback"] = Function::New(env, VoidCallback, "voidCallback");
230
- exports["valueCallback"] = Function::New(env, ValueCallback, std::string("valueCallback"));
231
- exports["voidCallbackWithData"] =
232
- Function::New(env, VoidCallbackWithData, nullptr, &testData);
233
- exports["valueCallbackWithData"] =
234
- Function::New(env, ValueCallbackWithData, nullptr, &testData);
235
- exports["callWithArgs"] = Function::New(env, CallWithArgs);
236
- exports["callWithVector"] = Function::New(env, CallWithVector);
237
- exports["callWithVectorUsingCppWrapper"] =
238
- Function::New(env, CallWithVectorUsingCppWrapper);
239
- exports["callWithCStyleArray"] = Function::New(env, CallWithCStyleArray);
240
- exports["callWithReceiverAndCStyleArray"] =
241
- Function::New(env, CallWithReceiverAndCStyleArray);
242
- exports["callWithReceiverAndArgs"] = Function::New(env, CallWithReceiverAndArgs);
243
- exports["callWithReceiverAndVector"] = Function::New(env, CallWithReceiverAndVector);
244
- exports["callWithReceiverAndVectorUsingCppWrapper"] =
245
- Function::New(env, CallWithReceiverAndVectorUsingCppWrapper);
246
- exports["callWithInvalidReceiver"] = Function::New(env, CallWithInvalidReceiver);
247
- exports["callConstructorWithArgs"] = Function::New(env, CallConstructorWithArgs);
248
- exports["callConstructorWithVector"] = Function::New(env, CallConstructorWithVector);
249
- exports["callConstructorWithCStyleArray"] =
250
- Function::New(env, CallConstructorWithCStyleArray);
251
- exports["isConstructCall"] = Function::New(env, IsConstructCall);
252
- exports["makeCallbackWithArgs"] = Function::New(env, MakeCallbackWithArgs);
253
- exports["makeCallbackWithVector"] =
254
- Function::New(env, MakeCallbackWithVector);
255
- exports["makeCallbackWithCStyleArray"] =
256
- Function::New(env, MakeCallbackWithCStyleArray);
257
- exports["makeCallbackWithInvalidReceiver"] =
258
- Function::New(env, MakeCallbackWithInvalidReceiver);
259
- exports["callWithFunctionOperator"] =
260
- Function::New(env, CallWithFunctionOperator);
261
- result["plain"] = exports;
262
-
263
- exports = Object::New(env);
264
- exports["emptyConstructor"] = Function::New(env, EmptyConstructor);
265
- exports["voidCallback"] = Function::New<VoidCallback>(env, "voidCallback");
266
- exports["valueCallback"] =
267
- Function::New<ValueCallback>(env, std::string("valueCallback"));
268
- exports["voidCallbackWithData"] =
269
- Function::New<VoidCallbackWithData>(env, nullptr, &testData);
270
- exports["valueCallbackWithData"] =
271
- Function::New<ValueCallbackWithData>(env, nullptr, &testData);
272
- exports["callWithArgs"] = Function::New<CallWithArgs>(env);
273
- exports["callWithVector"] = Function::New<CallWithVector>(env);
274
- exports["callWithVectorUsingCppWrapper"] =
275
- Function::New<CallWithVectorUsingCppWrapper>(env);
276
- exports["callWithCStyleArray"] = Function::New<CallWithCStyleArray>(env);
277
- exports["callWithReceiverAndCStyleArray"] =
278
- Function::New<CallWithReceiverAndCStyleArray>(env);
279
- exports["callWithReceiverAndArgs"] =
280
- Function::New<CallWithReceiverAndArgs>(env);
281
- exports["callWithReceiverAndVector"] =
282
- Function::New<CallWithReceiverAndVector>(env);
283
- exports["callWithReceiverAndVectorUsingCppWrapper"] =
284
- Function::New<CallWithReceiverAndVectorUsingCppWrapper>(env);
285
- exports["callWithInvalidReceiver"] =
286
- Function::New<CallWithInvalidReceiver>(env);
287
- exports["callConstructorWithArgs"] =
288
- Function::New<CallConstructorWithArgs>(env);
289
- exports["callConstructorWithVector"] =
290
- Function::New<CallConstructorWithVector>(env);
291
- exports["callConstructorWithCStyleArray"] =
292
- Function::New<CallConstructorWithCStyleArray>(env);
293
- exports["isConstructCall"] = Function::New<IsConstructCall>(env);
294
- exports["makeCallbackWithArgs"] = Function::New<MakeCallbackWithArgs>(env);
295
- exports["makeCallbackWithVector"] =
296
- Function::New<MakeCallbackWithVector>(env);
297
- exports["makeCallbackWithCStyleArray"] =
298
- Function::New<MakeCallbackWithCStyleArray>(env);
299
- exports["makeCallbackWithInvalidReceiver"] =
300
- Function::New<MakeCallbackWithInvalidReceiver>(env);
301
- exports["callWithFunctionOperator"] =
302
- Function::New<CallWithFunctionOperator>(env);
303
- result["templated"] = exports;
304
-
305
- exports = Object::New(env);
306
- exports["lambdaWithNoCapture"] =
307
- Function::New(env, [](const CallbackInfo& info) {
308
- auto env = info.Env();
309
- return Boolean::New(env, true);
310
- });
311
- exports["lambdaWithCapture"] =
312
- Function::New(env, [data = 42](const CallbackInfo& info) {
313
- auto env = info.Env();
314
- return Boolean::New(env, data == 42);
315
- });
316
- exports["lambdaWithMoveOnlyCapture"] = Function::New(
317
- env, [data = std::make_unique<int>(42)](const CallbackInfo& info) {
318
- auto env = info.Env();
319
- return Boolean::New(env, *data == 42);
320
- });
321
- result["lambda"] = exports;
322
-
323
- return result;
324
- }
@@ -1,133 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
-
5
- module.exports = require('./common').runTest(binding => {
6
- test(binding.function.plain);
7
- test(binding.function.templated);
8
- testLambda(binding.function.lambda);
9
- });
10
-
11
- function test (binding) {
12
- assert.strictEqual(binding.emptyConstructor(true), true);
13
- assert.strictEqual(binding.emptyConstructor(false), false);
14
-
15
- let obj = {};
16
- assert.deepStrictEqual(binding.voidCallback(obj), undefined);
17
- assert.deepStrictEqual(obj, { foo: 'bar' });
18
-
19
- assert.deepStrictEqual(binding.valueCallback(), { foo: 'bar' });
20
-
21
- let args = null;
22
- let ret = null;
23
- let receiver = null;
24
- function testFunction () {
25
- receiver = this;
26
- args = [].slice.call(arguments);
27
- return ret;
28
- }
29
- function testConstructor () {
30
- args = [].slice.call(arguments);
31
- }
32
-
33
- function makeCallbackTestFunction (receiver, expectedOne, expectedTwo, expectedThree) {
34
- return function callback (one, two, three) {
35
- assert.strictEqual(this, receiver);
36
- assert.strictEqual(one, expectedOne);
37
- assert.strictEqual(two, expectedTwo);
38
- assert.strictEqual(three, expectedThree);
39
- };
40
- }
41
-
42
- ret = 4;
43
- assert.strictEqual(binding.callWithArgs(testFunction, 1, 2, 3), 4);
44
- assert.strictEqual(receiver, undefined);
45
- assert.deepStrictEqual(args, [1, 2, 3]);
46
-
47
- ret = 5;
48
- assert.strictEqual(binding.callWithVector(testFunction, 2, 3, 4), 5);
49
- assert.strictEqual(receiver, undefined);
50
- assert.deepStrictEqual(args, [2, 3, 4]);
51
-
52
- ret = 5;
53
- assert.strictEqual(binding.callWithVectorUsingCppWrapper(testFunction, 2, 3, 4), 5);
54
- assert.strictEqual(receiver, undefined);
55
- assert.deepStrictEqual(args, [2, 3, 4]);
56
-
57
- ret = 6;
58
- assert.strictEqual(binding.callWithReceiverAndArgs(testFunction, obj, 3, 4, 5), 6);
59
- assert.deepStrictEqual(receiver, obj);
60
- assert.deepStrictEqual(args, [3, 4, 5]);
61
-
62
- ret = 7;
63
- assert.strictEqual(binding.callWithReceiverAndVector(testFunction, obj, 4, 5, 6), 7);
64
- assert.deepStrictEqual(receiver, obj);
65
- assert.deepStrictEqual(args, [4, 5, 6]);
66
-
67
- ret = 7;
68
- assert.strictEqual(binding.callWithReceiverAndVectorUsingCppWrapper(testFunction, obj, 4, 5, 6), 7);
69
- assert.deepStrictEqual(receiver, obj);
70
- assert.deepStrictEqual(args, [4, 5, 6]);
71
-
72
- ret = 8;
73
- assert.strictEqual(binding.callWithCStyleArray(testFunction, 5, 6, 7), ret);
74
- assert.deepStrictEqual(receiver, undefined);
75
- assert.deepStrictEqual(args, [5, 6, 7]);
76
-
77
- ret = 9;
78
- assert.strictEqual(binding.callWithReceiverAndCStyleArray(testFunction, obj, 6, 7, 8), ret);
79
- assert.deepStrictEqual(receiver, obj);
80
- assert.deepStrictEqual(args, [6, 7, 8]);
81
-
82
- ret = 10;
83
- assert.strictEqual(binding.callWithFunctionOperator(testFunction, 7, 8, 9), ret);
84
- assert.strictEqual(receiver, undefined);
85
- assert.deepStrictEqual(args, [7, 8, 9]);
86
-
87
- assert.throws(() => {
88
- binding.callWithInvalidReceiver();
89
- }, /Invalid (pointer passed as )?argument/);
90
-
91
- obj = binding.callConstructorWithArgs(testConstructor, 5, 6, 7);
92
- assert(obj instanceof testConstructor);
93
- assert.deepStrictEqual(args, [5, 6, 7]);
94
-
95
- obj = binding.callConstructorWithVector(testConstructor, 6, 7, 8);
96
- assert(obj instanceof testConstructor);
97
- assert.deepStrictEqual(args, [6, 7, 8]);
98
-
99
- obj = binding.callConstructorWithCStyleArray(testConstructor, 7, 8, 9);
100
- assert(obj instanceof testConstructor);
101
- assert.deepStrictEqual(args, [7, 8, 9]);
102
-
103
- obj = {};
104
- assert.deepStrictEqual(binding.voidCallbackWithData(obj), undefined);
105
- assert.deepStrictEqual(obj, { foo: 'bar', data: 1 });
106
-
107
- assert.deepStrictEqual(binding.valueCallbackWithData(), { foo: 'bar', data: 1 });
108
-
109
- assert.strictEqual(binding.voidCallback.name, 'voidCallback');
110
- assert.strictEqual(binding.valueCallback.name, 'valueCallback');
111
-
112
- let testConstructCall;
113
- binding.isConstructCall((result) => { testConstructCall = result; });
114
- assert.ok(!testConstructCall);
115
- /* eslint-disable no-new, new-cap */
116
- new binding.isConstructCall((result) => { testConstructCall = result; });
117
- /* eslint-enable no-new, new-cap */
118
- assert.ok(testConstructCall);
119
-
120
- obj = {};
121
- binding.makeCallbackWithArgs(makeCallbackTestFunction(obj, '1', '2', '3'), obj, '1', '2', '3');
122
- binding.makeCallbackWithVector(makeCallbackTestFunction(obj, 4, 5, 6), obj, 4, 5, 6);
123
- binding.makeCallbackWithCStyleArray(makeCallbackTestFunction(obj, 7, 8, 9), obj, 7, 8, 9);
124
- assert.throws(() => {
125
- binding.makeCallbackWithInvalidReceiver(() => {});
126
- });
127
- }
128
-
129
- function testLambda (binding) {
130
- assert.ok(binding.lambdaWithNoCapture());
131
- assert.ok(binding.lambdaWithCapture());
132
- assert.ok(binding.lambdaWithMoveOnlyCapture());
133
- }