koffi 2.3.4 → 2.3.6-beta.1

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 (206) hide show
  1. package/CHANGELOG.md +25 -2
  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 +5 -5
  6. package/src/cnoke/cnoke.js +40 -834
  7. package/src/cnoke/package.json +1 -0
  8. package/src/cnoke/src/builder.js +447 -0
  9. package/src/cnoke/src/index.js +20 -0
  10. package/src/cnoke/src/tools.js +401 -0
  11. package/src/core/libcc/libcc.cc +2 -2
  12. package/src/koffi/build/2.3.6-beta.1/koffi_darwin_arm64/koffi.node +0 -0
  13. package/src/koffi/build/2.3.6-beta.1/koffi_darwin_x64/koffi.node +0 -0
  14. package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_arm64/koffi.node +0 -0
  15. package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_ia32/koffi.node +0 -0
  16. package/src/koffi/build/2.3.6-beta.1/koffi_freebsd_x64/koffi.node +0 -0
  17. package/src/koffi/build/2.3.6-beta.1/koffi_linux_arm32hf/koffi.node +0 -0
  18. package/src/koffi/build/2.3.6-beta.1/koffi_linux_arm64/koffi.node +0 -0
  19. package/src/koffi/build/2.3.6-beta.1/koffi_linux_ia32/koffi.node +0 -0
  20. package/src/koffi/build/2.3.6-beta.1/koffi_linux_riscv64hf64/koffi.node +0 -0
  21. package/src/koffi/build/2.3.6-beta.1/koffi_linux_x64/koffi.node +0 -0
  22. package/src/koffi/build/2.3.6-beta.1/koffi_openbsd_ia32/koffi.node +0 -0
  23. package/src/koffi/build/2.3.6-beta.1/koffi_openbsd_x64/koffi.node +0 -0
  24. package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.exp +0 -0
  25. package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.lib +0 -0
  26. package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.node +0 -0
  27. package/src/koffi/build/2.3.6-beta.1/koffi_win32_arm64/koffi.pdb +0 -0
  28. package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.exp +0 -0
  29. package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.lib +0 -0
  30. package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.node +0 -0
  31. package/src/koffi/build/2.3.6-beta.1/koffi_win32_ia32/koffi.pdb +0 -0
  32. package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.exp +0 -0
  33. package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.lib +0 -0
  34. package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.node +0 -0
  35. package/src/koffi/build/2.3.6-beta.1/koffi_win32_x64/koffi.pdb +0 -0
  36. package/src/koffi/src/abi_arm32.cc +43 -14
  37. package/src/koffi/src/abi_arm64.cc +95 -21
  38. package/src/koffi/src/abi_riscv64.cc +125 -64
  39. package/src/koffi/src/abi_x64_sysv.cc +38 -20
  40. package/src/koffi/src/abi_x64_win.cc +11 -5
  41. package/src/koffi/src/abi_x86.cc +14 -7
  42. package/src/koffi/src/call.cc +114 -44
  43. package/src/koffi/src/call.hh +6 -4
  44. package/src/koffi/src/ffi.cc +172 -147
  45. package/src/koffi/src/ffi.hh +18 -10
  46. package/src/koffi/src/index.d.ts +28 -7
  47. package/src/koffi/src/index.js +23 -4
  48. package/src/koffi/src/util.cc +261 -69
  49. package/src/koffi/src/util.hh +34 -8
  50. package/vendor/node-addon-api/CHANGELOG.md +122 -9
  51. package/vendor/node-addon-api/CONTRIBUTING.md +10 -10
  52. package/vendor/node-addon-api/README.md +36 -12
  53. package/vendor/node-addon-api/benchmark/function_args.cc +95 -62
  54. package/vendor/node-addon-api/benchmark/function_args.js +6 -6
  55. package/vendor/node-addon-api/benchmark/index.js +1 -1
  56. package/vendor/node-addon-api/benchmark/property_descriptor.cc +27 -34
  57. package/vendor/node-addon-api/benchmark/property_descriptor.js +5 -4
  58. package/vendor/node-addon-api/doc/async_operations.md +1 -1
  59. package/vendor/node-addon-api/doc/async_worker_variants.md +23 -2
  60. package/vendor/node-addon-api/doc/cmake-js.md +1 -1
  61. package/vendor/node-addon-api/doc/error_handling.md +3 -3
  62. package/vendor/node-addon-api/doc/external.md +7 -0
  63. package/vendor/node-addon-api/doc/handle_scope.md +14 -0
  64. package/vendor/node-addon-api/doc/hierarchy.md +1 -1
  65. package/vendor/node-addon-api/doc/object.md +27 -0
  66. package/vendor/node-addon-api/index.js +3 -3
  67. package/vendor/node-addon-api/napi-inl.deprecated.h +121 -127
  68. package/vendor/node-addon-api/napi-inl.h +1178 -1144
  69. package/vendor/node-addon-api/napi.h +2786 -2675
  70. package/vendor/node-addon-api/package.json +42 -1
  71. package/vendor/node-addon-api/test/addon.cc +8 -6
  72. package/vendor/node-addon-api/test/addon_build/index.js +9 -9
  73. package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +2 -1
  74. package/vendor/node-addon-api/test/addon_build/tpl/index.js +4 -4
  75. package/vendor/node-addon-api/test/addon_data.cc +12 -13
  76. package/vendor/node-addon-api/test/array_buffer.js +3 -2
  77. package/vendor/node-addon-api/test/async_progress_queue_worker.cc +13 -3
  78. package/vendor/node-addon-api/test/async_progress_queue_worker.js +5 -5
  79. package/vendor/node-addon-api/test/async_progress_worker.cc +65 -9
  80. package/vendor/node-addon-api/test/async_progress_worker.js +14 -9
  81. package/vendor/node-addon-api/test/async_worker.cc +236 -3
  82. package/vendor/node-addon-api/test/async_worker.js +122 -37
  83. package/vendor/node-addon-api/test/async_worker_nocallback.js +9 -3
  84. package/vendor/node-addon-api/test/async_worker_persistent.js +2 -2
  85. package/vendor/node-addon-api/test/basic_types/array.js +3 -4
  86. package/vendor/node-addon-api/test/basic_types/boolean.cc +4 -2
  87. package/vendor/node-addon-api/test/basic_types/boolean.js +1 -2
  88. package/vendor/node-addon-api/test/basic_types/number.cc +12 -6
  89. package/vendor/node-addon-api/test/basic_types/number.js +19 -18
  90. package/vendor/node-addon-api/test/basic_types/value.cc +52 -1
  91. package/vendor/node-addon-api/test/basic_types/value.js +44 -21
  92. package/vendor/node-addon-api/test/bigint.cc +2 -1
  93. package/vendor/node-addon-api/test/binding.cc +11 -5
  94. package/vendor/node-addon-api/test/binding.gyp +3 -1
  95. package/vendor/node-addon-api/test/buffer.cc +46 -38
  96. package/vendor/node-addon-api/test/buffer.js +12 -12
  97. package/vendor/node-addon-api/test/callbackInfo.cc +27 -0
  98. package/vendor/node-addon-api/test/callbackInfo.js +9 -0
  99. package/vendor/node-addon-api/test/callbackscope.cc +19 -2
  100. package/vendor/node-addon-api/test/callbackscope.js +20 -20
  101. package/vendor/node-addon-api/test/common/index.js +37 -4
  102. package/vendor/node-addon-api/test/dataview/dataview.js +5 -5
  103. package/vendor/node-addon-api/test/dataview/dataview_read_write.js +14 -12
  104. package/vendor/node-addon-api/test/date.cc +2 -1
  105. package/vendor/node-addon-api/test/date.js +2 -2
  106. package/vendor/node-addon-api/test/env_cleanup.cc +12 -0
  107. package/vendor/node-addon-api/test/env_cleanup.js +38 -39
  108. package/vendor/node-addon-api/test/error.cc +6 -5
  109. package/vendor/node-addon-api/test/error_terminating_environment.js +64 -60
  110. package/vendor/node-addon-api/test/external.cc +36 -32
  111. package/vendor/node-addon-api/test/external.js +43 -46
  112. package/vendor/node-addon-api/test/function.cc +58 -44
  113. package/vendor/node-addon-api/test/function.js +4 -0
  114. package/vendor/node-addon-api/test/function_reference.cc +15 -13
  115. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +50 -53
  116. package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +33 -34
  117. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +38 -40
  118. package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +47 -49
  119. package/vendor/node-addon-api/test/handlescope.cc +29 -3
  120. package/vendor/node-addon-api/test/handlescope.js +5 -3
  121. package/vendor/node-addon-api/test/index.js +1 -5
  122. package/vendor/node-addon-api/test/maybe/check.cc +49 -3
  123. package/vendor/node-addon-api/test/maybe/index.js +19 -7
  124. package/vendor/node-addon-api/test/memory_management.cc +9 -8
  125. package/vendor/node-addon-api/test/memory_management.js +2 -2
  126. package/vendor/node-addon-api/test/movable_callbacks.js +2 -2
  127. package/vendor/node-addon-api/test/name.js +3 -3
  128. package/vendor/node-addon-api/test/napi_child.js +2 -2
  129. package/vendor/node-addon-api/test/object/delete_property.js +7 -7
  130. package/vendor/node-addon-api/test/object/finalizer.cc +13 -12
  131. package/vendor/node-addon-api/test/object/finalizer.js +2 -2
  132. package/vendor/node-addon-api/test/object/get_property.js +6 -6
  133. package/vendor/node-addon-api/test/object/has_own_property.js +3 -3
  134. package/vendor/node-addon-api/test/object/has_property.js +4 -4
  135. package/vendor/node-addon-api/test/object/object.cc +191 -111
  136. package/vendor/node-addon-api/test/object/object.js +53 -52
  137. package/vendor/node-addon-api/test/object/object_deprecated.cc +24 -20
  138. package/vendor/node-addon-api/test/object/object_deprecated.js +3 -8
  139. package/vendor/node-addon-api/test/object/object_freeze_seal.js +54 -54
  140. package/vendor/node-addon-api/test/object/object_type_tag.cc +39 -0
  141. package/vendor/node-addon-api/test/object/object_type_tag.js +55 -0
  142. package/vendor/node-addon-api/test/object/subscript_operator.js +2 -2
  143. package/vendor/node-addon-api/test/object_reference.js +100 -100
  144. package/vendor/node-addon-api/test/objectwrap.cc +41 -34
  145. package/vendor/node-addon-api/test/objectwrap.js +23 -19
  146. package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +5 -5
  147. package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +1 -1
  148. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +7 -7
  149. package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +1 -1
  150. package/vendor/node-addon-api/test/objectwrap_removewrap.js +24 -32
  151. package/vendor/node-addon-api/test/objectwrap_worker_thread.js +5 -4
  152. package/vendor/node-addon-api/test/promise.cc +7 -0
  153. package/vendor/node-addon-api/test/promise.js +3 -1
  154. package/vendor/node-addon-api/test/reference.cc +1 -1
  155. package/vendor/node-addon-api/test/reference.js +2 -2
  156. package/vendor/node-addon-api/test/run_script.cc +1 -1
  157. package/vendor/node-addon-api/test/symbol.js +59 -66
  158. package/vendor/node-addon-api/test/testUtil.js +6 -6
  159. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +64 -29
  160. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +71 -34
  161. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +111 -19
  162. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +2 -1
  163. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +36 -26
  164. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +5 -5
  165. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +3 -2
  166. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +1 -1
  167. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +47 -32
  168. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +3 -3
  169. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +22 -9
  170. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +76 -31
  171. package/vendor/node-addon-api/test/thunking_manual.cc +61 -74
  172. package/vendor/node-addon-api/test/thunking_manual.js +6 -7
  173. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +20 -20
  174. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +19 -19
  175. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +57 -5
  176. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +2 -0
  177. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +5 -5
  178. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +5 -1
  179. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +4 -3
  180. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +3 -3
  181. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +14 -0
  182. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +76 -31
  183. package/vendor/node-addon-api/test/typedarray-bigint.js +2 -2
  184. package/vendor/node-addon-api/test/typedarray.cc +263 -70
  185. package/vendor/node-addon-api/test/typedarray.js +44 -10
  186. package/vendor/node-addon-api/test/version_management.cc +16 -15
  187. package/vendor/node-addon-api/test/version_management.js +18 -20
  188. package/vendor/node-addon-api/tools/check-napi.js +13 -14
  189. package/vendor/node-addon-api/tools/conversion.js +161 -169
  190. package/vendor/node-addon-api/tools/eslint-format.js +9 -1
  191. package/vendor/node-addon-api/unit-test/README.md +4 -4
  192. package/src/koffi/build/2.3.4/koffi_darwin_arm64.tar.gz +0 -0
  193. package/src/koffi/build/2.3.4/koffi_darwin_x64.tar.gz +0 -0
  194. package/src/koffi/build/2.3.4/koffi_freebsd_arm64.tar.gz +0 -0
  195. package/src/koffi/build/2.3.4/koffi_freebsd_ia32.tar.gz +0 -0
  196. package/src/koffi/build/2.3.4/koffi_freebsd_x64.tar.gz +0 -0
  197. package/src/koffi/build/2.3.4/koffi_linux_arm32hf.tar.gz +0 -0
  198. package/src/koffi/build/2.3.4/koffi_linux_arm64.tar.gz +0 -0
  199. package/src/koffi/build/2.3.4/koffi_linux_ia32.tar.gz +0 -0
  200. package/src/koffi/build/2.3.4/koffi_linux_riscv64hf64.tar.gz +0 -0
  201. package/src/koffi/build/2.3.4/koffi_linux_x64.tar.gz +0 -0
  202. package/src/koffi/build/2.3.4/koffi_openbsd_ia32.tar.gz +0 -0
  203. package/src/koffi/build/2.3.4/koffi_openbsd_x64.tar.gz +0 -0
  204. package/src/koffi/build/2.3.4/koffi_win32_arm64.tar.gz +0 -0
  205. package/src/koffi/build/2.3.4/koffi_win32_ia32.tar.gz +0 -0
  206. package/src/koffi/build/2.3.4/koffi_win32_x64.tar.gz +0 -0
@@ -4,45 +4,43 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- function test(binding) {
8
- const KEY_TYPE = {
9
- C_STR: 'KEY_AS_C_STRING',
10
- CPP_STR: 'KEY_AS_CPP_STRING',
11
- NAPI: 'KEY_AS_NAPI_VALUES',
12
- INT_32: 'KEY_AS_INT_32_NUM'
13
- };
14
-
15
- function assertGlobalObjectHasProperty(key, keyType)
16
- {
17
- switch(keyType)
18
- {
19
- case KEY_TYPE.NAPI:
20
- assert.strictEqual(binding.globalObject.hasPropertyWithNapiValue(key), true);
21
- break;
22
-
23
- case KEY_TYPE.C_STR:
24
- assert.strictEqual(binding.globalObject.hasPropertyWithCStyleString(key), true);
25
- break;
26
-
27
- case KEY_TYPE.CPP_STR:
28
- assert.strictEqual(binding.globalObject.hasPropertyWithCppStyleString(key), true);
29
- break;
30
- }
7
+ function test (binding) {
8
+ const KEY_TYPE = {
9
+ C_STR: 'KEY_AS_C_STRING',
10
+ CPP_STR: 'KEY_AS_CPP_STRING',
11
+ NAPI: 'KEY_AS_NAPI_VALUES',
12
+ INT_32: 'KEY_AS_INT_32_NUM'
13
+ };
14
+
15
+ function assertGlobalObjectHasProperty (key, keyType) {
16
+ switch (keyType) {
17
+ case KEY_TYPE.NAPI:
18
+ assert.strictEqual(binding.globalObject.hasPropertyWithNapiValue(key), true);
19
+ break;
20
+
21
+ case KEY_TYPE.C_STR:
22
+ assert.strictEqual(binding.globalObject.hasPropertyWithCStyleString(key), true);
23
+ break;
24
+
25
+ case KEY_TYPE.CPP_STR:
26
+ assert.strictEqual(binding.globalObject.hasPropertyWithCppStyleString(key), true);
27
+ break;
31
28
  }
32
-
33
- function assertErrMessageIsThrown(propertyCheckExistenceFunction, errMsg) {
34
- assert.throws(() => {
35
- propertyCheckExistenceFunction(undefined);
36
- }, errMsg);
37
- }
38
-
39
- binding.globalObject.createMockTestObject();
40
- assertGlobalObjectHasProperty('c_str_key',KEY_TYPE.C_STR);
41
- assertGlobalObjectHasProperty('cpp_string_key',KEY_TYPE.CPP_STR);
42
- assertGlobalObjectHasProperty('circular',KEY_TYPE.CPP_STR);
43
- assertGlobalObjectHasProperty('2', KEY_TYPE.NAPI);
44
-
45
- assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCppStyleString, 'Error: A string was expected');
46
- assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCStyleString, 'Error: A string was expected');
47
- assertErrMessageIsThrown(binding.globalObject.hasPropertyWithInt32, 'Error: A number was expected');
29
+ }
30
+
31
+ function assertErrMessageIsThrown (propertyCheckExistenceFunction, errMsg) {
32
+ assert.throws(() => {
33
+ propertyCheckExistenceFunction(undefined);
34
+ }, errMsg);
35
+ }
36
+
37
+ binding.globalObject.createMockTestObject();
38
+ assertGlobalObjectHasProperty('c_str_key', KEY_TYPE.C_STR);
39
+ assertGlobalObjectHasProperty('cpp_string_key', KEY_TYPE.CPP_STR);
40
+ assertGlobalObjectHasProperty('circular', KEY_TYPE.CPP_STR);
41
+ assertGlobalObjectHasProperty('2', KEY_TYPE.NAPI);
42
+
43
+ assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCppStyleString, 'Error: A string was expected');
44
+ assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCStyleString, 'Error: A string was expected');
45
+ assertErrMessageIsThrown(binding.globalObject.hasPropertyWithInt32, 'Error: A number was expected');
48
46
  }
@@ -4,55 +4,53 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- function test(binding) {
7
+ function test (binding) {
8
8
  const KEY_TYPE = {
9
- C_STR: 'KEY_AS_C_STRING',
10
- CPP_STR: 'KEY_AS_CPP_STRING',
11
- NAPI: 'KEY_AS_NAPI_VALUES',
12
- INT_32: 'KEY_AS_INT_32_NUM'
13
- };
14
-
15
- function setGlobalObjectKeyValue(key, value, keyType) {
16
- switch(keyType)
17
- {
18
- case KEY_TYPE.CPP_STR:
19
- binding.globalObject.setPropertyWithCppStyleString(key,value);
20
- break;
21
-
22
- case KEY_TYPE.C_STR:
23
- binding.globalObject.setPropertyWithCStyleString(key,value);
24
- break;
25
-
26
- case KEY_TYPE.INT_32:
27
- binding.globalObject.setPropertyWithInt32(key,value);
28
- break;
29
-
30
- case KEY_TYPE.NAPI:
31
- binding.globalObject.setPropertyWithNapiValue(key,value);
32
- break;
33
- }
9
+ C_STR: 'KEY_AS_C_STRING',
10
+ CPP_STR: 'KEY_AS_CPP_STRING',
11
+ NAPI: 'KEY_AS_NAPI_VALUES',
12
+ INT_32: 'KEY_AS_INT_32_NUM'
13
+ };
14
+
15
+ function setGlobalObjectKeyValue (key, value, keyType) {
16
+ switch (keyType) {
17
+ case KEY_TYPE.CPP_STR:
18
+ binding.globalObject.setPropertyWithCppStyleString(key, value);
19
+ break;
20
+
21
+ case KEY_TYPE.C_STR:
22
+ binding.globalObject.setPropertyWithCStyleString(key, value);
23
+ break;
24
+
25
+ case KEY_TYPE.INT_32:
26
+ binding.globalObject.setPropertyWithInt32(key, value);
27
+ break;
28
+
29
+ case KEY_TYPE.NAPI:
30
+ binding.globalObject.setPropertyWithNapiValue(key, value);
31
+ break;
34
32
  }
35
-
36
- function assertErrMessageIsThrown(nativeObjectSetFunction, errMsg) {
37
- assert.throws(() => {
38
- nativeObjectSetFunction(undefined, 1);
39
- }, errMsg);
40
- }
41
-
42
-
43
- setGlobalObjectKeyValue("cKey","cValue",KEY_TYPE.CPP_STR);
44
- setGlobalObjectKeyValue(1,10,KEY_TYPE.INT_32);
45
- setGlobalObjectKeyValue("napi_key","napi_value",KEY_TYPE.NAPI);
46
- setGlobalObjectKeyValue("cppKey","cppValue",KEY_TYPE.CPP_STR);
47
- setGlobalObjectKeyValue("circular",global,KEY_TYPE.NAPI);
48
-
49
- assert.deepStrictEqual(global["circular"], global);
50
- assert.deepStrictEqual(global["cppKey"],"cppValue");
51
- assert.deepStrictEqual(global["napi_key"],"napi_value");
52
- assert.deepStrictEqual(global[1],10);
53
- assert.deepStrictEqual(global["cKey"],"cValue");
54
-
55
- assertErrMessageIsThrown(binding.globalObject.setPropertyWithCppStyleString, 'Error: A string was expected');
56
- assertErrMessageIsThrown(binding.globalObject.setPropertyWithCStyleString, 'Error: A string was expected');
57
- assertErrMessageIsThrown(binding.globalObject.setPropertyWithInt32, 'Error: A number was expected');
33
+ }
34
+
35
+ function assertErrMessageIsThrown (nativeObjectSetFunction, errMsg) {
36
+ assert.throws(() => {
37
+ nativeObjectSetFunction(undefined, 1);
38
+ }, errMsg);
39
+ }
40
+
41
+ setGlobalObjectKeyValue('cKey', 'cValue', KEY_TYPE.CPP_STR);
42
+ setGlobalObjectKeyValue(1, 10, KEY_TYPE.INT_32);
43
+ setGlobalObjectKeyValue('napi_key', 'napi_value', KEY_TYPE.NAPI);
44
+ setGlobalObjectKeyValue('cppKey', 'cppValue', KEY_TYPE.CPP_STR);
45
+ setGlobalObjectKeyValue('circular', global, KEY_TYPE.NAPI);
46
+
47
+ assert.deepStrictEqual(global.circular, global);
48
+ assert.deepStrictEqual(global.cppKey, 'cppValue');
49
+ assert.deepStrictEqual(global.napi_key, 'napi_value');
50
+ assert.deepStrictEqual(global[1], 10);
51
+ assert.deepStrictEqual(global.cKey, 'cValue');
52
+
53
+ assertErrMessageIsThrown(binding.globalObject.setPropertyWithCppStyleString, 'Error: A string was expected');
54
+ assertErrMessageIsThrown(binding.globalObject.setPropertyWithCStyleString, 'Error: A string was expected');
55
+ assertErrMessageIsThrown(binding.globalObject.setPropertyWithInt32, 'Error: A number was expected');
58
56
  }
@@ -1,7 +1,7 @@
1
- #include "napi.h"
2
- #include "string.h"
3
1
  #include <stdio.h>
4
2
  #include <stdlib.h>
3
+ #include "napi.h"
4
+ #include "string.h"
5
5
 
6
6
  using namespace Napi;
7
7
 
@@ -13,6 +13,16 @@ Value createScope(const CallbackInfo& info) {
13
13
  return String::New(info.Env(), "scope");
14
14
  }
15
15
 
16
+ Value createScopeFromExisting(const CallbackInfo& info) {
17
+ {
18
+ napi_handle_scope scope;
19
+ napi_open_handle_scope(info.Env(), &scope);
20
+ HandleScope scope_existing(info.Env(), scope);
21
+ String::New(scope_existing.Env(), "inner-existing-scope");
22
+ }
23
+ return String::New(info.Env(), "existing_scope");
24
+ }
25
+
16
26
  Value escapeFromScope(const CallbackInfo& info) {
17
27
  Value result;
18
28
  {
@@ -22,6 +32,18 @@ Value escapeFromScope(const CallbackInfo& info) {
22
32
  return result;
23
33
  }
24
34
 
35
+ Value escapeFromExistingScope(const CallbackInfo& info) {
36
+ Value result;
37
+ {
38
+ napi_escapable_handle_scope scope;
39
+ napi_open_escapable_handle_scope(info.Env(), &scope);
40
+ EscapableHandleScope scope_existing(info.Env(), scope);
41
+ result = scope_existing.Escape(
42
+ String::New(scope_existing.Env(), "inner-existing-scope"));
43
+ }
44
+ return result;
45
+ }
46
+
25
47
  #define LOOP_MAX 1000000
26
48
  Value stressEscapeFromScope(const CallbackInfo& info) {
27
49
  Value result;
@@ -31,7 +53,7 @@ Value stressEscapeFromScope(const CallbackInfo& info) {
31
53
  snprintf(buffer, 128, "%d", i);
32
54
  std::string name = std::string("inner-scope") + std::string(buffer);
33
55
  Value newValue = String::New(info.Env(), name.c_str());
34
- if (i == (LOOP_MAX -1)) {
56
+ if (i == (LOOP_MAX - 1)) {
35
57
  result = scope.Escape(newValue);
36
58
  }
37
59
  }
@@ -52,7 +74,11 @@ Object InitHandleScope(Env env) {
52
74
  Object exports = Object::New(env);
53
75
 
54
76
  exports["createScope"] = Function::New(env, createScope);
77
+ exports["createScopeFromExisting"] =
78
+ Function::New(env, createScopeFromExisting);
55
79
  exports["escapeFromScope"] = Function::New(env, escapeFromScope);
80
+ exports["escapeFromExistingScope"] =
81
+ Function::New(env, escapeFromExistingScope);
56
82
  exports["stressEscapeFromScope"] = Function::New(env, stressEscapeFromScope);
57
83
  exports["doubleEscapeFromScope"] = Function::New(env, doubleEscapeFromScope);
58
84
 
@@ -4,11 +4,13 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('./common').runTest(test);
6
6
 
7
- function test(binding) {
7
+ function test (binding) {
8
8
  assert.strictEqual(binding.handlescope.createScope(), 'scope');
9
+ assert.strictEqual(binding.handlescope.createScopeFromExisting(), 'existing_scope');
9
10
  assert.strictEqual(binding.handlescope.escapeFromScope(), 'inner-scope');
11
+ assert.strictEqual(binding.handlescope.escapeFromExistingScope(), 'inner-existing-scope');
10
12
  assert.strictEqual(binding.handlescope.stressEscapeFromScope(), 'inner-scope999999');
11
13
  assert.throws(() => binding.handlescope.doubleEscapeFromScope(),
12
- Error,
13
- ' napi_escape_handle already called on scope');
14
+ Error,
15
+ ' napi_escape_handle already called on scope');
14
16
  }
@@ -90,11 +90,6 @@ function loadTestModules (currentDirectory = __dirname, pre = '') {
90
90
 
91
91
  loadTestModules();
92
92
 
93
- process.config.target_defaults.default_configuration =
94
- fs
95
- .readdirSync(path.join(__dirname, process.env.REL_BUILD_PATH || '', 'build'))
96
- .filter((item) => (item === 'Debug' || item === 'Release'))[0];
97
-
98
93
  let napiVersion = Number(process.versions.napi);
99
94
  if (process.env.NAPI_VERSION) {
100
95
  // we need this so that we don't try run tests that rely
@@ -139,6 +134,7 @@ if (majorNodeVersion < 12 && !filterConditionsProvided) {
139
134
 
140
135
  if (napiVersion < 8 && !filterConditionsProvided) {
141
136
  testModules.splice(testModules.indexOf('object/object_freeze_seal'), 1);
137
+ testModules.splice(testModules.indexOf('object/object_type_tag'), 1);
142
138
  }
143
139
 
144
140
  (async function () {
@@ -1,3 +1,4 @@
1
+ #include "assert.h"
1
2
  #include "napi.h"
2
3
  #if defined(NODE_ADDON_API_ENABLE_MAYBE)
3
4
 
@@ -6,11 +7,52 @@ using namespace Napi;
6
7
  namespace {
7
8
 
8
9
  void VoidCallback(const CallbackInfo& info) {
9
- Function fn = info[0].As<Function>();
10
+ Napi::Function fn = info[0].As<Function>();
11
+ Maybe<Value> ret = fn.Call({});
10
12
 
11
- Maybe<Value> it = fn.Call({});
13
+ assert(ret.IsNothing() == true);
14
+ assert(ret.IsJust() == false);
12
15
 
13
- it.Check();
16
+ Napi::Value placeHolder = Napi::Number::New(info.Env(), 12345);
17
+ Napi::Value unwrappedValue = ret.UnwrapOr(placeHolder);
18
+
19
+ assert(unwrappedValue.As<Number>().Uint32Value() == 12345);
20
+
21
+ assert(ret.UnwrapTo(&placeHolder) == false);
22
+ assert(placeHolder.As<Number>().Uint32Value() == 12345);
23
+
24
+ ret.Check();
25
+ }
26
+
27
+ void TestMaybeOperatorOverload(const CallbackInfo& info) {
28
+ Napi::Function fn_a = info[0].As<Function>();
29
+ Napi::Function fn_b = info[1].As<Function>();
30
+
31
+ assert(fn_a.Call({}) == fn_a.Call({}));
32
+ assert(fn_a.Call({}) != fn_b.Call({}));
33
+ }
34
+
35
+ void NormalJsCallback(const CallbackInfo& info) {
36
+ Napi::Function fn = info[0].As<Function>();
37
+ uint32_t magic_number = info[1].As<Number>().Uint32Value();
38
+
39
+ Maybe<Value> ret = fn.Call({});
40
+
41
+ assert(ret.IsNothing() == false);
42
+ assert(ret.IsJust() == true);
43
+
44
+ Napi::Value unwrappedValue = ret.Unwrap();
45
+ assert(unwrappedValue.IsNumber() == true);
46
+
47
+ assert(unwrappedValue.As<Number>().Uint32Value() == magic_number);
48
+
49
+ unwrappedValue =
50
+ ret.UnwrapOr(Napi::Number::New(info.Env(), magic_number - 1));
51
+ assert(unwrappedValue.As<Number>().Uint32Value() == magic_number);
52
+
53
+ Napi::Value placeHolder = Napi::Number::New(info.Env(), magic_number - 1);
54
+ assert(ret.UnwrapTo(&placeHolder) == true);
55
+ assert(placeHolder.As<Number>().Uint32Value() == magic_number);
14
56
  }
15
57
 
16
58
  } // end anonymous namespace
@@ -18,6 +60,10 @@ void VoidCallback(const CallbackInfo& info) {
18
60
  Object InitMaybeCheck(Env env) {
19
61
  Object exports = Object::New(env);
20
62
  exports.Set("voidCallback", Function::New(env, VoidCallback));
63
+ exports.Set("normalJsCallback", Function::New(env, NormalJsCallback));
64
+ exports.Set("testMaybeOverloadOp",
65
+ Function::New(env, TestMaybeOperatorOverload));
21
66
  return exports;
22
67
  }
68
+
23
69
  #endif
@@ -1,20 +1,22 @@
1
1
  'use strict';
2
2
 
3
- const buildType = process.config.target_defaults.default_configuration;
4
3
  const assert = require('assert');
5
- const os = require('os');
4
+ const { whichBuildType } = require('../common');
6
5
 
7
6
  const napiChild = require('../napi_child');
8
7
 
9
- module.exports = test(require(`../build/${buildType}/binding_noexcept_maybe.node`).maybe_check);
8
+ module.exports = async function wrapTest () {
9
+ const buildType = await whichBuildType();
10
+ test(require(`../build/${buildType}/binding_noexcept_maybe.node`).maybe_check);
11
+ };
10
12
 
11
- function test(binding) {
13
+ function test (binding) {
12
14
  if (process.argv.includes('child')) {
13
15
  child(binding);
14
16
  return;
15
17
  }
16
18
  const cp = napiChild.spawn(process.execPath, [__filename, 'child'], {
17
- stdio: ['ignore', 'inherit', 'pipe'],
19
+ stdio: ['ignore', 'inherit', 'pipe']
18
20
  });
19
21
  cp.stderr.setEncoding('utf8');
20
22
  let stderr = '';
@@ -31,8 +33,18 @@ function test(binding) {
31
33
  });
32
34
  }
33
35
 
34
- function child(binding) {
36
+ function child (binding) {
37
+ const MAGIC_NUMBER = 12459062;
38
+ binding.normalJsCallback(() => {
39
+ return MAGIC_NUMBER;
40
+ }, MAGIC_NUMBER);
41
+
42
+ binding.testMaybeOverloadOp(
43
+ () => { return MAGIC_NUMBER; },
44
+ () => { throw Error('Foobar'); }
45
+ );
46
+
35
47
  binding.voidCallback(() => {
36
48
  throw new Error('foobar');
37
- })
49
+ });
38
50
  }
@@ -3,15 +3,16 @@
3
3
  using namespace Napi;
4
4
 
5
5
  Value externalAllocatedMemory(const CallbackInfo& info) {
6
- int64_t kSize = 1024 * 1024;
7
- int64_t baseline = MemoryManagement::AdjustExternalMemory(info.Env(), 0);
8
- int64_t tmp = MemoryManagement::AdjustExternalMemory(info.Env(), kSize);
9
- tmp = MemoryManagement::AdjustExternalMemory(info.Env(), -kSize);
10
- return Boolean::New(info.Env(), tmp == baseline);
6
+ int64_t kSize = 1024 * 1024;
7
+ int64_t baseline = MemoryManagement::AdjustExternalMemory(info.Env(), 0);
8
+ int64_t tmp = MemoryManagement::AdjustExternalMemory(info.Env(), kSize);
9
+ tmp = MemoryManagement::AdjustExternalMemory(info.Env(), -kSize);
10
+ return Boolean::New(info.Env(), tmp == baseline);
11
11
  }
12
12
 
13
13
  Object InitMemoryManagement(Env env) {
14
- Object exports = Object::New(env);
15
- exports["externalAllocatedMemory"] = Function::New(env, externalAllocatedMemory);
16
- return exports;
14
+ Object exports = Object::New(env);
15
+ exports["externalAllocatedMemory"] =
16
+ Function::New(env, externalAllocatedMemory);
17
+ return exports;
17
18
  }
@@ -4,6 +4,6 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('./common').runTest(test);
6
6
 
7
- function test(binding) {
8
- assert.strictEqual(binding.memory_management.externalAllocatedMemory(), true)
7
+ function test (binding) {
8
+ assert.strictEqual(binding.memory_management.externalAllocatedMemory(), true);
9
9
  }
@@ -5,14 +5,14 @@ const testUtil = require('./testUtil');
5
5
 
6
6
  module.exports = require('./common').runTest(binding => test(binding.movable_callbacks));
7
7
 
8
- async function test(binding) {
8
+ async function test (binding) {
9
9
  await testUtil.runGCTests([
10
10
  'External',
11
11
  () => {
12
12
  const fn = common.mustCall(() => {
13
13
  // noop
14
14
  }, 1);
15
- const external = binding.createExternal(fn);
15
+ binding.createExternal(fn);
16
16
  },
17
17
  () => {
18
18
  // noop, wait for gc
@@ -4,13 +4,12 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('./common').runTest(test);
6
6
 
7
- function test(binding) {
7
+ function test (binding) {
8
8
  const expected = '123456789';
9
9
 
10
-
11
10
  assert.throws(binding.name.nullStringShouldThrow, {
12
11
  name: 'Error',
13
- message: 'Error in native callback',
12
+ message: 'Error in native callback'
14
13
  });
15
14
  assert.ok(binding.name.checkString(expected, 'utf8'));
16
15
  assert.ok(binding.name.checkString(expected, 'utf16'));
@@ -37,6 +36,7 @@ function test(binding) {
37
36
  assert.ok(binding.name.checkString(substr2, 'utf8', 3));
38
37
  assert.ok(binding.name.checkString(substr2, 'utf16', 3));
39
38
 
39
+ // eslint-disable-next-line symbol-description
40
40
  assert.ok(binding.name.checkSymbol(Symbol()));
41
41
  assert.ok(binding.name.checkSymbol(Symbol('test')));
42
42
 
@@ -1,12 +1,12 @@
1
1
  // Makes sure that child processes are spawned appropriately.
2
- exports.spawnSync = function(command, args, options) {
2
+ exports.spawnSync = function (command, args, options) {
3
3
  if (require('../index').needsFlag) {
4
4
  args.splice(0, 0, '--napi-modules');
5
5
  }
6
6
  return require('child_process').spawnSync(command, args, options);
7
7
  };
8
8
 
9
- exports.spawn = function(command, args, options) {
9
+ exports.spawn = function (command, args, options) {
10
10
  if (require('../index').needsFlag) {
11
11
  args.splice(0, 0, '--napi-modules');
12
12
  }
@@ -4,10 +4,10 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- function test(binding) {
8
- function testDeleteProperty(nativeDeleteProperty) {
7
+ function test (binding) {
8
+ function testDeleteProperty (nativeDeleteProperty) {
9
9
  const obj = { one: 1, two: 2 };
10
- Object.defineProperty(obj, "three", {configurable: false, value: 3});
10
+ Object.defineProperty(obj, 'three', { configurable: false, value: 3 });
11
11
  assert.strictEqual(nativeDeleteProperty(obj, 'one'), true);
12
12
  assert.strictEqual(nativeDeleteProperty(obj, 'missing'), true);
13
13
 
@@ -17,17 +17,17 @@ function test(binding) {
17
17
  assert.deepStrictEqual(obj, { two: 2 });
18
18
  }
19
19
 
20
- function testShouldThrowErrorIfKeyIsInvalid(nativeDeleteProperty) {
20
+ function testShouldThrowErrorIfKeyIsInvalid (nativeDeleteProperty) {
21
21
  assert.throws(() => {
22
22
  nativeDeleteProperty(undefined, 'test');
23
23
  }, /Cannot convert undefined or null to object/);
24
24
  }
25
25
 
26
- const testObj = { 15 : 42 , three: 3};
26
+ const testObj = { 15: 42, three: 3 };
27
27
 
28
- binding.object.deletePropertyWithUint32(testObj,15);
28
+ binding.object.deletePropertyWithUint32(testObj, 15);
29
29
 
30
- assert.strictEqual(testObj.hasOwnProperty(15),false);
30
+ assert.strictEqual(Object.prototype.hasOwnProperty.call(testObj, 15), false);
31
31
 
32
32
  testDeleteProperty(binding.object.deletePropertyWithNapiValue);
33
33
  testDeleteProperty(binding.object.deletePropertyWithNapiWrapperValue);
@@ -7,23 +7,24 @@ static int dummy;
7
7
  Value AddFinalizer(const CallbackInfo& info) {
8
8
  ObjectReference* ref = new ObjectReference;
9
9
  *ref = Persistent(Object::New(info.Env()));
10
- info[0]
11
- .As<Object>()
12
- .AddFinalizer([](Napi::Env /*env*/, ObjectReference* ref) {
13
- ref->Set("finalizerCalled", true);
14
- delete ref;
15
- }, ref);
10
+ info[0].As<Object>().AddFinalizer(
11
+ [](Napi::Env /*env*/, ObjectReference* ref) {
12
+ ref->Set("finalizerCalled", true);
13
+ delete ref;
14
+ },
15
+ ref);
16
16
  return ref->Value();
17
17
  }
18
18
 
19
19
  Value AddFinalizerWithHint(const CallbackInfo& info) {
20
20
  ObjectReference* ref = new ObjectReference;
21
21
  *ref = Persistent(Object::New(info.Env()));
22
- info[0]
23
- .As<Object>()
24
- .AddFinalizer([](Napi::Env /*env*/, ObjectReference* ref, int* dummy_p) {
25
- ref->Set("finalizerCalledWithCorrectHint", dummy_p == &dummy);
26
- delete ref;
27
- }, ref, &dummy);
22
+ info[0].As<Object>().AddFinalizer(
23
+ [](Napi::Env /*env*/, ObjectReference* ref, int* dummy_p) {
24
+ ref->Set("finalizerCalledWithCorrectHint", dummy_p == &dummy);
25
+ delete ref;
26
+ },
27
+ ref,
28
+ &dummy);
28
29
  return ref->Value();
29
30
  }
@@ -5,11 +5,11 @@ const testUtil = require('../testUtil');
5
5
 
6
6
  module.exports = require('../common').runTest(test);
7
7
 
8
- function createWeakRef(binding, bindingToTest) {
8
+ function createWeakRef (binding, bindingToTest) {
9
9
  return binding.object[bindingToTest]({});
10
10
  }
11
11
 
12
- function test(binding) {
12
+ function test (binding) {
13
13
  let obj1;
14
14
  let obj2;
15
15
  return testUtil.runGCTests([
@@ -4,26 +4,26 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- function test(binding) {
8
- function testGetProperty(nativeGetProperty) {
7
+ function test (binding) {
8
+ function testGetProperty (nativeGetProperty) {
9
9
  const obj = { test: 1 };
10
10
  assert.strictEqual(nativeGetProperty(obj, 'test'), 1);
11
11
  }
12
12
 
13
- function testShouldReturnUndefinedIfKeyIsNotPresent(nativeGetProperty) {
13
+ function testShouldReturnUndefinedIfKeyIsNotPresent (nativeGetProperty) {
14
14
  const obj = { };
15
15
  assert.strictEqual(nativeGetProperty(obj, 'test'), undefined);
16
16
  }
17
17
 
18
- function testShouldThrowErrorIfKeyIsInvalid(nativeGetProperty) {
18
+ function testShouldThrowErrorIfKeyIsInvalid (nativeGetProperty) {
19
19
  assert.throws(() => {
20
20
  nativeGetProperty(undefined, 'test');
21
21
  }, /Cannot convert undefined or null to object/);
22
22
  }
23
23
 
24
24
  const testObject = { 42: 100 };
25
- const property = binding.object.getPropertyWithUint32(testObject, 42);
26
- assert.strictEqual(property,100)
25
+ const property = binding.object.getPropertyWithUint32(testObject, 42);
26
+ assert.strictEqual(property, 100);
27
27
 
28
28
  const nativeFunctions = [
29
29
  binding.object.getPropertyWithNapiValue,
@@ -4,8 +4,8 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- function test(binding) {
8
- function testHasOwnProperty(nativeHasOwnProperty) {
7
+ function test (binding) {
8
+ function testHasOwnProperty (nativeHasOwnProperty) {
9
9
  const obj = { one: 1 };
10
10
 
11
11
  Object.defineProperty(obj, 'two', { value: 2 });
@@ -16,7 +16,7 @@ function test(binding) {
16
16
  assert.strictEqual(nativeHasOwnProperty(obj, 'toString'), false);
17
17
  }
18
18
 
19
- function testShouldThrowErrorIfKeyIsInvalid(nativeHasOwnProperty) {
19
+ function testShouldThrowErrorIfKeyIsInvalid (nativeHasOwnProperty) {
20
20
  assert.throws(() => {
21
21
  nativeHasOwnProperty(undefined, 'test');
22
22
  }, /Cannot convert undefined or null to object/);