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
@@ -1,7 +1,7 @@
1
1
  #include "napi.h"
2
2
 
3
3
  static napi_value Getter_Core(napi_env env, napi_callback_info info) {
4
- (void) info;
4
+ (void)info;
5
5
  napi_value result;
6
6
  napi_status status = napi_create_uint32(env, 42, &result);
7
7
  NAPI_THROW_IF_FAILED(env, status, nullptr);
@@ -14,7 +14,7 @@ static napi_value Setter_Core(napi_env env, napi_callback_info info) {
14
14
  napi_status status =
15
15
  napi_get_cb_info(env, info, &argc, &argv, nullptr, nullptr);
16
16
  NAPI_THROW_IF_FAILED(env, status, nullptr);
17
- (void) argv;
17
+ (void)argv;
18
18
  return nullptr;
19
19
  }
20
20
 
@@ -23,22 +23,23 @@ static Napi::Value Getter(const Napi::CallbackInfo& info) {
23
23
  }
24
24
 
25
25
  static void Setter(const Napi::CallbackInfo& info) {
26
- (void) info[0];
26
+ (void)info[0];
27
27
  }
28
28
 
29
29
  #if NAPI_VERSION > 5
30
30
  class PropDescBenchmark : public Napi::Addon<PropDescBenchmark> {
31
31
  public:
32
32
  PropDescBenchmark(Napi::Env, Napi::Object exports) {
33
- DefineAddon(exports, {
34
- InstanceAccessor("addon",
35
- &PropDescBenchmark::Getter,
36
- &PropDescBenchmark::Setter,
37
- napi_enumerable),
38
- InstanceAccessor<&PropDescBenchmark::Getter,
39
- &PropDescBenchmark::Setter>("addon_templated",
40
- napi_enumerable),
41
- });
33
+ DefineAddon(exports,
34
+ {
35
+ InstanceAccessor("addon",
36
+ &PropDescBenchmark::Getter,
37
+ &PropDescBenchmark::Setter,
38
+ napi_enumerable),
39
+ InstanceAccessor<&PropDescBenchmark::Getter,
40
+ &PropDescBenchmark::Setter>(
41
+ "addon_templated", napi_enumerable),
42
+ });
42
43
  }
43
44
 
44
45
  private:
@@ -47,39 +48,31 @@ class PropDescBenchmark : public Napi::Addon<PropDescBenchmark> {
47
48
  }
48
49
 
49
50
  void Setter(const Napi::CallbackInfo& info, const Napi::Value& val) {
50
- (void) info[0];
51
- (void) val;
51
+ (void)info[0];
52
+ (void)val;
52
53
  }
53
54
  };
54
55
  #endif // NAPI_VERSION > 5
55
56
 
56
57
  static Napi::Object Init(Napi::Env env, Napi::Object exports) {
57
58
  napi_status status;
58
- napi_property_descriptor core_prop = {
59
- "core",
60
- nullptr,
61
- nullptr,
62
- Getter_Core,
63
- Setter_Core,
64
- nullptr,
65
- napi_enumerable,
66
- nullptr
67
- };
59
+ napi_property_descriptor core_prop = {"core",
60
+ nullptr,
61
+ nullptr,
62
+ Getter_Core,
63
+ Setter_Core,
64
+ nullptr,
65
+ napi_enumerable,
66
+ nullptr};
68
67
 
69
68
  status = napi_define_properties(env, exports, 1, &core_prop);
70
69
  NAPI_THROW_IF_FAILED(env, status, Napi::Object());
71
70
 
72
- exports.DefineProperty(
73
- Napi::PropertyDescriptor::Accessor(env,
74
- exports,
75
- "cplusplus",
76
- Getter,
77
- Setter,
78
- napi_enumerable));
71
+ exports.DefineProperty(Napi::PropertyDescriptor::Accessor(
72
+ env, exports, "cplusplus", Getter, Setter, napi_enumerable));
79
73
 
80
- exports.DefineProperty(
81
- Napi::PropertyDescriptor::Accessor<Getter, Setter>("templated",
82
- napi_enumerable));
74
+ exports.DefineProperty(Napi::PropertyDescriptor::Accessor<Getter, Setter>(
75
+ "templated", napi_enumerable));
83
76
 
84
77
  #if NAPI_VERSION > 5
85
78
  PropDescBenchmark::Init(env, exports);
@@ -2,15 +2,15 @@ const path = require('path');
2
2
  const Benchmark = require('benchmark');
3
3
  const addonName = path.basename(__filename, '.js');
4
4
 
5
- [ addonName, addonName + '_noexcept' ]
5
+ [addonName, addonName + '_noexcept']
6
6
  .forEach((addonName) => {
7
7
  const rootAddon = require('bindings')({
8
8
  bindings: addonName,
9
9
  module_root: __dirname
10
10
  });
11
11
  delete rootAddon.path;
12
- const getters = new Benchmark.Suite;
13
- const setters = new Benchmark.Suite;
12
+ const getters = new Benchmark.Suite();
13
+ const setters = new Benchmark.Suite();
14
14
  const maxNameLength = Object.keys(rootAddon)
15
15
  .reduce((soFar, value) => Math.max(soFar, value.length), 0);
16
16
 
@@ -18,11 +18,12 @@ const addonName = path.basename(__filename, '.js');
18
18
 
19
19
  Object.keys(rootAddon).forEach((key) => {
20
20
  getters.add(`${key} getter`.padStart(maxNameLength + 7), () => {
21
+ // eslint-disable-next-line no-unused-vars
21
22
  const x = rootAddon[key];
22
23
  });
23
24
  setters.add(`${key} setter`.padStart(maxNameLength + 7), () => {
24
25
  rootAddon[key] = 5;
25
- })
26
+ });
26
27
  });
27
28
 
28
29
  getters
@@ -19,7 +19,7 @@ asynchronous operations:
19
19
 
20
20
  - **[`Napi::AsyncWorker`](async_worker.md)**
21
21
 
22
- These class helps manage asynchronous operations through an abstraction
22
+ This class helps manage asynchronous operations through an abstraction
23
23
  of the concept of moving data between the **event loop** and **worker threads**.
24
24
 
25
25
  Also, the above class may not be appropriate for every scenario. When using any
@@ -51,8 +51,11 @@ virtual void Napi::AsyncProgressWorker::OnOK();
51
51
 
52
52
  ### OnProgress
53
53
 
54
- This method is invoked when the computation in the `Napi::AsyncProgressWorker::ExecutionProcess::Send`
55
- method was called during worker thread execution.
54
+ This method is invoked when the computation in the
55
+ `Napi::AsyncProgressWorker::ExecutionProcess::Send` method was called during
56
+ worker thread execution. This method can also be triggered via a call to
57
+ `Napi::AsyncProgress[Queue]Worker::ExecutionProcess::Signal`, in which case the
58
+ `data` parameter will be `nullptr`.
56
59
 
57
60
  ```cpp
58
61
  virtual void Napi::AsyncProgressWorker::OnProgress(const T* data, size_t count)
@@ -251,6 +254,15 @@ class instead which is documented further down this page.
251
254
  void Napi::AsyncProgressWorker::ExecutionProcess::Send(const T* data, size_t count) const;
252
255
  ```
253
256
 
257
+ ### Signal
258
+
259
+ `Napi::AsyncProgressWorker::ExecutionProcess::Signal` triggers an invocation of
260
+ `Napi::AsyncProgressWorker::OnProgress` with `nullptr` as the `data` parameter.
261
+
262
+ ```cpp
263
+ void Napi::AsyncProgressWorker::ExecutionProcess::Signal();
264
+ ```
265
+
254
266
  ## Example
255
267
 
256
268
  The first step to use the `Napi::AsyncProgressWorker` class is to create a new class that
@@ -415,6 +427,15 @@ with each data item.
415
427
  void Napi::AsyncProgressQueueWorker::ExecutionProcess::Send(const T* data, size_t count) const;
416
428
  ```
417
429
 
430
+ ### Signal
431
+
432
+ `Napi::AsyncProgressQueueWorker::ExecutionProcess::Signal` triggers an invocation of
433
+ `Napi::AsyncProgressQueueWorker::OnProgress` with `nullptr` as the `data` parameter.
434
+
435
+ ```cpp
436
+ void Napi::AsyncProgressQueueWorker::ExecutionProcess::Signal() const;
437
+ ```
438
+
418
439
  ## Example
419
440
 
420
441
  The code below shows an example of the `Napi::AsyncProgressQueueWorker` implementation, but
@@ -47,7 +47,7 @@ add_definitions(-DNAPI_EXPERIMENTAL)
47
47
 
48
48
  ### node-addon-api
49
49
 
50
- If your Node-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api).
50
+ If your Node-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#node-api-and-node-addon-api).
51
51
 
52
52
  ## Example
53
53
 
@@ -26,7 +26,7 @@ The following sections explain the approach for each case:
26
26
  <a name="exceptions"></a>
27
27
 
28
28
  In most cases when an error occurs, the addon should do whatever cleanup is possible
29
- and then return to JavaScript so that the error can be propagated. In less frequent
29
+ and then return to JavaScript so that the error can be propagated. In less frequent
30
30
  cases the addon may be able to recover from the error, clear the error and then
31
31
  continue.
32
32
 
@@ -48,8 +48,8 @@ method.
48
48
  If a C++ exception of type `Napi::Error` escapes from a Node-API C++ callback, then
49
49
  the Node-API wrapper automatically converts and throws it as a JavaScript exception.
50
50
 
51
- On return from a native method, node-addon-api will automatically convert a pending C++
52
- exception to a JavaScript exception.
51
+ On return from a native method, node-addon-api will automatically convert a pending
52
+ `Napi::Error` C++ exception to a JavaScript exception.
53
53
 
54
54
  When C++ exceptions are enabled try/catch can be used to catch exceptions thrown
55
55
  from calls to JavaScript and then they can either be handled or rethrown before
@@ -6,6 +6,13 @@ The `Napi::External` template class implements the ability to create a `Napi::Va
6
6
 
7
7
  `Napi::External` objects can be created with an optional Finalizer function and optional Hint value. The Finalizer function, if specified, is called when your `Napi::External` object is released by Node's garbage collector. It gives your code the opportunity to free any dynamically created data. If you specify a Hint value, it is passed to your Finalizer function.
8
8
 
9
+ Note that `Napi::Value::IsExternal()` will return `true` for any external value.
10
+ It does not differentiate between the templated parameter `T` in
11
+ `Napi::External<T>`. It is up to the addon to ensure an `Napi::External<T>`
12
+ object holds the correct `T` when retrieving the data via
13
+ `Napi::External<T>::Data()`. One method to ensure an object is of a specific
14
+ type is through [type tags](./object.md#TypeTag).
15
+
9
16
  ## Methods
10
17
 
11
18
  ### New
@@ -61,3 +61,17 @@ Napi::Env Napi::HandleScope::Env() const;
61
61
  ```
62
62
 
63
63
  Returns the `Napi::Env` associated with the `Napi::HandleScope`.
64
+
65
+ ## Example
66
+
67
+ ```cpp
68
+ for (int i = 0; i < LOOP_MAX; i++) {
69
+ Napi::HandleScope scope(info.Env());
70
+ std::string name = std::string("inner-scope") + std::to_string(i);
71
+ Napi::Value newValue = Napi::String::New(info.Env(), name.c_str());
72
+ // do something with newValue
73
+ };
74
+ ```
75
+
76
+ For more details refer to the section titled [Object lifetime
77
+ management](object_lifetime_management.md).
@@ -81,7 +81,7 @@
81
81
  [`Napi::Reference<Napi::Object>`]: ./reference.md
82
82
  [`Napi::String`]: ./string.md
83
83
  [`Napi::Symbol`]: ./symbol.md
84
- [`Napi::ThreadSafeFunction`]: ./thread_safe_function.md
84
+ [`Napi::ThreadSafeFunction`]: ./threadsafe_function.md
85
85
  [`Napi::TypeError`]: ./type_error.md
86
86
  [`Napi::TypedArray`]: ./typed_array.md
87
87
  [`Napi::TypedArrayOf`]: ./typed_array_of.md
@@ -241,6 +241,33 @@ from being added to it and marking all existing properties as non-configurable.
241
241
  Values of present properties can still be changed as long as they are
242
242
  writable.
243
243
 
244
+ ### TypeTag()
245
+
246
+ ```cpp
247
+ void Napi::Object::TypeTag(const napi_type_tag* type_tag) const;
248
+ ```
249
+
250
+ - `[in] type_tag`: The tag with which this object is to be marked.
251
+
252
+ The `Napi::Object::TypeTag()` method associates the value of the `type_tag`
253
+ pointer with this JavaScript object. `Napi::Object::CheckTypeTag()` can then be
254
+ used to compare the tag that was attached to this object with one owned by the
255
+ addon to ensure that this object has the right type.
256
+
257
+ ### CheckTypeTag()
258
+
259
+ ```cpp
260
+ bool Napi::Object::CheckTypeTag(const napi_type_tag* type_tag) const;
261
+ ```
262
+
263
+ - `[in] type_tag`: The tag with which to compare any tag found on this object.
264
+
265
+ The `Napi::Object::CheckTypeTag()` method compares the pointer given as
266
+ `type_tag` with any that can be found on this JavaScript object. If no tag is
267
+ found on this object or, if a tag is found but it does not match `type_tag`,
268
+ then the return value is `false`. If a tag is found and it matches `type_tag`,
269
+ then the return value is `true`.
270
+
244
271
  ### operator\[\]()
245
272
 
246
273
  ```cpp
@@ -1,11 +1,11 @@
1
1
  const path = require('path');
2
2
 
3
- const include_dir = path.relative('.', __dirname);
3
+ const includeDir = path.relative('.', __dirname);
4
4
 
5
5
  module.exports = {
6
6
  include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
7
- include_dir,
8
- gyp: path.join(include_dir, 'node_api.gyp:nothing'),
7
+ include_dir: includeDir,
8
+ gyp: path.join(includeDir, 'node_api.gyp:nothing'),
9
9
  isNodeApiBuiltin: true,
10
10
  needsFlag: false
11
11
  };
@@ -6,187 +6,181 @@
6
6
  ////////////////////////////////////////////////////////////////////////////////
7
7
 
8
8
  template <typename Getter>
9
- inline PropertyDescriptor
10
- PropertyDescriptor::Accessor(const char* utf8name,
11
- Getter getter,
12
- napi_property_attributes attributes,
13
- void* /*data*/) {
9
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
10
+ const char* utf8name,
11
+ Getter getter,
12
+ napi_property_attributes attributes,
13
+ void* /*data*/) {
14
14
  using CbData = details::CallbackData<Getter, Napi::Value>;
15
15
  // TODO: Delete when the function is destroyed
16
- auto callbackData = new CbData({ getter, nullptr });
17
-
18
- return PropertyDescriptor({
19
- utf8name,
20
- nullptr,
21
- nullptr,
22
- CbData::Wrapper,
23
- nullptr,
24
- nullptr,
25
- attributes,
26
- callbackData
27
- });
16
+ auto callbackData = new CbData({getter, nullptr});
17
+
18
+ return PropertyDescriptor({utf8name,
19
+ nullptr,
20
+ nullptr,
21
+ CbData::Wrapper,
22
+ nullptr,
23
+ nullptr,
24
+ attributes,
25
+ callbackData});
28
26
  }
29
27
 
30
28
  template <typename Getter>
31
- inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name,
32
- Getter getter,
33
- napi_property_attributes attributes,
34
- void* data) {
29
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
30
+ const std::string& utf8name,
31
+ Getter getter,
32
+ napi_property_attributes attributes,
33
+ void* data) {
35
34
  return Accessor(utf8name.c_str(), getter, attributes, data);
36
35
  }
37
36
 
38
37
  template <typename Getter>
39
- inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
40
- Getter getter,
41
- napi_property_attributes attributes,
42
- void* /*data*/) {
38
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
39
+ napi_value name,
40
+ Getter getter,
41
+ napi_property_attributes attributes,
42
+ void* /*data*/) {
43
43
  using CbData = details::CallbackData<Getter, Napi::Value>;
44
44
  // TODO: Delete when the function is destroyed
45
- auto callbackData = new CbData({ getter, nullptr });
46
-
47
- return PropertyDescriptor({
48
- nullptr,
49
- name,
50
- nullptr,
51
- CbData::Wrapper,
52
- nullptr,
53
- nullptr,
54
- attributes,
55
- callbackData
56
- });
45
+ auto callbackData = new CbData({getter, nullptr});
46
+
47
+ return PropertyDescriptor({nullptr,
48
+ name,
49
+ nullptr,
50
+ CbData::Wrapper,
51
+ nullptr,
52
+ nullptr,
53
+ attributes,
54
+ callbackData});
57
55
  }
58
56
 
59
57
  template <typename Getter>
60
- inline PropertyDescriptor PropertyDescriptor::Accessor(Name name,
61
- Getter getter,
62
- napi_property_attributes attributes,
63
- void* data) {
58
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
59
+ Name name, Getter getter, napi_property_attributes attributes, void* data) {
64
60
  napi_value nameValue = name;
65
61
  return PropertyDescriptor::Accessor(nameValue, getter, attributes, data);
66
62
  }
67
63
 
68
64
  template <typename Getter, typename Setter>
69
- inline PropertyDescriptor PropertyDescriptor::Accessor(const char* utf8name,
70
- Getter getter,
71
- Setter setter,
72
- napi_property_attributes attributes,
73
- void* /*data*/) {
65
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
66
+ const char* utf8name,
67
+ Getter getter,
68
+ Setter setter,
69
+ napi_property_attributes attributes,
70
+ void* /*data*/) {
74
71
  using CbData = details::AccessorCallbackData<Getter, Setter>;
75
72
  // TODO: Delete when the function is destroyed
76
- auto callbackData = new CbData({ getter, setter, nullptr });
77
-
78
- return PropertyDescriptor({
79
- utf8name,
80
- nullptr,
81
- nullptr,
82
- CbData::GetterWrapper,
83
- CbData::SetterWrapper,
84
- nullptr,
85
- attributes,
86
- callbackData
87
- });
73
+ auto callbackData = new CbData({getter, setter, nullptr});
74
+
75
+ return PropertyDescriptor({utf8name,
76
+ nullptr,
77
+ nullptr,
78
+ CbData::GetterWrapper,
79
+ CbData::SetterWrapper,
80
+ nullptr,
81
+ attributes,
82
+ callbackData});
88
83
  }
89
84
 
90
85
  template <typename Getter, typename Setter>
91
- inline PropertyDescriptor PropertyDescriptor::Accessor(const std::string& utf8name,
92
- Getter getter,
93
- Setter setter,
94
- napi_property_attributes attributes,
95
- void* data) {
86
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
87
+ const std::string& utf8name,
88
+ Getter getter,
89
+ Setter setter,
90
+ napi_property_attributes attributes,
91
+ void* data) {
96
92
  return Accessor(utf8name.c_str(), getter, setter, attributes, data);
97
93
  }
98
94
 
99
95
  template <typename Getter, typename Setter>
100
- inline PropertyDescriptor PropertyDescriptor::Accessor(napi_value name,
101
- Getter getter,
102
- Setter setter,
103
- napi_property_attributes attributes,
104
- void* /*data*/) {
96
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
97
+ napi_value name,
98
+ Getter getter,
99
+ Setter setter,
100
+ napi_property_attributes attributes,
101
+ void* /*data*/) {
105
102
  using CbData = details::AccessorCallbackData<Getter, Setter>;
106
103
  // TODO: Delete when the function is destroyed
107
- auto callbackData = new CbData({ getter, setter, nullptr });
108
-
109
- return PropertyDescriptor({
110
- nullptr,
111
- name,
112
- nullptr,
113
- CbData::GetterWrapper,
114
- CbData::SetterWrapper,
115
- nullptr,
116
- attributes,
117
- callbackData
118
- });
104
+ auto callbackData = new CbData({getter, setter, nullptr});
105
+
106
+ return PropertyDescriptor({nullptr,
107
+ name,
108
+ nullptr,
109
+ CbData::GetterWrapper,
110
+ CbData::SetterWrapper,
111
+ nullptr,
112
+ attributes,
113
+ callbackData});
119
114
  }
120
115
 
121
116
  template <typename Getter, typename Setter>
122
- inline PropertyDescriptor PropertyDescriptor::Accessor(Name name,
123
- Getter getter,
124
- Setter setter,
125
- napi_property_attributes attributes,
126
- void* data) {
117
+ inline PropertyDescriptor PropertyDescriptor::Accessor(
118
+ Name name,
119
+ Getter getter,
120
+ Setter setter,
121
+ napi_property_attributes attributes,
122
+ void* data) {
127
123
  napi_value nameValue = name;
128
- return PropertyDescriptor::Accessor(nameValue, getter, setter, attributes, data);
124
+ return PropertyDescriptor::Accessor(
125
+ nameValue, getter, setter, attributes, data);
129
126
  }
130
127
 
131
128
  template <typename Callable>
132
- inline PropertyDescriptor PropertyDescriptor::Function(const char* utf8name,
133
- Callable cb,
134
- napi_property_attributes attributes,
135
- void* /*data*/) {
129
+ inline PropertyDescriptor PropertyDescriptor::Function(
130
+ const char* utf8name,
131
+ Callable cb,
132
+ napi_property_attributes attributes,
133
+ void* /*data*/) {
136
134
  using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
137
135
  using CbData = details::CallbackData<Callable, ReturnType>;
138
136
  // TODO: Delete when the function is destroyed
139
- auto callbackData = new CbData({ cb, nullptr });
140
-
141
- return PropertyDescriptor({
142
- utf8name,
143
- nullptr,
144
- CbData::Wrapper,
145
- nullptr,
146
- nullptr,
147
- nullptr,
148
- attributes,
149
- callbackData
150
- });
137
+ auto callbackData = new CbData({cb, nullptr});
138
+
139
+ return PropertyDescriptor({utf8name,
140
+ nullptr,
141
+ CbData::Wrapper,
142
+ nullptr,
143
+ nullptr,
144
+ nullptr,
145
+ attributes,
146
+ callbackData});
151
147
  }
152
148
 
153
149
  template <typename Callable>
154
- inline PropertyDescriptor PropertyDescriptor::Function(const std::string& utf8name,
155
- Callable cb,
156
- napi_property_attributes attributes,
157
- void* data) {
150
+ inline PropertyDescriptor PropertyDescriptor::Function(
151
+ const std::string& utf8name,
152
+ Callable cb,
153
+ napi_property_attributes attributes,
154
+ void* data) {
158
155
  return Function(utf8name.c_str(), cb, attributes, data);
159
156
  }
160
157
 
161
158
  template <typename Callable>
162
- inline PropertyDescriptor PropertyDescriptor::Function(napi_value name,
163
- Callable cb,
164
- napi_property_attributes attributes,
165
- void* /*data*/) {
159
+ inline PropertyDescriptor PropertyDescriptor::Function(
160
+ napi_value name,
161
+ Callable cb,
162
+ napi_property_attributes attributes,
163
+ void* /*data*/) {
166
164
  using ReturnType = decltype(cb(CallbackInfo(nullptr, nullptr)));
167
165
  using CbData = details::CallbackData<Callable, ReturnType>;
168
166
  // TODO: Delete when the function is destroyed
169
- auto callbackData = new CbData({ cb, nullptr });
170
-
171
- return PropertyDescriptor({
172
- nullptr,
173
- name,
174
- CbData::Wrapper,
175
- nullptr,
176
- nullptr,
177
- nullptr,
178
- attributes,
179
- callbackData
180
- });
167
+ auto callbackData = new CbData({cb, nullptr});
168
+
169
+ return PropertyDescriptor({nullptr,
170
+ name,
171
+ CbData::Wrapper,
172
+ nullptr,
173
+ nullptr,
174
+ nullptr,
175
+ attributes,
176
+ callbackData});
181
177
  }
182
178
 
183
179
  template <typename Callable>
184
- inline PropertyDescriptor PropertyDescriptor::Function(Name name,
185
- Callable cb,
186
- napi_property_attributes attributes,
187
- void* data) {
180
+ inline PropertyDescriptor PropertyDescriptor::Function(
181
+ Name name, Callable cb, napi_property_attributes attributes, void* data) {
188
182
  napi_value nameValue = name;
189
183
  return PropertyDescriptor::Function(nameValue, cb, attributes, data);
190
184
  }
191
185
 
192
- #endif // !SRC_NAPI_INL_DEPRECATED_H_
186
+ #endif // !SRC_NAPI_INL_DEPRECATED_H_