koffi 2.12.0 → 2.12.2

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 (188) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.txt +2 -2
  3. package/README.md +8 -8
  4. package/build/koffi/darwin_arm64/koffi.node +0 -0
  5. package/build/koffi/darwin_x64/koffi.node +0 -0
  6. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  7. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  8. package/build/koffi/freebsd_x64/koffi.node +0 -0
  9. package/build/koffi/linux_arm64/koffi.node +0 -0
  10. package/build/koffi/linux_armhf/koffi.node +0 -0
  11. package/build/koffi/linux_ia32/koffi.node +0 -0
  12. package/build/koffi/linux_loong64/koffi.node +0 -0
  13. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  14. package/build/koffi/linux_x64/koffi.node +0 -0
  15. package/build/koffi/musl_arm64/koffi.node +0 -0
  16. package/build/koffi/musl_x64/koffi.node +0 -0
  17. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  18. package/build/koffi/openbsd_x64/koffi.node +0 -0
  19. package/build/koffi/win32_arm64/koffi.exp +0 -0
  20. package/build/koffi/win32_arm64/koffi.node +0 -0
  21. package/build/koffi/win32_ia32/koffi.exp +0 -0
  22. package/build/koffi/win32_ia32/koffi.node +0 -0
  23. package/build/koffi/win32_x64/koffi.exp +0 -0
  24. package/build/koffi/win32_x64/koffi.node +0 -0
  25. package/doc/assets.ini +3 -3
  26. package/doc/develop.sh +4 -3
  27. package/doc/pages/platforms.md +1 -1
  28. package/doc/static/highlight.js +1 -1
  29. package/doc/static/koffi.css +3 -2
  30. package/doc/static/print.css +1 -1
  31. package/doc/templates/code.html +5 -5
  32. package/doc/templates/page.html +4 -4
  33. package/index.d.ts +2 -2
  34. package/index.js +25 -25
  35. package/indirect.js +25 -5
  36. package/package.json +2 -2
  37. package/src/cnoke/LICENSE.txt +2 -2
  38. package/src/cnoke/README.md +2 -0
  39. package/src/cnoke/assets/FindCNoke.cmake +12 -2
  40. package/src/cnoke/assets/win_delay_hook.c +4 -4
  41. package/src/cnoke/cnoke.js +4 -2
  42. package/src/cnoke/package.json +1 -1
  43. package/src/cnoke/src/builder.js +11 -14
  44. package/src/cnoke/src/index.js +2 -2
  45. package/src/cnoke/src/tools.js +34 -2
  46. package/src/core/{libcc/libcc.cc → base/base.cc} +3092 -1674
  47. package/src/core/{libcc/libcc.hh → base/base.hh} +3059 -2432
  48. package/src/core/{libcc → base}/mimetypes.inc +42 -4
  49. package/src/core/{libcc → base}/mimetypes_gen.py +3 -3
  50. package/src/core/unicode/generate.py +124 -0
  51. package/src/core/unicode/xid.cc +52 -0
  52. package/src/core/unicode/xid.hh +29 -0
  53. package/src/core/unicode/xid.inc +465 -0
  54. package/src/koffi/CMakeLists.txt +8 -5
  55. package/src/koffi/cmake/raylib.cmake +6 -2
  56. package/src/koffi/cmake/{sqlite.cmake → sqlite3.cmake} +3 -3
  57. package/src/koffi/examples/electron-forge/forge.config.js +23 -3
  58. package/src/koffi/examples/electron-forge/package.json +18 -16
  59. package/src/koffi/src/abi_arm32.cc +8 -21
  60. package/src/koffi/src/abi_arm32_asm.S +2 -2
  61. package/src/koffi/src/abi_arm64.cc +46 -59
  62. package/src/koffi/src/abi_arm64_asm.S +4 -4
  63. package/src/koffi/src/abi_arm64_asm.asm +2 -2
  64. package/src/koffi/src/abi_loong64_asm.S +2 -2
  65. package/src/koffi/src/abi_riscv64.cc +6 -19
  66. package/src/koffi/src/abi_riscv64_asm.S +2 -2
  67. package/src/koffi/src/abi_x64_sysv.cc +4 -17
  68. package/src/koffi/src/abi_x64_sysv_asm.S +5 -5
  69. package/src/koffi/src/abi_x64_win.cc +4 -17
  70. package/src/koffi/src/abi_x64_win_asm.asm +2 -2
  71. package/src/koffi/src/abi_x86.cc +9 -22
  72. package/src/koffi/src/abi_x86_asm.S +2 -2
  73. package/src/koffi/src/abi_x86_asm.asm +2 -2
  74. package/src/koffi/src/call.cc +49 -42
  75. package/src/koffi/src/call.hh +9 -8
  76. package/src/koffi/src/errno.inc +152 -152
  77. package/src/koffi/src/ffi.cc +45 -39
  78. package/src/koffi/src/ffi.hh +6 -6
  79. package/src/koffi/src/init.js +1 -1
  80. package/src/koffi/src/parser.cc +6 -5
  81. package/src/koffi/src/parser.hh +3 -3
  82. package/src/koffi/src/trampolines/armasm.inc +2 -2
  83. package/src/koffi/src/trampolines/gnu.inc +2 -2
  84. package/src/koffi/src/trampolines/masm32.inc +2 -2
  85. package/src/koffi/src/trampolines/masm64.inc +2 -2
  86. package/src/koffi/src/trampolines/prototypes.inc +2 -2
  87. package/src/koffi/src/util.cc +9 -9
  88. package/src/koffi/src/util.hh +3 -3
  89. package/src/koffi/src/win32.cc +5 -5
  90. package/src/koffi/src/win32.hh +9 -9
  91. package/vendor/node-addon-api/CHANGELOG.md +97 -2
  92. package/vendor/node-addon-api/CONTRIBUTING.md +117 -7
  93. package/vendor/node-addon-api/README.md +25 -249
  94. package/vendor/node-addon-api/common.gypi +1 -0
  95. package/vendor/node-addon-api/doc/README.md +145 -0
  96. package/vendor/node-addon-api/doc/array_buffer.md +15 -15
  97. package/vendor/node-addon-api/doc/basic_env.md +200 -0
  98. package/vendor/node-addon-api/doc/buffer.md +24 -26
  99. package/vendor/node-addon-api/doc/cmake-js.md +19 -0
  100. package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md} +16 -4
  101. package/vendor/node-addon-api/doc/env.md +11 -131
  102. package/vendor/node-addon-api/doc/error_handling.md +12 -0
  103. package/vendor/node-addon-api/doc/external.md +13 -4
  104. package/vendor/node-addon-api/doc/finalization.md +153 -0
  105. package/vendor/node-addon-api/doc/memory_management.md +1 -1
  106. package/vendor/node-addon-api/doc/object_wrap.md +19 -3
  107. package/vendor/node-addon-api/doc/promises.md +51 -0
  108. package/vendor/node-addon-api/doc/setup.md +29 -6
  109. package/vendor/node-addon-api/doc/value.md +13 -0
  110. package/vendor/node-addon-api/doc/version_management.md +2 -2
  111. package/vendor/node-addon-api/eslint.config.js +5 -0
  112. package/vendor/node-addon-api/index.js +2 -0
  113. package/vendor/node-addon-api/napi-inl.h +592 -166
  114. package/vendor/node-addon-api/napi.h +167 -59
  115. package/vendor/node-addon-api/node_addon_api.gyp +10 -0
  116. package/vendor/node-addon-api/noexcept.gypi +1 -1
  117. package/vendor/node-addon-api/package.json +10 -13
  118. package/vendor/node-addon-api/release-please-config.json +15 -0
  119. package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +2 -1
  120. package/vendor/node-addon-api/test/array_buffer.js +1 -1
  121. package/vendor/node-addon-api/test/async_context.js +2 -2
  122. package/vendor/node-addon-api/test/async_progress_queue_worker.js +3 -3
  123. package/vendor/node-addon-api/test/async_progress_worker.js +3 -3
  124. package/vendor/node-addon-api/test/async_worker.cc +15 -13
  125. package/vendor/node-addon-api/test/async_worker.js +5 -5
  126. package/vendor/node-addon-api/test/basic_types/value.cc +6 -0
  127. package/vendor/node-addon-api/test/basic_types/value.js +17 -0
  128. package/vendor/node-addon-api/test/binding.cc +8 -0
  129. package/vendor/node-addon-api/test/binding.gyp +23 -1
  130. package/vendor/node-addon-api/test/buffer.js +1 -2
  131. package/vendor/node-addon-api/test/common/index.js +1 -1
  132. package/vendor/node-addon-api/test/except_all.cc +22 -0
  133. package/vendor/node-addon-api/test/except_all.js +14 -0
  134. package/vendor/node-addon-api/test/exports.js +19 -0
  135. package/vendor/node-addon-api/test/finalizer_order.cc +152 -0
  136. package/vendor/node-addon-api/test/finalizer_order.js +98 -0
  137. package/vendor/node-addon-api/test/function.js +2 -2
  138. package/vendor/node-addon-api/test/function_reference.js +2 -2
  139. package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +4 -4
  140. package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +4 -4
  141. package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +3 -3
  142. package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +5 -5
  143. package/vendor/node-addon-api/test/name.cc +10 -8
  144. package/vendor/node-addon-api/test/object/delete_property.cc +5 -5
  145. package/vendor/node-addon-api/test/object/get_property.cc +5 -5
  146. package/vendor/node-addon-api/test/object/has_own_property.cc +4 -4
  147. package/vendor/node-addon-api/test/object/has_property.cc +5 -5
  148. package/vendor/node-addon-api/test/object/object.cc +1 -1
  149. package/vendor/node-addon-api/test/object/set_property.cc +5 -5
  150. package/vendor/node-addon-api/test/object/subscript_operator.cc +3 -3
  151. package/vendor/node-addon-api/test/object_reference.cc +18 -18
  152. package/vendor/node-addon-api/test/promise.cc +75 -0
  153. package/vendor/node-addon-api/test/promise.js +23 -0
  154. package/vendor/node-addon-api/test/require_basic_finalizers/index.js +38 -0
  155. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +12 -0
  156. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +48 -0
  157. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +3 -0
  158. package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +11 -0
  159. package/vendor/node-addon-api/test/run_script.cc +1 -1
  160. package/vendor/node-addon-api/test/type_taggable.cc +1 -1
  161. package/vendor/node-addon-api/test/type_taggable.js +3 -4
  162. package/vendor/node-addon-api/test/typedarray.cc +28 -24
  163. package/vendor/node-addon-api/tools/conversion.js +1 -1
  164. package/vendor/node-api-headers/CHANGELOG.md +29 -0
  165. package/vendor/node-api-headers/CREATING_A_RELEASE.md +12 -2
  166. package/vendor/node-api-headers/def/js_native_api.def +6 -1
  167. package/vendor/node-api-headers/def/node_api.def +7 -1
  168. package/vendor/node-api-headers/include/js_native_api.h +56 -24
  169. package/vendor/node-api-headers/include/js_native_api_types.h +27 -0
  170. package/vendor/node-api-headers/include/node_api.h +38 -29
  171. package/vendor/node-api-headers/lib/parse-utils.js +92 -0
  172. package/vendor/node-api-headers/package.json +7 -7
  173. package/vendor/node-api-headers/release-please-config.json +12 -0
  174. package/vendor/node-api-headers/scripts/update-headers.js +63 -12
  175. package/vendor/node-api-headers/scripts/write-symbols.js +1 -1
  176. package/vendor/node-api-headers/symbols.js +17 -1
  177. package/vendor/node-api-headers/test/parse-utils.js +21 -0
  178. package/doc/flat/flat.css +0 -27
  179. package/doc/flat/normal.css +0 -429
  180. package/doc/flat/print.css +0 -29
  181. package/doc/flat/reset.css +0 -41
  182. package/doc/flat/small.css +0 -104
  183. package/doc/flat/static.js +0 -161
  184. package/src/core/libcc/brotli.cc +0 -186
  185. package/src/core/libcc/lz4.cc +0 -197
  186. package/src/core/libcc/miniz.cc +0 -353
  187. package/vendor/node-addon-api/tools/eslint-format.js +0 -79
  188. /package/vendor/node-api-headers/{scripts → lib}/clang-utils.js +0 -0
@@ -5,25 +5,25 @@ using namespace Napi;
5
5
 
6
6
  Value GetPropertyWithNapiValueAsKey(const CallbackInfo& info) {
7
7
  Object globalObject = info.Env().Global();
8
- Name key = info[0].As<Name>();
8
+ Name key = info[0].UnsafeAs<Name>();
9
9
  return MaybeUnwrap(globalObject.Get(key));
10
10
  }
11
11
 
12
12
  Value GetPropertyWithInt32AsKey(const CallbackInfo& info) {
13
13
  Object globalObject = info.Env().Global();
14
- Number key = info[0].As<Napi::Number>();
14
+ Number key = info[0].UnsafeAs<Napi::Number>();
15
15
  return MaybeUnwrapOr(globalObject.Get(key.Uint32Value()), Value());
16
16
  }
17
17
 
18
18
  Value GetPropertyWithCStyleStringAsKey(const CallbackInfo& info) {
19
19
  Object globalObject = info.Env().Global();
20
- String cStrkey = info[0].As<String>();
20
+ String cStrkey = info[0].UnsafeAs<String>();
21
21
  return MaybeUnwrapOr(globalObject.Get(cStrkey.Utf8Value().c_str()), Value());
22
22
  }
23
23
 
24
24
  Value GetPropertyWithCppStyleStringAsKey(const CallbackInfo& info) {
25
25
  Object globalObject = info.Env().Global();
26
- String cppStrKey = info[0].As<String>();
26
+ String cppStrKey = info[0].UnsafeAs<String>();
27
27
  return MaybeUnwrapOr(globalObject.Get(cppStrKey.Utf8Value()), Value());
28
28
  }
29
29
 
@@ -5,7 +5,7 @@ using namespace Napi;
5
5
 
6
6
  Value HasPropertyWithCStyleStringAsKey(const CallbackInfo& info) {
7
7
  Object globalObject = info.Env().Global();
8
- String key = info[0].As<String>();
8
+ String key = info[0].UnsafeAs<String>();
9
9
  return Boolean::New(
10
10
  info.Env(),
11
11
  MaybeUnwrapOr(globalObject.HasOwnProperty(key.Utf8Value().c_str()),
@@ -14,7 +14,7 @@ Value HasPropertyWithCStyleStringAsKey(const CallbackInfo& info) {
14
14
 
15
15
  Value HasPropertyWithCppStyleStringAsKey(const CallbackInfo& info) {
16
16
  Object globalObject = info.Env().Global();
17
- String key = info[0].As<String>();
17
+ String key = info[0].UnsafeAs<String>();
18
18
  return Boolean::New(
19
19
  info.Env(),
20
20
  MaybeUnwrapOr(globalObject.HasOwnProperty(key.Utf8Value()), false));
@@ -22,7 +22,7 @@ Value HasPropertyWithCppStyleStringAsKey(const CallbackInfo& info) {
22
22
 
23
23
  Value HasPropertyWithNapiValueAsKey(const CallbackInfo& info) {
24
24
  Object globalObject = info.Env().Global();
25
- Name key = info[0].As<Name>();
25
+ Name key = info[0].UnsafeAs<Name>();
26
26
  return Boolean::New(info.Env(),
27
27
  MaybeUnwrap(globalObject.HasOwnProperty(key)));
28
28
  }
@@ -4,28 +4,28 @@ using namespace Napi;
4
4
 
5
5
  void SetPropertyWithCStyleStringAsKey(const CallbackInfo& info) {
6
6
  Object globalObject = info.Env().Global();
7
- String key = info[0].As<String>();
7
+ String key = info[0].UnsafeAs<String>();
8
8
  Value value = info[1];
9
9
  globalObject.Set(key.Utf8Value().c_str(), value);
10
10
  }
11
11
 
12
12
  void SetPropertyWithCppStyleStringAsKey(const CallbackInfo& info) {
13
13
  Object globalObject = info.Env().Global();
14
- String key = info[0].As<String>();
14
+ String key = info[0].UnsafeAs<String>();
15
15
  Value value = info[1];
16
16
  globalObject.Set(key.Utf8Value(), value);
17
17
  }
18
18
 
19
19
  void SetPropertyWithInt32AsKey(const CallbackInfo& info) {
20
20
  Object globalObject = info.Env().Global();
21
- Number key = info[0].As<Number>();
21
+ Number key = info[0].UnsafeAs<Number>();
22
22
  Value value = info[1];
23
23
  globalObject.Set(key.Uint32Value(), value);
24
24
  }
25
25
 
26
26
  void SetPropertyWithNapiValueAsKey(const CallbackInfo& info) {
27
27
  Object globalObject = info.Env().Global();
28
- Name key = info[0].As<Name>();
28
+ Name key = info[0].UnsafeAs<Name>();
29
29
  Value value = info[1];
30
30
  globalObject.Set(key, value);
31
- }
31
+ }
@@ -21,19 +21,21 @@ Value EchoString(const CallbackInfo& info) {
21
21
 
22
22
  Value CreateString(const CallbackInfo& info) {
23
23
  String encoding = info[0].As<String>();
24
- Number length = info[1].As<Number>();
24
+ Value length = info[1];
25
25
 
26
26
  if (encoding.Utf8Value() == "utf8") {
27
27
  if (length.IsUndefined()) {
28
28
  return String::New(info.Env(), testValueUtf8);
29
29
  } else {
30
- return String::New(info.Env(), testValueUtf8, length.Uint32Value());
30
+ return String::New(
31
+ info.Env(), testValueUtf8, length.As<Number>().Uint32Value());
31
32
  }
32
33
  } else if (encoding.Utf8Value() == "utf16") {
33
34
  if (length.IsUndefined()) {
34
35
  return String::New(info.Env(), testValueUtf16);
35
36
  } else {
36
- return String::New(info.Env(), testValueUtf16, length.Uint32Value());
37
+ return String::New(
38
+ info.Env(), testValueUtf16, length.As<Number>().Uint32Value());
37
39
  }
38
40
  } else {
39
41
  Error::New(info.Env(), "Invalid encoding.").ThrowAsJavaScriptException();
@@ -44,12 +46,12 @@ Value CreateString(const CallbackInfo& info) {
44
46
  Value CheckString(const CallbackInfo& info) {
45
47
  String value = info[0].As<String>();
46
48
  String encoding = info[1].As<String>();
47
- Number length = info[2].As<Number>();
49
+ Value length = info[2];
48
50
 
49
51
  if (encoding.Utf8Value() == "utf8") {
50
52
  std::string testValue = testValueUtf8;
51
53
  if (!length.IsUndefined()) {
52
- testValue = testValue.substr(0, length.Uint32Value());
54
+ testValue = testValue.substr(0, length.As<Number>().Uint32Value());
53
55
  }
54
56
 
55
57
  std::string stringValue = value;
@@ -57,7 +59,7 @@ Value CheckString(const CallbackInfo& info) {
57
59
  } else if (encoding.Utf8Value() == "utf16") {
58
60
  std::u16string testValue = testValueUtf16;
59
61
  if (!length.IsUndefined()) {
60
- testValue = testValue.substr(0, length.Uint32Value());
62
+ testValue = testValue.substr(0, length.As<Number>().Uint32Value());
61
63
  }
62
64
 
63
65
  std::u16string stringValue = value;
@@ -69,10 +71,10 @@ Value CheckString(const CallbackInfo& info) {
69
71
  }
70
72
 
71
73
  Value CreateSymbol(const CallbackInfo& info) {
72
- String description = info[0].As<String>();
74
+ Value description = info[0];
73
75
 
74
76
  if (!description.IsUndefined()) {
75
- return Symbol::New(info.Env(), description);
77
+ return Symbol::New(info.Env(), description.As<String>());
76
78
  } else {
77
79
  return Symbol::New(info.Env());
78
80
  }
@@ -4,13 +4,13 @@
4
4
  using namespace Napi;
5
5
 
6
6
  Value DeletePropertyWithUint32(const CallbackInfo& info) {
7
- Object obj = info[0].As<Object>();
7
+ Object obj = info[0].UnsafeAs<Object>();
8
8
  Number key = info[1].As<Number>();
9
9
  return Boolean::New(info.Env(), MaybeUnwrap(obj.Delete(key.Uint32Value())));
10
10
  }
11
11
 
12
12
  Value DeletePropertyWithNapiValue(const CallbackInfo& info) {
13
- Object obj = info[0].As<Object>();
13
+ Object obj = info[0].UnsafeAs<Object>();
14
14
  Name key = info[1].As<Name>();
15
15
  return Boolean::New(
16
16
  info.Env(),
@@ -18,20 +18,20 @@ Value DeletePropertyWithNapiValue(const CallbackInfo& info) {
18
18
  }
19
19
 
20
20
  Value DeletePropertyWithNapiWrapperValue(const CallbackInfo& info) {
21
- Object obj = info[0].As<Object>();
21
+ Object obj = info[0].UnsafeAs<Object>();
22
22
  Name key = info[1].As<Name>();
23
23
  return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Delete(key), false));
24
24
  }
25
25
 
26
26
  Value DeletePropertyWithCStyleString(const CallbackInfo& info) {
27
- Object obj = info[0].As<Object>();
27
+ Object obj = info[0].UnsafeAs<Object>();
28
28
  String jsKey = info[1].As<String>();
29
29
  return Boolean::New(
30
30
  info.Env(), MaybeUnwrapOr(obj.Delete(jsKey.Utf8Value().c_str()), false));
31
31
  }
32
32
 
33
33
  Value DeletePropertyWithCppStyleString(const CallbackInfo& info) {
34
- Object obj = info[0].As<Object>();
34
+ Object obj = info[0].UnsafeAs<Object>();
35
35
  String jsKey = info[1].As<String>();
36
36
  return Boolean::New(info.Env(),
37
37
  MaybeUnwrapOr(obj.Delete(jsKey.Utf8Value()), false));
@@ -4,31 +4,31 @@
4
4
  using namespace Napi;
5
5
 
6
6
  Value GetPropertyWithNapiValue(const CallbackInfo& info) {
7
- Object obj = info[0].As<Object>();
7
+ Object obj = info[0].UnsafeAs<Object>();
8
8
  Name key = info[1].As<Name>();
9
9
  return MaybeUnwrapOr(obj.Get(static_cast<napi_value>(key)), Value());
10
10
  }
11
11
 
12
12
  Value GetPropertyWithNapiWrapperValue(const CallbackInfo& info) {
13
- Object obj = info[0].As<Object>();
13
+ Object obj = info[0].UnsafeAs<Object>();
14
14
  Name key = info[1].As<Name>();
15
15
  return MaybeUnwrapOr(obj.Get(key), Value());
16
16
  }
17
17
 
18
18
  Value GetPropertyWithUint32(const CallbackInfo& info) {
19
- Object obj = info[0].As<Object>();
19
+ Object obj = info[0].UnsafeAs<Object>();
20
20
  Number key = info[1].As<Number>();
21
21
  return MaybeUnwrap(obj.Get(key.Uint32Value()));
22
22
  }
23
23
 
24
24
  Value GetPropertyWithCStyleString(const CallbackInfo& info) {
25
- Object obj = info[0].As<Object>();
25
+ Object obj = info[0].UnsafeAs<Object>();
26
26
  String jsKey = info[1].As<String>();
27
27
  return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value().c_str()), Value());
28
28
  }
29
29
 
30
30
  Value GetPropertyWithCppStyleString(const CallbackInfo& info) {
31
- Object obj = info[0].As<Object>();
31
+ Object obj = info[0].UnsafeAs<Object>();
32
32
  String jsKey = info[1].As<String>();
33
33
  return MaybeUnwrapOr(obj.Get(jsKey.Utf8Value()), Value());
34
34
  }
@@ -4,7 +4,7 @@
4
4
  using namespace Napi;
5
5
 
6
6
  Value HasOwnPropertyWithNapiValue(const CallbackInfo& info) {
7
- Object obj = info[0].As<Object>();
7
+ Object obj = info[0].UnsafeAs<Object>();
8
8
  Name key = info[1].As<Name>();
9
9
  return Boolean::New(
10
10
  info.Env(),
@@ -12,14 +12,14 @@ Value HasOwnPropertyWithNapiValue(const CallbackInfo& info) {
12
12
  }
13
13
 
14
14
  Value HasOwnPropertyWithNapiWrapperValue(const CallbackInfo& info) {
15
- Object obj = info[0].As<Object>();
15
+ Object obj = info[0].UnsafeAs<Object>();
16
16
  Name key = info[1].As<Name>();
17
17
  return Boolean::New(info.Env(),
18
18
  MaybeUnwrapOr(obj.HasOwnProperty(key), false));
19
19
  }
20
20
 
21
21
  Value HasOwnPropertyWithCStyleString(const CallbackInfo& info) {
22
- Object obj = info[0].As<Object>();
22
+ Object obj = info[0].UnsafeAs<Object>();
23
23
  String jsKey = info[1].As<String>();
24
24
  return Boolean::New(
25
25
  info.Env(),
@@ -27,7 +27,7 @@ Value HasOwnPropertyWithCStyleString(const CallbackInfo& info) {
27
27
  }
28
28
 
29
29
  Value HasOwnPropertyWithCppStyleString(const CallbackInfo& info) {
30
- Object obj = info[0].As<Object>();
30
+ Object obj = info[0].UnsafeAs<Object>();
31
31
  String jsKey = info[1].As<String>();
32
32
  return Boolean::New(
33
33
  info.Env(), MaybeUnwrapOr(obj.HasOwnProperty(jsKey.Utf8Value()), false));
@@ -4,34 +4,34 @@
4
4
  using namespace Napi;
5
5
 
6
6
  Value HasPropertyWithNapiValue(const CallbackInfo& info) {
7
- Object obj = info[0].As<Object>();
7
+ Object obj = info[0].UnsafeAs<Object>();
8
8
  Name key = info[1].As<Name>();
9
9
  return Boolean::New(
10
10
  info.Env(), MaybeUnwrapOr(obj.Has(static_cast<napi_value>(key)), false));
11
11
  }
12
12
 
13
13
  Value HasPropertyWithNapiWrapperValue(const CallbackInfo& info) {
14
- Object obj = info[0].As<Object>();
14
+ Object obj = info[0].UnsafeAs<Object>();
15
15
  Name key = info[1].As<Name>();
16
16
  return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Has(key), false));
17
17
  }
18
18
 
19
19
  Value HasPropertyWithCStyleString(const CallbackInfo& info) {
20
- Object obj = info[0].As<Object>();
20
+ Object obj = info[0].UnsafeAs<Object>();
21
21
  String jsKey = info[1].As<String>();
22
22
  return Boolean::New(info.Env(),
23
23
  MaybeUnwrapOr(obj.Has(jsKey.Utf8Value().c_str()), false));
24
24
  }
25
25
 
26
26
  Value HasPropertyWithUint32(const CallbackInfo& info) {
27
- Object obj = info[0].As<Object>();
27
+ Object obj = info[0].UnsafeAs<Object>();
28
28
  Number jsKey = info[1].As<Number>();
29
29
  return Boolean::New(info.Env(),
30
30
  MaybeUnwrapOr(obj.Has(jsKey.Uint32Value()), false));
31
31
  }
32
32
 
33
33
  Value HasPropertyWithCppStyleString(const CallbackInfo& info) {
34
- Object obj = info[0].As<Object>();
34
+ Object obj = info[0].UnsafeAs<Object>();
35
35
  String jsKey = info[1].As<String>();
36
36
  return Boolean::New(info.Env(),
37
37
  MaybeUnwrapOr(obj.Has(jsKey.Utf8Value()), false));
@@ -338,7 +338,7 @@ void Increment(const CallbackInfo& info) {
338
338
  #endif // NAPI_CPP_EXCEPTIONS
339
339
 
340
340
  Value InstanceOf(const CallbackInfo& info) {
341
- Object obj = info[0].As<Object>();
341
+ Object obj = info[0].UnsafeAs<Object>();
342
342
  Function constructor = info[1].As<Function>();
343
343
  return Boolean::New(info.Env(), MaybeUnwrap(obj.InstanceOf(constructor)));
344
344
  }
@@ -4,7 +4,7 @@
4
4
  using namespace Napi;
5
5
 
6
6
  Value SetPropertyWithNapiValue(const CallbackInfo& info) {
7
- Object obj = info[0].As<Object>();
7
+ Object obj = info[0].UnsafeAs<Object>();
8
8
  Name key = info[1].As<Name>();
9
9
  Value value = info[2];
10
10
  return Boolean::New(
@@ -13,14 +13,14 @@ Value SetPropertyWithNapiValue(const CallbackInfo& info) {
13
13
  }
14
14
 
15
15
  Value SetPropertyWithNapiWrapperValue(const CallbackInfo& info) {
16
- Object obj = info[0].As<Object>();
16
+ Object obj = info[0].UnsafeAs<Object>();
17
17
  Name key = info[1].As<Name>();
18
18
  Value value = info[2];
19
19
  return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Set(key, value), false));
20
20
  }
21
21
 
22
22
  Value SetPropertyWithUint32(const CallbackInfo& info) {
23
- Object obj = info[0].As<Object>();
23
+ Object obj = info[0].UnsafeAs<Object>();
24
24
  Number key = info[1].As<Number>();
25
25
  Value value = info[2];
26
26
  return Boolean::New(info.Env(),
@@ -28,7 +28,7 @@ Value SetPropertyWithUint32(const CallbackInfo& info) {
28
28
  }
29
29
 
30
30
  Value SetPropertyWithCStyleString(const CallbackInfo& info) {
31
- Object obj = info[0].As<Object>();
31
+ Object obj = info[0].UnsafeAs<Object>();
32
32
  String jsKey = info[1].As<String>();
33
33
  Value value = info[2];
34
34
  return Boolean::New(
@@ -37,7 +37,7 @@ Value SetPropertyWithCStyleString(const CallbackInfo& info) {
37
37
  }
38
38
 
39
39
  Value SetPropertyWithCppStyleString(const CallbackInfo& info) {
40
- Object obj = info[0].As<Object>();
40
+ Object obj = info[0].UnsafeAs<Object>();
41
41
  String jsKey = info[1].As<String>();
42
42
  Value value = info[2];
43
43
  return Boolean::New(info.Env(),
@@ -8,7 +8,7 @@ Value SubscriptGetWithCStyleString(const CallbackInfo& info) {
8
8
 
9
9
  // make sure const case compiles
10
10
  const Object obj2 = info[0].As<Object>();
11
- MaybeUnwrap(obj2[jsKey.Utf8Value().c_str()]).As<Boolean>();
11
+ MaybeUnwrap(obj2[jsKey.Utf8Value().c_str()]).As<Value>();
12
12
 
13
13
  Object obj = info[0].As<Object>();
14
14
  return obj[jsKey.Utf8Value().c_str()];
@@ -19,7 +19,7 @@ Value SubscriptGetWithCppStyleString(const CallbackInfo& info) {
19
19
 
20
20
  // make sure const case compiles
21
21
  const Object obj2 = info[0].As<Object>();
22
- MaybeUnwrap(obj2[jsKey.Utf8Value()]).As<Boolean>();
22
+ MaybeUnwrap(obj2[jsKey.Utf8Value()]).As<Value>();
23
23
 
24
24
  Object obj = info[0].As<Object>();
25
25
  return obj[jsKey.Utf8Value()];
@@ -30,7 +30,7 @@ Value SubscriptGetAtIndex(const CallbackInfo& info) {
30
30
 
31
31
  // make sure const case compiles
32
32
  const Object obj2 = info[0].As<Object>();
33
- MaybeUnwrap(obj2[index]).As<Boolean>();
33
+ MaybeUnwrap(obj2[index]).As<Value>();
34
34
 
35
35
  Object obj = info[0].As<Object>();
36
36
  return obj[index];
@@ -224,13 +224,13 @@ void SetCastedObjects(const CallbackInfo& info) {
224
224
  Value GetFromValue(const CallbackInfo& info) {
225
225
  Env env = info.Env();
226
226
 
227
- if (info[0].As<String>() == String::New(env, "weak")) {
227
+ if (info[0] == String::New(env, "weak")) {
228
228
  if (weak.IsEmpty()) {
229
229
  return String::New(env, "No Referenced Value");
230
230
  } else {
231
231
  return weak.Value();
232
232
  }
233
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
233
+ } else if (info[0] == String::New(env, "persistent")) {
234
234
  return persistent.Value();
235
235
  } else {
236
236
  return reference.Value();
@@ -290,7 +290,7 @@ Value GetFromGetters(const CallbackInfo& info) {
290
290
  Value GetFromGetter(const CallbackInfo& info) {
291
291
  Env env = info.Env();
292
292
 
293
- if (info[0].As<String>() == String::New(env, "weak")) {
293
+ if (info[0] == String::New(env, "weak")) {
294
294
  if (weak.IsEmpty()) {
295
295
  return String::New(env, "No Referenced Value");
296
296
  } else {
@@ -300,7 +300,7 @@ Value GetFromGetter(const CallbackInfo& info) {
300
300
  return MaybeUnwrap(weak.Get(info[1].As<Number>().Uint32Value()));
301
301
  }
302
302
  }
303
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
303
+ } else if (info[0] == String::New(env, "persistent")) {
304
304
  if (info[1].IsString()) {
305
305
  return MaybeUnwrap(persistent.Get(info[1].As<String>().Utf8Value()));
306
306
  } else if (info[1].IsNumber()) {
@@ -322,13 +322,13 @@ Value GetFromGetter(const CallbackInfo& info) {
322
322
  Value GetCastedFromValue(const CallbackInfo& info) {
323
323
  Env env = info.Env();
324
324
 
325
- if (info[0].As<String>() == String::New(env, "weak")) {
325
+ if (info[0] == String::New(env, "weak")) {
326
326
  if (casted_weak.IsEmpty()) {
327
327
  return String::New(env, "No Referenced Value");
328
328
  } else {
329
329
  return casted_weak.Value();
330
330
  }
331
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
331
+ } else if (info[0] == String::New(env, "persistent")) {
332
332
  return casted_persistent.Value();
333
333
  } else {
334
334
  return casted_reference.Value();
@@ -341,13 +341,13 @@ Value GetCastedFromValue(const CallbackInfo& info) {
341
341
  Value GetCastedFromGetter(const CallbackInfo& info) {
342
342
  Env env = info.Env();
343
343
 
344
- if (info[0].As<String>() == String::New(env, "weak")) {
344
+ if (info[0] == String::New(env, "weak")) {
345
345
  if (casted_weak.IsEmpty()) {
346
346
  return String::New(env, "No Referenced Value");
347
347
  } else {
348
348
  return MaybeUnwrap(casted_weak.Get(info[1].As<Number>()));
349
349
  }
350
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
350
+ } else if (info[0] == String::New(env, "persistent")) {
351
351
  return MaybeUnwrap(casted_persistent.Get(info[1].As<Number>()));
352
352
  } else {
353
353
  return MaybeUnwrap(casted_reference.Get(info[1].As<Number>()));
@@ -360,15 +360,15 @@ Number UnrefObjects(const CallbackInfo& info) {
360
360
  Env env = info.Env();
361
361
  uint32_t num;
362
362
 
363
- if (info[0].As<String>() == String::New(env, "weak")) {
363
+ if (info[0] == String::New(env, "weak")) {
364
364
  num = weak.Unref();
365
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
365
+ } else if (info[0] == String::New(env, "persistent")) {
366
366
  num = persistent.Unref();
367
- } else if (info[0].As<String>() == String::New(env, "references")) {
367
+ } else if (info[0] == String::New(env, "references")) {
368
368
  num = reference.Unref();
369
- } else if (info[0].As<String>() == String::New(env, "casted weak")) {
369
+ } else if (info[0] == String::New(env, "casted weak")) {
370
370
  num = casted_weak.Unref();
371
- } else if (info[0].As<String>() == String::New(env, "casted persistent")) {
371
+ } else if (info[0] == String::New(env, "casted persistent")) {
372
372
  num = casted_persistent.Unref();
373
373
  } else {
374
374
  num = casted_reference.Unref();
@@ -383,15 +383,15 @@ Number RefObjects(const CallbackInfo& info) {
383
383
  Env env = info.Env();
384
384
  uint32_t num;
385
385
 
386
- if (info[0].As<String>() == String::New(env, "weak")) {
386
+ if (info[0] == String::New(env, "weak")) {
387
387
  num = weak.Ref();
388
- } else if (info[0].As<String>() == String::New(env, "persistent")) {
388
+ } else if (info[0] == String::New(env, "persistent")) {
389
389
  num = persistent.Ref();
390
- } else if (info[0].As<String>() == String::New(env, "references")) {
390
+ } else if (info[0] == String::New(env, "references")) {
391
391
  num = reference.Ref();
392
- } else if (info[0].As<String>() == String::New(env, "casted weak")) {
392
+ } else if (info[0] == String::New(env, "casted weak")) {
393
393
  num = casted_weak.Ref();
394
- } else if (info[0].As<String>() == String::New(env, "casted persistent")) {
394
+ } else if (info[0] == String::New(env, "casted persistent")) {
395
395
  num = casted_persistent.Ref();
396
396
  } else {
397
397
  num = casted_reference.Ref();
@@ -1,4 +1,5 @@
1
1
  #include "napi.h"
2
+ #include "test_helper.h"
2
3
 
3
4
  using namespace Napi;
4
5
 
@@ -23,6 +24,74 @@ Value PromiseReturnsCorrectEnv(const CallbackInfo& info) {
23
24
  return Boolean::New(info.Env(), deferred.Env() == info.Env());
24
25
  }
25
26
 
27
+ Value ThenMethodOnFulfilled(const CallbackInfo& info) {
28
+ auto deferred = Promise::Deferred::New(info.Env());
29
+ Function onFulfilled = info[0].As<Function>();
30
+
31
+ Promise resultPromise = MaybeUnwrap(deferred.Promise().Then(onFulfilled));
32
+
33
+ bool isPromise = resultPromise.IsPromise();
34
+ deferred.Resolve(Number::New(info.Env(), 42));
35
+
36
+ Object result = Object::New(info.Env());
37
+ result["isPromise"] = Boolean::New(info.Env(), isPromise);
38
+ result["promise"] = resultPromise;
39
+
40
+ return result;
41
+ }
42
+
43
+ Value ThenMethodOnFulfilledOnRejectedResolve(const CallbackInfo& info) {
44
+ auto deferred = Promise::Deferred::New(info.Env());
45
+ Function onFulfilled = info[0].As<Function>();
46
+ Function onRejected = info[1].As<Function>();
47
+
48
+ Promise resultPromise =
49
+ MaybeUnwrap(deferred.Promise().Then(onFulfilled, onRejected));
50
+
51
+ bool isPromise = resultPromise.IsPromise();
52
+ deferred.Resolve(Number::New(info.Env(), 42));
53
+
54
+ Object result = Object::New(info.Env());
55
+ result["isPromise"] = Boolean::New(info.Env(), isPromise);
56
+ result["promise"] = resultPromise;
57
+
58
+ return result;
59
+ }
60
+
61
+ Value ThenMethodOnFulfilledOnRejectedReject(const CallbackInfo& info) {
62
+ auto deferred = Promise::Deferred::New(info.Env());
63
+ Function onFulfilled = info[0].As<Function>();
64
+ Function onRejected = info[1].As<Function>();
65
+
66
+ Promise resultPromise =
67
+ MaybeUnwrap(deferred.Promise().Then(onFulfilled, onRejected));
68
+
69
+ bool isPromise = resultPromise.IsPromise();
70
+ deferred.Reject(String::New(info.Env(), "Rejected"));
71
+
72
+ Object result = Object::New(info.Env());
73
+ result["isPromise"] = Boolean::New(info.Env(), isPromise);
74
+ result["promise"] = resultPromise;
75
+
76
+ return result;
77
+ }
78
+
79
+ Value CatchMethod(const CallbackInfo& info) {
80
+ auto deferred = Promise::Deferred::New(info.Env());
81
+ Function onRejected = info[0].As<Function>();
82
+
83
+ Promise resultPromise = MaybeUnwrap(deferred.Promise().Catch(onRejected));
84
+
85
+ bool isPromise = resultPromise.IsPromise();
86
+ deferred.Reject(String::New(info.Env(), "Rejected"));
87
+
88
+ Object result = Object::New(info.Env());
89
+ result["isPromise"] = Boolean::New(info.Env(), isPromise);
90
+ result["promise"] = resultPromise;
91
+
92
+ return result;
93
+ }
94
+
26
95
  Object InitPromise(Env env) {
27
96
  Object exports = Object::New(env);
28
97
 
@@ -31,6 +100,12 @@ Object InitPromise(Env env) {
31
100
  exports["rejectPromise"] = Function::New(env, RejectPromise);
32
101
  exports["promiseReturnsCorrectEnv"] =
33
102
  Function::New(env, PromiseReturnsCorrectEnv);
103
+ exports["thenMethodOnFulfilled"] = Function::New(env, ThenMethodOnFulfilled);
104
+ exports["thenMethodOnFulfilledOnRejectedResolve"] =
105
+ Function::New(env, ThenMethodOnFulfilledOnRejectedResolve);
106
+ exports["thenMethodOnFulfilledOnRejectedReject"] =
107
+ Function::New(env, ThenMethodOnFulfilledOnRejectedReject);
108
+ exports["catchMethod"] = Function::New(env, CatchMethod);
34
109
 
35
110
  return exports;
36
111
  }
@@ -17,4 +17,27 @@ async function test (binding) {
17
17
  rejecting.then(common.mustNotCall()).catch(common.mustCall());
18
18
 
19
19
  assert(binding.promise.promiseReturnsCorrectEnv());
20
+
21
+ const onFulfilled = (value) => value * 2;
22
+ const onRejected = (reason) => reason + '!';
23
+
24
+ const thenOnFulfilled = binding.promise.thenMethodOnFulfilled(onFulfilled);
25
+ assert.strictEqual(thenOnFulfilled.isPromise, true);
26
+ const onFulfilledValue = await thenOnFulfilled.promise;
27
+ assert.strictEqual(onFulfilledValue, 84);
28
+
29
+ const thenResolve = binding.promise.thenMethodOnFulfilledOnRejectedResolve(onFulfilled, onRejected);
30
+ assert.strictEqual(thenResolve.isPromise, true);
31
+ const thenResolveValue = await thenResolve.promise;
32
+ assert.strictEqual(thenResolveValue, 84);
33
+
34
+ const thenRejected = binding.promise.thenMethodOnFulfilledOnRejectedReject(onFulfilled, onRejected);
35
+ assert.strictEqual(thenRejected.isPromise, true);
36
+ const rejectedValue = await thenRejected.promise;
37
+ assert.strictEqual(rejectedValue, 'Rejected!');
38
+
39
+ const catchMethod = binding.promise.catchMethod(onRejected);
40
+ assert.strictEqual(catchMethod.isPromise, true);
41
+ const catchValue = await catchMethod.promise;
42
+ assert.strictEqual(catchValue, 'Rejected!');
20
43
  }
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const { promisify } = require('util');
4
+ const exec = promisify(require('child_process').exec);
5
+ const { copy, remove } = require('fs-extra');
6
+ const path = require('path');
7
+ const assert = require('assert');
8
+
9
+ async function test () {
10
+ const addon = 'require-basic-finalizers';
11
+ const ADDON_FOLDER = path.join(__dirname, 'addons', addon);
12
+
13
+ await remove(ADDON_FOLDER);
14
+ await copy(path.join(__dirname, 'tpl'), ADDON_FOLDER);
15
+
16
+ console.log(' >Building addon');
17
+
18
+ // Fail when NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS is enabled
19
+ await assert.rejects(exec('npm --require-basic-finalizers install', {
20
+ cwd: ADDON_FOLDER
21
+ }), 'Addon unexpectedly compiled successfully');
22
+
23
+ // Succeed when NODE_ADDON_API_REQUIRE_BASIC_FINALIZERS is not enabled
24
+ return assert.doesNotReject(exec('npm install', {
25
+ cwd: ADDON_FOLDER
26
+ }));
27
+ }
28
+
29
+ module.exports = (function () {
30
+ // This test will only run under an experimental version test.
31
+ const isExperimental = Number(process.env.NAPI_VERSION) === 2147483647;
32
+
33
+ if (isExperimental) {
34
+ return test();
35
+ } else {
36
+ console.log(' >Skipped (non-experimental test run)');
37
+ }
38
+ })();
@@ -0,0 +1,12 @@
1
+ #include <napi.h>
2
+
3
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
4
+ exports.Set(
5
+ "external",
6
+ Napi::External<int>::New(
7
+ env, new int(1), [](Napi::Env /*env*/, int* data) { delete data; }));
8
+
9
+ return exports;
10
+ }
11
+
12
+ NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)