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
@@ -7,7 +7,8 @@ Napi::Value StaticGetter(const Napi::CallbackInfo& /*info*/) {
7
7
  return MaybeUnwrap(testStaticContextRef.Value().Get("value"));
8
8
  }
9
9
 
10
- void StaticSetter(const Napi::CallbackInfo& /*info*/, const Napi::Value& value) {
10
+ void StaticSetter(const Napi::CallbackInfo& /*info*/,
11
+ const Napi::Value& value) {
11
12
  testStaticContextRef.Value().Set("value", value);
12
13
  }
13
14
 
@@ -22,11 +23,9 @@ Napi::Value TestStaticMethodInternal(const Napi::CallbackInfo& info) {
22
23
  }
23
24
 
24
25
  class Test : public Napi::ObjectWrap<Test> {
25
- public:
26
- Test(const Napi::CallbackInfo& info) :
27
- Napi::ObjectWrap<Test>(info) {
28
-
29
- if(info.Length() > 0) {
26
+ public:
27
+ Test(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Test>(info) {
28
+ if (info.Length() > 0) {
30
29
  finalizeCb_ = Napi::Persistent(info[0].As<Napi::Function>());
31
30
  }
32
31
  // Create an own instance property.
@@ -35,20 +34,19 @@ public:
35
34
  info.This().As<Napi::Object>(),
36
35
  "ownProperty",
37
36
  OwnPropertyGetter,
38
- napi_enumerable, this));
37
+ napi_enumerable,
38
+ this));
39
39
 
40
40
  // Create an own instance property with a templated function.
41
41
  info.This().As<Napi::Object>().DefineProperty(
42
- Napi::PropertyDescriptor::Accessor<OwnPropertyGetter>("ownPropertyT",
43
- napi_enumerable, this));
42
+ Napi::PropertyDescriptor::Accessor<OwnPropertyGetter>(
43
+ "ownPropertyT", napi_enumerable, this));
44
44
 
45
45
  bufref_ = Napi::Persistent(Napi::Buffer<uint8_t>::New(
46
46
  Env(),
47
47
  static_cast<uint8_t*>(malloc(1)),
48
48
  1,
49
- [](Napi::Env, uint8_t* bufaddr) {
50
- free(bufaddr);
51
- }));
49
+ [](Napi::Env, uint8_t* bufaddr) { free(bufaddr); }));
52
50
  }
53
51
 
54
52
  static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) {
@@ -88,16 +86,16 @@ public:
88
86
  .Call(array, {}));
89
87
  }
90
88
 
91
- void TestVoidMethodT(const Napi::CallbackInfo &info) {
89
+ void TestVoidMethodT(const Napi::CallbackInfo& info) {
92
90
  value_ = MaybeUnwrap(info[0].ToString());
93
91
  }
94
92
 
95
- Napi::Value TestMethodT(const Napi::CallbackInfo &info) {
96
- return Napi::String::New(info.Env(), value_);
93
+ Napi::Value TestMethodT(const Napi::CallbackInfo& info) {
94
+ return Napi::String::New(info.Env(), value_);
97
95
  }
98
96
 
99
97
  static Napi::Value TestStaticMethodT(const Napi::CallbackInfo& info) {
100
- return Napi::String::New(info.Env(), s_staticMethodText);
98
+ return Napi::String::New(info.Env(), s_staticMethodText);
101
99
  }
102
100
 
103
101
  static void TestStaticVoidMethodT(const Napi::CallbackInfo& info) {
@@ -105,20 +103,31 @@ public:
105
103
  }
106
104
 
107
105
  static void Initialize(Napi::Env env, Napi::Object exports) {
108
-
109
- Napi::Symbol kTestStaticValueInternal = Napi::Symbol::New(env, "kTestStaticValueInternal");
110
- Napi::Symbol kTestStaticAccessorInternal = Napi::Symbol::New(env, "kTestStaticAccessorInternal");
111
- Napi::Symbol kTestStaticAccessorTInternal = Napi::Symbol::New(env, "kTestStaticAccessorTInternal");
112
- Napi::Symbol kTestStaticMethodInternal = Napi::Symbol::New(env, "kTestStaticMethodInternal");
113
- Napi::Symbol kTestStaticMethodTInternal = Napi::Symbol::New(env, "kTestStaticMethodTInternal");
114
- Napi::Symbol kTestStaticVoidMethodTInternal = Napi::Symbol::New(env, "kTestStaticVoidMethodTInternal");
115
-
116
- Napi::Symbol kTestValueInternal = Napi::Symbol::New(env, "kTestValueInternal");
117
- Napi::Symbol kTestAccessorInternal = Napi::Symbol::New(env, "kTestAccessorInternal");
118
- Napi::Symbol kTestAccessorTInternal = Napi::Symbol::New(env, "kTestAccessorTInternal");
119
- Napi::Symbol kTestMethodInternal = Napi::Symbol::New(env, "kTestMethodInternal");
120
- Napi::Symbol kTestMethodTInternal = Napi::Symbol::New(env, "kTestMethodTInternal");
121
- Napi::Symbol kTestVoidMethodTInternal = Napi::Symbol::New(env, "kTestVoidMethodTInternal");
106
+ Napi::Symbol kTestStaticValueInternal =
107
+ Napi::Symbol::New(env, "kTestStaticValueInternal");
108
+ Napi::Symbol kTestStaticAccessorInternal =
109
+ Napi::Symbol::New(env, "kTestStaticAccessorInternal");
110
+ Napi::Symbol kTestStaticAccessorTInternal =
111
+ Napi::Symbol::New(env, "kTestStaticAccessorTInternal");
112
+ Napi::Symbol kTestStaticMethodInternal =
113
+ Napi::Symbol::New(env, "kTestStaticMethodInternal");
114
+ Napi::Symbol kTestStaticMethodTInternal =
115
+ Napi::Symbol::New(env, "kTestStaticMethodTInternal");
116
+ Napi::Symbol kTestStaticVoidMethodTInternal =
117
+ Napi::Symbol::New(env, "kTestStaticVoidMethodTInternal");
118
+
119
+ Napi::Symbol kTestValueInternal =
120
+ Napi::Symbol::New(env, "kTestValueInternal");
121
+ Napi::Symbol kTestAccessorInternal =
122
+ Napi::Symbol::New(env, "kTestAccessorInternal");
123
+ Napi::Symbol kTestAccessorTInternal =
124
+ Napi::Symbol::New(env, "kTestAccessorTInternal");
125
+ Napi::Symbol kTestMethodInternal =
126
+ Napi::Symbol::New(env, "kTestMethodInternal");
127
+ Napi::Symbol kTestMethodTInternal =
128
+ Napi::Symbol::New(env, "kTestMethodTInternal");
129
+ Napi::Symbol kTestVoidMethodTInternal =
130
+ Napi::Symbol::New(env, "kTestVoidMethodTInternal");
122
131
 
123
132
  exports.Set(
124
133
  "Test",
@@ -237,17 +246,15 @@ public:
237
246
  }
238
247
 
239
248
  void Finalize(Napi::Env env) {
240
-
241
- if(finalizeCb_.IsEmpty()) {
249
+ if (finalizeCb_.IsEmpty()) {
242
250
  return;
243
251
  }
244
252
 
245
253
  finalizeCb_.Call(env.Global(), {Napi::Boolean::New(env, true)});
246
254
  finalizeCb_.Unref();
247
-
248
255
  }
249
256
 
250
- private:
257
+ private:
251
258
  std::string value_;
252
259
  Napi::FunctionReference finalizeCb_;
253
260
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-lone-blocks */
1
2
  'use strict';
2
3
 
3
4
  const assert = require('assert');
@@ -5,7 +6,7 @@ const testUtil = require('./testUtil');
5
6
 
6
7
  module.exports = require('./common').runTest(test);
7
8
 
8
- async function test(binding) {
9
+ async function test (binding) {
9
10
  const Test = binding.objectwrap.Test;
10
11
 
11
12
  const testValue = (obj, clazz) => {
@@ -28,6 +29,7 @@ async function test(binding) {
28
29
  // read write-only
29
30
  {
30
31
  let error;
32
+ // eslint-disable-next-line no-unused-vars
31
33
  try { const read = obj.testSetter; } catch (e) { error = e; }
32
34
  // no error
33
35
  assert.strictEqual(error, undefined);
@@ -107,19 +109,19 @@ async function test(binding) {
107
109
  // for..in: object and prototype
108
110
  {
109
111
  const keys = [];
110
- for (let key in obj) {
112
+ for (const key in obj) {
111
113
  keys.push(key);
112
114
  }
113
115
 
114
- assert(keys.length == 6);
116
+ assert(keys.length === 6);
115
117
  // on prototype
116
- assert(keys.includes("testGetSet"));
117
- assert(keys.includes("testGetter"));
118
- assert(keys.includes("testValue"));
119
- assert(keys.includes("testMethod"));
118
+ assert(keys.includes('testGetSet'));
119
+ assert(keys.includes('testGetter'));
120
+ assert(keys.includes('testValue'));
121
+ assert(keys.includes('testMethod'));
120
122
  // on object only
121
- assert(keys.includes("ownProperty"));
122
- assert(keys.includes("ownPropertyT"));
123
+ assert(keys.includes('ownProperty'));
124
+ assert(keys.includes('ownPropertyT'));
123
125
  }
124
126
  };
125
127
 
@@ -135,7 +137,7 @@ async function test(binding) {
135
137
  obj.testSetter = 'iterator';
136
138
  const values = [];
137
139
 
138
- for (let item of obj) {
140
+ for (const item of obj) {
139
141
  values.push(item);
140
142
  }
141
143
 
@@ -146,7 +148,7 @@ async function test(binding) {
146
148
  const testStaticValue = (clazz) => {
147
149
  assert.strictEqual(clazz.testStaticValue, 'value');
148
150
  assert.strictEqual(clazz[clazz.kTestStaticValueInternal], 5);
149
- }
151
+ };
150
152
 
151
153
  const testStaticAccessor = (clazz) => {
152
154
  // read-only, write-only
@@ -165,6 +167,7 @@ async function test(binding) {
165
167
  // read write-only
166
168
  {
167
169
  let error;
170
+ // eslint-disable-next-line no-unused-vars
168
171
  try { const read = clazz.testStaticSetter; } catch (e) { error = e; }
169
172
  // no error
170
173
  assert.strictEqual(error, undefined);
@@ -227,7 +230,7 @@ async function test(binding) {
227
230
  // for..in
228
231
  {
229
232
  const keys = [];
230
- for (let key in clazz) {
233
+ for (const key in clazz) {
231
234
  keys.push(key);
232
235
  }
233
236
 
@@ -240,21 +243,22 @@ async function test(binding) {
240
243
  }
241
244
  };
242
245
 
243
- async function testFinalize(clazz) {
246
+ async function testFinalize (clazz) {
244
247
  let finalizeCalled = false;
245
248
  await testUtil.runGCTests([
246
249
  'test finalize',
247
250
  () => {
248
- const finalizeCb = function(called) {
251
+ const finalizeCb = function (called) {
249
252
  finalizeCalled = called;
250
253
  };
251
254
 
252
- //Scope Test instance so that it can be gc'd.
255
+ // Scope Test instance so that it can be gc'd.
256
+ // eslint-disable-next-line no-new
253
257
  (() => { new Test(finalizeCb); })();
254
258
  },
255
259
  () => assert.strictEqual(finalizeCalled, true)
256
260
  ]);
257
- };
261
+ }
258
262
 
259
263
  const testObj = (obj, clazz) => {
260
264
  testValue(obj, clazz);
@@ -264,16 +268,16 @@ async function test(binding) {
264
268
  testEnumerables(obj, clazz);
265
269
 
266
270
  testConventions(obj, clazz);
267
- }
271
+ };
268
272
 
269
- async function testClass(clazz) {
273
+ async function testClass (clazz) {
270
274
  testStaticValue(clazz);
271
275
  testStaticAccessor(clazz);
272
276
  testStaticMethod(clazz);
273
277
 
274
278
  testStaticEnumerables(clazz);
275
279
  await testFinalize(clazz);
276
- };
280
+ }
277
281
 
278
282
  // `Test` is needed for accessing exposed symbols
279
283
  testObj(new Test(), Test);
@@ -1,10 +1,10 @@
1
1
  #include <napi.h>
2
2
 
3
- class ConstructorExceptionTest :
4
- public Napi::ObjectWrap<ConstructorExceptionTest> {
5
- public:
6
- ConstructorExceptionTest(const Napi::CallbackInfo& info) :
7
- Napi::ObjectWrap<ConstructorExceptionTest>(info) {
3
+ class ConstructorExceptionTest
4
+ : public Napi::ObjectWrap<ConstructorExceptionTest> {
5
+ public:
6
+ ConstructorExceptionTest(const Napi::CallbackInfo& info)
7
+ : Napi::ObjectWrap<ConstructorExceptionTest>(info) {
8
8
  Napi::Error error = Napi::Error::New(info.Env(), "an exception");
9
9
  #ifdef NAPI_DISABLE_CPP_EXCEPTIONS
10
10
  error.ThrowAsJavaScriptException();
@@ -3,7 +3,7 @@
3
3
  const assert = require('assert');
4
4
  const testUtil = require('./testUtil');
5
5
 
6
- function test(binding) {
6
+ function test (binding) {
7
7
  return testUtil.runGCTests([
8
8
  'objectwrap constructor exception',
9
9
  () => {
@@ -1,25 +1,25 @@
1
1
  #include <napi.h>
2
2
 
3
3
  class TestMIBase {
4
- public:
4
+ public:
5
5
  TestMIBase() : test(0) {}
6
6
  virtual void dummy() {}
7
7
  uint32_t test;
8
8
  };
9
9
 
10
10
  class TestMI : public TestMIBase, public Napi::ObjectWrap<TestMI> {
11
- public:
12
- TestMI(const Napi::CallbackInfo& info) :
13
- Napi::ObjectWrap<TestMI>(info) {}
11
+ public:
12
+ TestMI(const Napi::CallbackInfo& info) : Napi::ObjectWrap<TestMI>(info) {}
14
13
 
15
14
  Napi::Value GetTest(const Napi::CallbackInfo& info) {
16
15
  return Napi::Number::New(info.Env(), test);
17
16
  }
18
17
 
19
18
  static void Initialize(Napi::Env env, Napi::Object exports) {
20
- exports.Set("TestMI", DefineClass(env, "TestMI", {
21
- InstanceAccessor<&TestMI::GetTest>("test")
22
- }));
19
+ exports.Set(
20
+ "TestMI",
21
+ DefineClass(
22
+ env, "TestMI", {InstanceAccessor<&TestMI::GetTest>("test")}));
23
23
  }
24
24
  };
25
25
 
@@ -8,6 +8,6 @@ const test = bindingName => {
8
8
  const testmi = new TestMI();
9
9
 
10
10
  assert.strictEqual(testmi.test, 0);
11
- }
11
+ };
12
12
 
13
13
  module.exports = require('./common').runTestWithBindingPath(test);
@@ -2,39 +2,31 @@
2
2
 
3
3
  if (process.argv[2] === 'child') {
4
4
  // Create a single wrapped instance then exit.
5
- return new (require(process.argv[3]).objectwrap.Test)();
6
- }
7
-
8
- const assert = require('assert');
9
- const { spawnSync } = require('child_process');
10
- const testUtil = require('./testUtil');
11
-
12
- module.exports = require('./common').runTestWithBindingPath(test);
5
+ // eslint-disable-next-line no-new
6
+ new (require(process.argv[3]).objectwrap.Test)();
7
+ } else {
8
+ const assert = require('assert');
9
+ const testUtil = require('./testUtil');
13
10
 
14
- function test(bindingName) {
15
- return testUtil.runGCTests([
16
- 'objectwrap removewrap test',
17
- () => {
18
- const binding = require(bindingName);
19
- const Test = binding.objectwrap_removewrap.Test;
20
- const getDtorCalled = binding.objectwrap_removewrap.getDtorCalled;
11
+ module.exports = require('./common').runTestWithBindingPath(test);
21
12
 
22
- assert.strictEqual(getDtorCalled(), 0);
23
- assert.throws(() => {
24
- new Test();
25
- });
26
- assert.strictEqual(getDtorCalled(), 1);
27
- },
28
- // Test that gc does not crash.
29
- () => {}
30
- ]);
13
+ function test (bindingName) {
14
+ return testUtil.runGCTests([
15
+ 'objectwrap removewrap test',
16
+ () => {
17
+ const binding = require(bindingName);
18
+ const Test = binding.objectwrap_removewrap.Test;
19
+ const getDtorCalled = binding.objectwrap_removewrap.getDtorCalled;
31
20
 
32
- // Start a child process that creates a single wrapped instance to ensure that
33
- // it is properly freed at its exit. It must not segfault.
34
- // Re: https://github.com/nodejs/node-addon-api/issues/660
35
- const child = spawnSync(process.execPath, [
36
- __filename, 'child', bindingName
37
- ]);
38
- assert.strictEqual(child.signal, null);
39
- assert.strictEqual(child.status, 0);
21
+ assert.strictEqual(getDtorCalled(), 0);
22
+ assert.throws(() => {
23
+ // eslint-disable-next-line no-new
24
+ new Test();
25
+ });
26
+ assert.strictEqual(getDtorCalled(), 1);
27
+ },
28
+ // Test that gc does not crash.
29
+ () => {}
30
+ ]);
31
+ }
40
32
  }
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
  const path = require('path');
3
- const { Worker, isMainThread, workerData } = require('worker_threads');
3
+ const { Worker, isMainThread } = require('worker_threads');
4
+ const { runTestWithBuildType, whichBuildType } = require('./common');
4
5
 
5
- module.exports = require('./common').runTestWithBuildType(test);
6
+ module.exports = runTestWithBuildType(test);
6
7
 
7
- async function test(buildType) {
8
+ async function test () {
8
9
  if (isMainThread) {
9
- const buildType = process.config.target_defaults.default_configuration;
10
+ const buildType = await whichBuildType();
10
11
  const worker = new Worker(__filename, { workerData: buildType });
11
12
  return new Promise((resolve, reject) => {
12
13
  worker.on('exit', () => {
@@ -18,12 +18,19 @@ Value RejectPromise(const CallbackInfo& info) {
18
18
  return deferred.Promise();
19
19
  }
20
20
 
21
+ Value PromiseReturnsCorrectEnv(const CallbackInfo& info) {
22
+ auto deferred = Promise::Deferred::New(info.Env());
23
+ return Boolean::New(info.Env(), deferred.Env() == info.Env());
24
+ }
25
+
21
26
  Object InitPromise(Env env) {
22
27
  Object exports = Object::New(env);
23
28
 
24
29
  exports["isPromise"] = Function::New(env, IsPromise);
25
30
  exports["resolvePromise"] = Function::New(env, ResolvePromise);
26
31
  exports["rejectPromise"] = Function::New(env, RejectPromise);
32
+ exports["promiseReturnsCorrectEnv"] =
33
+ Function::New(env, PromiseReturnsCorrectEnv);
27
34
 
28
35
  return exports;
29
36
  }
@@ -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
  assert.strictEqual(binding.promise.isPromise({}), false);
10
10
 
11
11
  const resolving = binding.promise.resolvePromise('resolved');
@@ -15,4 +15,6 @@ async function test(binding) {
15
15
  const rejecting = binding.promise.rejectPromise('error');
16
16
  await assert.strictEqual(binding.promise.isPromise(rejecting), true);
17
17
  rejecting.then(common.mustNotCall()).catch(common.mustCall());
18
+
19
+ assert(binding.promise.promiseReturnsCorrectEnv());
18
20
  }
@@ -4,7 +4,7 @@ using namespace Napi;
4
4
 
5
5
  static Reference<Buffer<uint8_t>> weak;
6
6
 
7
- void CreateWeakArray(const CallbackInfo& info) {
7
+ void CreateWeakArray(const CallbackInfo& info) {
8
8
  weak = Weak(Buffer<uint8_t>::New(info.Env(), 1));
9
9
  weak.SuppressDestruct();
10
10
  }
@@ -5,10 +5,10 @@ const testUtil = require('./testUtil');
5
5
 
6
6
  module.exports = require('./common').runTest(test);
7
7
 
8
- function test(binding) {
8
+ function test (binding) {
9
9
  return testUtil.runGCTests([
10
10
  'test reference',
11
11
  () => binding.reference.createWeakArray(),
12
12
  () => assert.strictEqual(true, binding.reference.accessWeakArrayEmpty())
13
13
  ]);
14
- };
14
+ }
@@ -42,7 +42,7 @@ Value RunWithContext(const CallbackInfo& info) {
42
42
  return MaybeUnwrap(fn.Call(args));
43
43
  }
44
44
 
45
- } // end anonymous namespace
45
+ } // end anonymous namespace
46
46
 
47
47
  Object InitRunScript(Env env) {
48
48
  Object exports = Object::New(env);
@@ -1,73 +1,66 @@
1
1
  'use strict';
2
2
 
3
- const buildType = process.config.target_defaults.default_configuration;
4
3
  const assert = require('assert');
5
4
 
6
5
  module.exports = require('./common').runTest(test);
7
6
 
8
-
9
- function test(binding)
10
- {
11
- const majorNodeVersion = process.versions.node.split('.')[0];
12
-
13
- let wellKnownSymbolFunctions = ['asyncIterator','hasInstance','isConcatSpreadable', 'iterator','match','replace','search','split','species','toPrimitive','toStringTag','unscopables'];
14
- if (majorNodeVersion >= 12) {
15
- wellKnownSymbolFunctions.push('matchAll');
16
- }
17
-
18
- function assertCanCreateSymbol(symbol)
19
- {
20
- assert(binding.symbol.createNewSymbolWithCppStr(symbol) !== null);
21
- assert(binding.symbol.createNewSymbolWithCStr(symbol) !== null);
22
- assert(binding.symbol.createNewSymbolWithNapi(symbol) !== null);
23
- }
24
-
25
- function assertSymbolAreUnique(symbol)
26
- {
27
- const symbolOne = binding.symbol.createNewSymbolWithCppStr(symbol);
28
- const symbolTwo = binding.symbol.createNewSymbolWithCppStr(symbol);
29
-
30
- assert(symbolOne !== symbolTwo);
31
- }
32
-
33
- function assertSymbolIsWellknown(symbol)
34
- {
35
- const symbOne = binding.symbol.getWellKnownSymbol(symbol);
36
- const symbTwo = binding.symbol.getWellKnownSymbol(symbol);
37
- assert(symbOne && symbTwo);
38
- assert(symbOne === symbTwo);
39
- }
40
-
41
- function assertSymbolIsNotWellknown(symbol)
42
- {
43
- const symbolTest = binding.symbol.getWellKnownSymbol(symbol);
44
- assert(symbolTest === undefined);
45
- }
46
-
47
- function assertCanCreateOrFetchGlobalSymbols(symbol, fetchFunction)
48
- {
49
- const symbOne = fetchFunction(symbol);
50
- const symbTwo = fetchFunction(symbol);
51
- assert(symbOne && symbTwo);
52
- assert(symbOne === symbTwo);
53
- }
54
-
55
- assertCanCreateSymbol("testing");
56
- assertSymbolAreUnique("symbol");
57
- assertSymbolIsNotWellknown("testing");
58
-
59
- for(const wellknownProperty of wellKnownSymbolFunctions)
60
- {
61
- assertSymbolIsWellknown(wellknownProperty);
62
- }
63
-
64
- assertCanCreateOrFetchGlobalSymbols("data", binding.symbol.getSymbolFromGlobalRegistry);
65
- assertCanCreateOrFetchGlobalSymbols("CppKey", binding.symbol.getSymbolFromGlobalRegistryWithCppKey);
66
- assertCanCreateOrFetchGlobalSymbols("CKey", binding.symbol.getSymbolFromGlobalRegistryWithCKey);
67
-
68
- assert(binding.symbol.createNewSymbolWithNoArgs() === undefined);
69
-
70
- assert(binding.symbol.testNullSymbolCanBeCreated() === binding.symbol.testNullSymbolCanBeCreated());
71
- assert(binding.symbol.testUndefinedSymbolCanBeCreated() === binding.symbol.testUndefinedSymbolCanBeCreated());
72
- assert(binding.symbol.testUndefinedSymbolCanBeCreated() !== binding.symbol.testNullSymbolCanBeCreated());
7
+ function test (binding) {
8
+ const majorNodeVersion = process.versions.node.split('.')[0];
9
+
10
+ const wellKnownSymbolFunctions = ['asyncIterator', 'hasInstance', 'isConcatSpreadable', 'iterator', 'match', 'replace', 'search', 'split', 'species', 'toPrimitive', 'toStringTag', 'unscopables'];
11
+ if (majorNodeVersion >= 12) {
12
+ wellKnownSymbolFunctions.push('matchAll');
13
+ }
14
+
15
+ function assertCanCreateSymbol (symbol) {
16
+ assert(binding.symbol.createNewSymbolWithCppStr(symbol) !== null);
17
+ assert(binding.symbol.createNewSymbolWithCStr(symbol) !== null);
18
+ assert(binding.symbol.createNewSymbolWithNapi(symbol) !== null);
19
+ }
20
+
21
+ function assertSymbolAreUnique (symbol) {
22
+ const symbolOne = binding.symbol.createNewSymbolWithCppStr(symbol);
23
+ const symbolTwo = binding.symbol.createNewSymbolWithCppStr(symbol);
24
+
25
+ assert(symbolOne !== symbolTwo);
26
+ }
27
+
28
+ function assertSymbolIsWellknown (symbol) {
29
+ const symbOne = binding.symbol.getWellKnownSymbol(symbol);
30
+ const symbTwo = binding.symbol.getWellKnownSymbol(symbol);
31
+ assert(symbOne && symbTwo);
32
+ assert(symbOne === symbTwo);
33
+ }
34
+
35
+ function assertSymbolIsNotWellknown (symbol) {
36
+ const symbolTest = binding.symbol.getWellKnownSymbol(symbol);
37
+ assert(symbolTest === undefined);
38
+ }
39
+
40
+ function assertCanCreateOrFetchGlobalSymbols (symbol, fetchFunction) {
41
+ const symbOne = fetchFunction(symbol);
42
+ const symbTwo = fetchFunction(symbol);
43
+ assert(symbOne && symbTwo);
44
+ assert(symbOne === symbTwo);
45
+ }
46
+
47
+ assertCanCreateSymbol('testing');
48
+ assertSymbolAreUnique('symbol');
49
+ assertSymbolIsNotWellknown('testing');
50
+
51
+ for (const wellknownProperty of wellKnownSymbolFunctions) {
52
+ assertSymbolIsWellknown(wellknownProperty);
53
+ }
54
+
55
+ assertCanCreateOrFetchGlobalSymbols('data', binding.symbol.getSymbolFromGlobalRegistry);
56
+ assertCanCreateOrFetchGlobalSymbols('CppKey', binding.symbol.getSymbolFromGlobalRegistryWithCppKey);
57
+ assertCanCreateOrFetchGlobalSymbols('CKey', binding.symbol.getSymbolFromGlobalRegistryWithCKey);
58
+
59
+ assert(binding.symbol.createNewSymbolWithNoArgs() === undefined);
60
+
61
+ // eslint-disable-next-line no-self-compare
62
+ assert(binding.symbol.testNullSymbolCanBeCreated() === binding.symbol.testNullSymbolCanBeCreated());
63
+ // eslint-disable-next-line no-self-compare
64
+ assert(binding.symbol.testUndefinedSymbolCanBeCreated() === binding.symbol.testUndefinedSymbolCanBeCreated());
65
+ assert(binding.symbol.testUndefinedSymbolCanBeCreated() !== binding.symbol.testNullSymbolCanBeCreated());
73
66
  }