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
@@ -22,64 +22,59 @@ static Napi::Value TestGetter(const Napi::CallbackInfo& /*info*/) {
22
22
  return Napi::Value();
23
23
  }
24
24
 
25
- static void TestSetter(const Napi::CallbackInfo& /*info*/) {
26
- }
25
+ static void TestSetter(const Napi::CallbackInfo& /*info*/) {}
27
26
 
28
27
  class TestClass : public Napi::ObjectWrap<TestClass> {
29
28
  public:
30
- TestClass(const Napi::CallbackInfo& info):
31
- ObjectWrap<TestClass>(info) {
32
- }
29
+ TestClass(const Napi::CallbackInfo& info) : ObjectWrap<TestClass>(info) {}
33
30
  static Napi::Value TestClassStaticMethod(const Napi::CallbackInfo& info) {
34
31
  return Napi::Number::New(info.Env(), 42);
35
32
  }
36
33
 
37
- static void TestClassStaticVoidMethod(const Napi::CallbackInfo& /*info*/) {
38
- }
34
+ static void TestClassStaticVoidMethod(const Napi::CallbackInfo& /*info*/) {}
39
35
 
40
36
  Napi::Value TestClassInstanceMethod(const Napi::CallbackInfo& info) {
41
37
  return Napi::Number::New(info.Env(), 42);
42
38
  }
43
39
 
44
- void TestClassInstanceVoidMethod(const Napi::CallbackInfo& /*info*/) {
45
- }
40
+ void TestClassInstanceVoidMethod(const Napi::CallbackInfo& /*info*/) {}
46
41
 
47
42
  Napi::Value TestClassInstanceGetter(const Napi::CallbackInfo& info) {
48
43
  return Napi::Number::New(info.Env(), 42);
49
44
  }
50
45
 
51
46
  void TestClassInstanceSetter(const Napi::CallbackInfo& /*info*/,
52
- const Napi::Value& /*new_value*/) {
53
- }
47
+ const Napi::Value& /*new_value*/) {}
54
48
 
55
49
  static Napi::Function NewClass(Napi::Env env) {
56
- return DefineClass(env, "TestClass", {
57
- // Make sure to check that the deleter gets called.
58
- StaticMethod("staticMethod", TestClassStaticMethod),
59
- // Make sure to check that the deleter gets called.
60
- StaticMethod("staticVoidMethod", TestClassStaticVoidMethod),
61
- // Make sure to check that the deleter gets called.
62
- StaticMethod(Napi::Symbol::New(env, "staticMethod"),
63
- TestClassStaticMethod),
64
- // Make sure to check that the deleter gets called.
65
- StaticMethod(Napi::Symbol::New(env, "staticVoidMethod"),
66
- TestClassStaticVoidMethod),
67
- // Make sure to check that the deleter gets called.
68
- InstanceMethod("instanceMethod", &TestClass::TestClassInstanceMethod),
69
- // Make sure to check that the deleter gets called.
70
- InstanceMethod("instanceVoidMethod",
71
- &TestClass::TestClassInstanceVoidMethod),
72
- // Make sure to check that the deleter gets called.
73
- InstanceMethod(Napi::Symbol::New(env, "instanceMethod"),
74
- &TestClass::TestClassInstanceMethod),
75
- // Make sure to check that the deleter gets called.
76
- InstanceMethod(Napi::Symbol::New(env, "instanceVoidMethod"),
77
- &TestClass::TestClassInstanceVoidMethod),
78
- // Make sure to check that the deleter gets called.
79
- InstanceAccessor("instanceAccessor",
80
- &TestClass::TestClassInstanceGetter,
81
- &TestClass::TestClassInstanceSetter)
82
- });
50
+ return DefineClass(
51
+ env,
52
+ "TestClass",
53
+ {// Make sure to check that the deleter gets called.
54
+ StaticMethod("staticMethod", TestClassStaticMethod),
55
+ // Make sure to check that the deleter gets called.
56
+ StaticMethod("staticVoidMethod", TestClassStaticVoidMethod),
57
+ // Make sure to check that the deleter gets called.
58
+ StaticMethod(Napi::Symbol::New(env, "staticMethod"),
59
+ TestClassStaticMethod),
60
+ // Make sure to check that the deleter gets called.
61
+ StaticMethod(Napi::Symbol::New(env, "staticVoidMethod"),
62
+ TestClassStaticVoidMethod),
63
+ // Make sure to check that the deleter gets called.
64
+ InstanceMethod("instanceMethod", &TestClass::TestClassInstanceMethod),
65
+ // Make sure to check that the deleter gets called.
66
+ InstanceMethod("instanceVoidMethod",
67
+ &TestClass::TestClassInstanceVoidMethod),
68
+ // Make sure to check that the deleter gets called.
69
+ InstanceMethod(Napi::Symbol::New(env, "instanceMethod"),
70
+ &TestClass::TestClassInstanceMethod),
71
+ // Make sure to check that the deleter gets called.
72
+ InstanceMethod(Napi::Symbol::New(env, "instanceVoidMethod"),
73
+ &TestClass::TestClassInstanceVoidMethod),
74
+ // Make sure to check that the deleter gets called.
75
+ InstanceAccessor("instanceAccessor",
76
+ &TestClass::TestClassInstanceGetter,
77
+ &TestClass::TestClassInstanceSetter)});
83
78
  }
84
79
  };
85
80
 
@@ -91,42 +86,34 @@ static Napi::Value CreateTestObject(const Napi::CallbackInfo& info) {
91
86
  item["testMethod"] = Napi::Function::New(env, TestMethod, "testMethod");
92
87
 
93
88
  item.DefineProperties({
94
- // Make sure to check that the deleter gets called.
95
- Napi::PropertyDescriptor::Accessor(env,
96
- item,
97
- "accessor_1",
98
- TestGetter),
99
- // Make sure to check that the deleter gets called.
100
- Napi::PropertyDescriptor::Accessor(env,
101
- item,
102
- std::string("accessor_1_std_string"),
103
- TestGetter),
104
- // Make sure to check that the deleter gets called.
105
- Napi::PropertyDescriptor::Accessor(env,
106
- item,
107
- Napi::String::New(info.Env(),
108
- "accessor_1_js_string"),
109
- TestGetter),
110
- // Make sure to check that the deleter gets called.
111
- Napi::PropertyDescriptor::Accessor(env,
112
- item,
113
- "accessor_2",
114
- TestGetter,
115
- TestSetter),
116
- // Make sure to check that the deleter gets called.
117
- Napi::PropertyDescriptor::Accessor(env,
118
- item,
119
- std::string("accessor_2_std_string"),
120
- TestGetter,
121
- TestSetter),
122
- // Make sure to check that the deleter gets called.
123
- Napi::PropertyDescriptor::Accessor(env,
124
- item,
125
- Napi::String::New(env,
126
- "accessor_2_js_string"),
127
- TestGetter,
128
- TestSetter),
129
- Napi::PropertyDescriptor::Value("TestClass", TestClass::NewClass(env)),
89
+ // Make sure to check that the deleter gets called.
90
+ Napi::PropertyDescriptor::Accessor(env, item, "accessor_1", TestGetter),
91
+ // Make sure to check that the deleter gets called.
92
+ Napi::PropertyDescriptor::Accessor(
93
+ env, item, std::string("accessor_1_std_string"), TestGetter),
94
+ // Make sure to check that the deleter gets called.
95
+ Napi::PropertyDescriptor::Accessor(
96
+ env,
97
+ item,
98
+ Napi::String::New(info.Env(), "accessor_1_js_string"),
99
+ TestGetter),
100
+ // Make sure to check that the deleter gets called.
101
+ Napi::PropertyDescriptor::Accessor(
102
+ env, item, "accessor_2", TestGetter, TestSetter),
103
+ // Make sure to check that the deleter gets called.
104
+ Napi::PropertyDescriptor::Accessor(env,
105
+ item,
106
+ std::string("accessor_2_std_string"),
107
+ TestGetter,
108
+ TestSetter),
109
+ // Make sure to check that the deleter gets called.
110
+ Napi::PropertyDescriptor::Accessor(
111
+ env,
112
+ item,
113
+ Napi::String::New(env, "accessor_2_js_string"),
114
+ TestGetter,
115
+ TestSetter),
116
+ Napi::PropertyDescriptor::Value("TestClass", TestClass::NewClass(env)),
130
117
  });
131
118
 
132
119
  return item;
@@ -1,17 +1,16 @@
1
1
  // Flags: --expose-gc
2
2
  'use strict';
3
3
 
4
- const assert = require('assert');
5
-
6
4
  module.exports = require('./common').runTest(test);
7
5
 
8
- function test(binding) {
9
- console.log("Thunking: Performing initial GC");
6
+ function test (binding) {
7
+ console.log('Thunking: Performing initial GC');
10
8
  global.gc();
11
- console.log("Thunking: Creating test object");
9
+ console.log('Thunking: Creating test object');
12
10
  let object = binding.thunking_manual.createTestObject();
11
+ // eslint-disable-next-line no-unused-vars
13
12
  object = null;
14
- console.log("Thunking: About to GC\n--------");
13
+ console.log('Thunking: About to GC\n--------');
15
14
  global.gc();
16
- console.log("--------\nThunking: GC complete");
15
+ console.log('--------\nThunking: GC complete');
17
16
  }
@@ -40,23 +40,23 @@ static void TSFNCallJS(Env env,
40
40
  }
41
41
 
42
42
  using TSFN = TypedThreadSafeFunction<ThreadSafeFunctionInfo, int, TSFNCallJS>;
43
- static TSFN tsfn;
43
+ static TSFN s_tsfn;
44
44
 
45
45
  // Thread data to transmit to JS
46
46
  static int ints[ARRAY_LENGTH];
47
47
 
48
48
  static void SecondaryThread() {
49
- if (tsfn.Release() != napi_ok) {
49
+ if (s_tsfn.Release() != napi_ok) {
50
50
  Error::Fatal("TypedSecondaryThread", "ThreadSafeFunction.Release() failed");
51
51
  }
52
52
  }
53
53
 
54
54
  // Source thread producing the data
55
55
  static void DataSourceThread() {
56
- ThreadSafeFunctionInfo* info = tsfn.GetContext();
56
+ ThreadSafeFunctionInfo* info = s_tsfn.GetContext();
57
57
 
58
58
  if (info->startSecondary) {
59
- if (tsfn.Acquire() != napi_ok) {
59
+ if (s_tsfn.Acquire() != napi_ok) {
60
60
  Error::Fatal("TypedDataSourceThread",
61
61
  "ThreadSafeFunction.Acquire() failed");
62
62
  }
@@ -71,13 +71,13 @@ static void DataSourceThread() {
71
71
 
72
72
  switch (info->type) {
73
73
  case ThreadSafeFunctionInfo::DEFAULT:
74
- status = tsfn.BlockingCall();
74
+ status = s_tsfn.BlockingCall();
75
75
  break;
76
76
  case ThreadSafeFunctionInfo::BLOCKING:
77
- status = tsfn.BlockingCall(&ints[index]);
77
+ status = s_tsfn.BlockingCall(&ints[index]);
78
78
  break;
79
79
  case ThreadSafeFunctionInfo::NON_BLOCKING:
80
- status = tsfn.NonBlockingCall(&ints[index]);
80
+ status = s_tsfn.NonBlockingCall(&ints[index]);
81
81
  break;
82
82
  }
83
83
 
@@ -117,7 +117,7 @@ static void DataSourceThread() {
117
117
  Error::Fatal("TypedDataSourceThread", "Queue was never closing");
118
118
  }
119
119
 
120
- if (!queueWasClosing && tsfn.Release() != napi_ok) {
120
+ if (!queueWasClosing && s_tsfn.Release() != napi_ok) {
121
121
  Error::Fatal("TypedDataSourceThread",
122
122
  "ThreadSafeFunction.Release() failed");
123
123
  }
@@ -127,9 +127,9 @@ static Value StopThread(const CallbackInfo& info) {
127
127
  tsfnInfo.jsFinalizeCallback = Napi::Persistent(info[0].As<Function>());
128
128
  bool abort = info[1].As<Boolean>();
129
129
  if (abort) {
130
- tsfn.Abort();
130
+ s_tsfn.Abort();
131
131
  } else {
132
- tsfn.Release();
132
+ s_tsfn.Release();
133
133
  }
134
134
  {
135
135
  std::lock_guard<std::mutex> _(tsfnInfo.protect);
@@ -160,15 +160,15 @@ static Value StartThreadInternal(const CallbackInfo& info,
160
160
  tsfnInfo.maxQueueSize = info[3].As<Number>().Uint32Value();
161
161
  tsfnInfo.closeCalledFromJs = false;
162
162
 
163
- tsfn = TSFN::New(info.Env(),
164
- info[0].As<Function>(),
165
- Object::New(info.Env()),
166
- "Test",
167
- tsfnInfo.maxQueueSize,
168
- 2,
169
- &tsfnInfo,
170
- JoinTheThreads,
171
- threads);
163
+ s_tsfn = TSFN::New(info.Env(),
164
+ info[0].As<Function>(),
165
+ Object::New(info.Env()),
166
+ "Test",
167
+ tsfnInfo.maxQueueSize,
168
+ 2,
169
+ &tsfnInfo,
170
+ JoinTheThreads,
171
+ threads);
172
172
 
173
173
  threads[0] = std::thread(DataSourceThread);
174
174
 
@@ -176,7 +176,7 @@ static Value StartThreadInternal(const CallbackInfo& info,
176
176
  }
177
177
 
178
178
  static Value Release(const CallbackInfo& /* info */) {
179
- if (tsfn.Release() != napi_ok) {
179
+ if (s_tsfn.Release() != napi_ok) {
180
180
  Error::Fatal("Release", "TypedThreadSafeFunction.Release() failed");
181
181
  }
182
182
  return Value();
@@ -5,7 +5,7 @@ const common = require('../common');
5
5
 
6
6
  module.exports = common.runTest(test);
7
7
 
8
- async function test(binding) {
8
+ async function test (binding) {
9
9
  const expectedArray = (function (arrayLength) {
10
10
  const result = [];
11
11
  for (let index = 0; index < arrayLength; index++) {
@@ -14,15 +14,16 @@ async function test(binding) {
14
14
  return result;
15
15
  })(binding.typed_threadsafe_function.ARRAY_LENGTH);
16
16
 
17
- function testWithJSMarshaller({
17
+ function testWithJSMarshaller ({
18
18
  threadStarter,
19
19
  quitAfter,
20
20
  abort,
21
21
  maxQueueSize,
22
- launchSecondary }) {
22
+ launchSecondary
23
+ }) {
23
24
  return new Promise((resolve) => {
24
25
  const array = [];
25
- binding.typed_threadsafe_function[threadStarter](function testCallback(value) {
26
+ binding.typed_threadsafe_function[threadStarter](function testCallback (value) {
26
27
  array.push(value);
27
28
  if (array.length === quitAfter) {
28
29
  binding.typed_threadsafe_function.stopThread(common.mustCall(() => {
@@ -39,9 +40,9 @@ async function test(binding) {
39
40
  });
40
41
  }
41
42
 
42
- await new Promise(function testWithoutJSMarshaller(resolve) {
43
+ await new Promise(function testWithoutJSMarshaller (resolve) {
43
44
  let callCount = 0;
44
- binding.typed_threadsafe_function.startThreadNoNative(function testCallback() {
45
+ binding.typed_threadsafe_function.startThreadNoNative(function testCallback () {
45
46
  callCount++;
46
47
 
47
48
  // The default call-into-JS implementation passes no arguments.
@@ -54,7 +55,7 @@ async function test(binding) {
54
55
  });
55
56
  }
56
57
  }, false /* abort */, false /* launchSecondary */,
57
- binding.typed_threadsafe_function.MAX_QUEUE_SIZE);
58
+ binding.typed_threadsafe_function.MAX_QUEUE_SIZE);
58
59
  });
59
60
 
60
61
  // Start the thread in blocking mode, and assert that all values are passed.
@@ -65,7 +66,7 @@ async function test(binding) {
65
66
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
66
67
  quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH
67
68
  }),
68
- expectedArray,
69
+ expectedArray
69
70
  );
70
71
 
71
72
  // Start the thread in blocking mode with an infinite queue, and assert that
@@ -76,7 +77,7 @@ async function test(binding) {
76
77
  maxQueueSize: 0,
77
78
  quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH
78
79
  }),
79
- expectedArray,
80
+ expectedArray
80
81
  );
81
82
 
82
83
  // Start the thread in non-blocking mode, and assert that all values are
@@ -87,7 +88,7 @@ async function test(binding) {
87
88
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
88
89
  quitAfter: binding.typed_threadsafe_function.ARRAY_LENGTH
89
90
  }),
90
- expectedArray,
91
+ expectedArray
91
92
  );
92
93
 
93
94
  // Start the thread in blocking mode, and assert that all values are passed.
@@ -98,7 +99,7 @@ async function test(binding) {
98
99
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
99
100
  quitAfter: 1
100
101
  }),
101
- expectedArray,
102
+ expectedArray
102
103
  );
103
104
 
104
105
  // Start the thread in blocking mode with an infinite queue, and assert that
@@ -109,10 +110,9 @@ async function test(binding) {
109
110
  maxQueueSize: 0,
110
111
  quitAfter: 1
111
112
  }),
112
- expectedArray,
113
+ expectedArray
113
114
  );
114
115
 
115
-
116
116
  // Start the thread in non-blocking mode, and assert that all values are
117
117
  // passed. Quit early, but let the thread finish.
118
118
  assert.deepStrictEqual(
@@ -121,7 +121,7 @@ async function test(binding) {
121
121
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
122
122
  quitAfter: 1
123
123
  }),
124
- expectedArray,
124
+ expectedArray
125
125
  );
126
126
 
127
127
  // Start the thread in blocking mode, and assert that all values are passed.
@@ -134,7 +134,7 @@ async function test(binding) {
134
134
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
135
135
  launchSecondary: true
136
136
  }),
137
- expectedArray,
137
+ expectedArray
138
138
  );
139
139
 
140
140
  // Start the thread in non-blocking mode, and assert that all values are
@@ -147,7 +147,7 @@ async function test(binding) {
147
147
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
148
148
  launchSecondary: true
149
149
  }),
150
- expectedArray,
150
+ expectedArray
151
151
  );
152
152
 
153
153
  // Start the thread in blocking mode, and assert that it could not finish.
@@ -159,7 +159,7 @@ async function test(binding) {
159
159
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
160
160
  abort: true
161
161
  })).indexOf(0),
162
- -1,
162
+ -1
163
163
  );
164
164
 
165
165
  // Start the thread in blocking mode with an infinite queue, and assert that
@@ -171,7 +171,7 @@ async function test(binding) {
171
171
  maxQueueSize: 0,
172
172
  abort: true
173
173
  })).indexOf(0),
174
- -1,
174
+ -1
175
175
  );
176
176
 
177
177
  // Start the thread in non-blocking mode, and assert that it could not finish.
@@ -183,6 +183,6 @@ async function test(binding) {
183
183
  maxQueueSize: binding.typed_threadsafe_function.MAX_QUEUE_SIZE,
184
184
  abort: true
185
185
  })).indexOf(0),
186
- -1,
186
+ -1
187
187
  );
188
188
  }
@@ -1,3 +1,4 @@
1
+ #include <assert.h>
1
2
  #include "napi.h"
2
3
 
3
4
  #if (NAPI_VERSION > 3)
@@ -11,7 +12,7 @@ namespace {
11
12
 
12
13
  class TSFNWrap : public ObjectWrap<TSFNWrap> {
13
14
  public:
14
- static Object Init(Napi::Env env, Object exports);
15
+ static Function Init(Napi::Env env);
15
16
  TSFNWrap(const CallbackInfo& info);
16
17
 
17
18
  Napi::Value GetContext(const CallbackInfo& /*info*/) {
@@ -31,15 +32,14 @@ class TSFNWrap : public ObjectWrap<TSFNWrap> {
31
32
  std::unique_ptr<Promise::Deferred> _deferred;
32
33
  };
33
34
 
34
- Object TSFNWrap::Init(Napi::Env env, Object exports) {
35
+ Function TSFNWrap::Init(Napi::Env env) {
35
36
  Function func =
36
37
  DefineClass(env,
37
38
  "TSFNWrap",
38
39
  {InstanceMethod("getContext", &TSFNWrap::GetContext),
39
40
  InstanceMethod("release", &TSFNWrap::Release)});
40
41
 
41
- exports.Set("TSFNWrap", func);
42
- return exports;
42
+ return func;
43
43
  }
44
44
 
45
45
  TSFNWrap::TSFNWrap(const CallbackInfo& info) : ObjectWrap<TSFNWrap>(info) {
@@ -61,8 +61,60 @@ TSFNWrap::TSFNWrap(const CallbackInfo& info) : ObjectWrap<TSFNWrap>(info) {
61
61
 
62
62
  } // namespace
63
63
 
64
+ struct SimpleTestContext {
65
+ SimpleTestContext(int val) : _val(val) {}
66
+ int _val = -1;
67
+ };
68
+
69
+ // A simple test to check that the context has been set successfully
70
+ void AssertGetContextFromTSFNNoFinalizerIsCorrect(const CallbackInfo& info) {
71
+ // Test the overload where we provide a resource name but no finalizer
72
+ using TSFN = TypedThreadSafeFunction<SimpleTestContext>;
73
+ SimpleTestContext* ctx = new SimpleTestContext(42);
74
+ TSFN tsfn = TSFN::New(info.Env(), "testRes", 1, 1, ctx);
75
+
76
+ assert(tsfn.GetContext() == ctx);
77
+ delete ctx;
78
+ tsfn.Release();
79
+
80
+ // Test the other overload where we provide a async resource object, res name
81
+ // but no finalizer
82
+ ctx = new SimpleTestContext(52);
83
+ tsfn = TSFN::New(
84
+ info.Env(), Object::New(info.Env()), "testResourceObject", 1, 1, ctx);
85
+
86
+ assert(tsfn.GetContext() == ctx);
87
+ delete ctx;
88
+ tsfn.Release();
89
+
90
+ ctx = new SimpleTestContext(52);
91
+ tsfn = TSFN::New(info.Env(),
92
+ "resStrings",
93
+ 1,
94
+ 1,
95
+ ctx,
96
+ [](Napi::Env, void*, SimpleTestContext*) {});
97
+
98
+ assert(tsfn.GetContext() == ctx);
99
+ delete ctx;
100
+ tsfn.Release();
101
+
102
+ ctx = new SimpleTestContext(52);
103
+ Function emptyFunc;
104
+ tsfn = TSFN::New(info.Env(), emptyFunc, "resString", 1, 1, ctx);
105
+ assert(tsfn.GetContext() == ctx);
106
+ delete ctx;
107
+ tsfn.Release();
108
+ }
109
+
64
110
  Object InitTypedThreadSafeFunctionCtx(Env env) {
65
- return TSFNWrap::Init(env, Object::New(env));
111
+ Object exports = Object::New(env);
112
+ Function tsfnWrap = TSFNWrap::Init(env);
113
+
114
+ exports.Set("TSFNWrap", tsfnWrap);
115
+ exports.Set("AssertTSFNReturnCorrectCxt",
116
+ Function::New(env, AssertGetContextFromTSFNNoFinalizerIsCorrect));
117
+ return exports;
66
118
  }
67
119
 
68
120
  #endif
@@ -9,4 +9,6 @@ async function test (binding) {
9
9
  const tsfn = new binding.typed_threadsafe_function_ctx.TSFNWrap(ctx);
10
10
  assert(tsfn.getContext() === ctx);
11
11
  await tsfn.release();
12
+
13
+ binding.typed_threadsafe_function_ctx.AssertTSFNReturnCorrectCxt();
12
14
  }
@@ -4,11 +4,11 @@ const assert = require('assert');
4
4
 
5
5
  module.exports = require('../common').runTest(test);
6
6
 
7
- async function test(binding) {
7
+ async function test (binding) {
8
8
  const testCall = binding.typed_threadsafe_function_existing_tsfn.testCall;
9
9
 
10
- assert.strictEqual(typeof await testCall({ blocking: true, data: true }), "number");
11
- assert.strictEqual(typeof await testCall({ blocking: true, data: false }), "undefined");
12
- assert.strictEqual(typeof await testCall({ blocking: false, data: true }), "number");
13
- assert.strictEqual(typeof await testCall({ blocking: false, data: false }), "undefined");
10
+ assert.strictEqual(typeof await testCall({ blocking: true, data: true }), 'number');
11
+ assert.strictEqual(typeof await testCall({ blocking: true, data: false }), 'undefined');
12
+ assert.strictEqual(typeof await testCall({ blocking: false, data: true }), 'number');
13
+ assert.strictEqual(typeof await testCall({ blocking: false, data: false }), 'undefined');
14
14
  }
@@ -16,12 +16,16 @@ static Value Test(const CallbackInfo& info) {
16
16
  return info.Env().Undefined();
17
17
  }
18
18
 
19
+ static Value ExtractEnvNullValue(const CallbackInfo& info) {
20
+ return info.Env().Null();
21
+ }
22
+
19
23
  } // namespace
20
24
 
21
25
  Object InitTypedThreadSafeFunctionPtr(Env env) {
22
26
  Object exports = Object::New(env);
23
27
  exports["test"] = Function::New(env, Test);
24
-
28
+ exports["null"] = Function::New(env, ExtractEnvNullValue);
25
29
  return exports;
26
30
  }
27
31
 
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
-
2
+ const assert = require('assert');
3
3
  module.exports = require('../common').runTest(test);
4
4
 
5
- function test(binding) {
6
- binding.typed_threadsafe_function_ptr.test({}, () => {});
5
+ function test (binding) {
6
+ assert(binding.typed_threadsafe_function_ptr.test({}, () => {}) === undefined);
7
+ assert(binding.typed_threadsafe_function_ptr.null() === null);
7
8
  }
@@ -33,15 +33,15 @@ module.exports = require('../common').runTest(test);
33
33
  /** @param {number[]} N */
34
34
  const sum = (N) => N.reduce((sum, n) => sum + n, 0);
35
35
 
36
- function test(binding) {
37
- async function check(bindingFunction) {
36
+ function test (binding) {
37
+ async function check (bindingFunction) {
38
38
  const calls = [];
39
39
  const result = await bindingFunction(THREAD_COUNT, Array.prototype.push.bind(calls));
40
40
  assert.ok(result);
41
41
  assert.equal(sum(calls), EXPECTED_SUM);
42
42
  }
43
43
 
44
- async function checkAcquire() {
44
+ async function checkAcquire () {
45
45
  const calls = [];
46
46
  const { promise, createThread, stopThreads } = binding.typed_threadsafe_function_sum.testAcquire(Array.prototype.push.bind(calls));
47
47
  for (let i = 0; i < THREAD_COUNT; i++) {
@@ -32,6 +32,7 @@ static Value TestUnref(const CallbackInfo& info) {
32
32
  static_cast<FinalizerDataType*>(nullptr));
33
33
 
34
34
  tsfn->BlockingCall();
35
+ tsfn->Ref(info.Env());
35
36
 
36
37
  setTimeout.Call(
37
38
  global,
@@ -42,11 +43,24 @@ static Value TestUnref(const CallbackInfo& info) {
42
43
  return info.Env().Undefined();
43
44
  }
44
45
 
46
+ static Value TestRef(const CallbackInfo& info) {
47
+ Function cb = info[1].As<Function>();
48
+
49
+ auto tsfn = TSFN::New(info.Env(), cb, "testRes", 1, 1, nullptr);
50
+
51
+ tsfn.BlockingCall();
52
+ tsfn.Unref(info.Env());
53
+ tsfn.Ref(info.Env());
54
+
55
+ return info.Env().Undefined();
56
+ }
57
+
45
58
  } // namespace
46
59
 
47
60
  Object InitTypedThreadSafeFunctionUnref(Env env) {
48
61
  Object exports = Object::New(env);
49
62
  exports["testUnref"] = Function::New(env, TestUnref);
63
+ exports["testRef"] = Function::New(env, TestRef);
50
64
  return exports;
51
65
  }
52
66