koffi 2.7.2 → 2.7.3

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 (65) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm32hf/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
  11. package/build/koffi/linux_x64/koffi.node +0 -0
  12. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  13. package/build/koffi/openbsd_x64/koffi.node +0 -0
  14. package/build/koffi/win32_arm64/koffi.node +0 -0
  15. package/build/koffi/win32_ia32/koffi.node +0 -0
  16. package/build/koffi/win32_x64/koffi.node +0 -0
  17. package/doc/misc.md +1 -1
  18. package/index.js +2 -2
  19. package/indirect.js +2 -2
  20. package/package.json +2 -2
  21. package/src/koffi/src/call.cc +1 -1
  22. package/src/koffi/src/util.cc +7 -13
  23. package/src/koffi/src/util.hh +9 -1
  24. package/vendor/node-addon-api/CHANGELOG.md +76 -0
  25. package/vendor/node-addon-api/LICENSE.md +2 -6
  26. package/vendor/node-addon-api/README.md +10 -9
  27. package/vendor/node-addon-api/benchmark/binding.gyp +4 -4
  28. package/vendor/node-addon-api/common.gypi +1 -2
  29. package/vendor/node-addon-api/doc/array.md +1 -1
  30. package/vendor/node-addon-api/doc/async_worker_variants.md +16 -16
  31. package/vendor/node-addon-api/doc/cmake-js.md +1 -1
  32. package/vendor/node-addon-api/doc/env.md +11 -0
  33. package/vendor/node-addon-api/doc/hierarchy.md +2 -0
  34. package/vendor/node-addon-api/doc/setup.md +53 -71
  35. package/vendor/node-addon-api/doc/syntax_error.md +66 -0
  36. package/vendor/node-addon-api/doc/value.md +2 -0
  37. package/vendor/node-addon-api/index.js +2 -1
  38. package/vendor/node-addon-api/napi-inl.h +68 -65
  39. package/vendor/node-addon-api/napi.h +15 -5
  40. package/vendor/node-addon-api/node_addon_api.gyp +32 -0
  41. package/vendor/node-addon-api/package.json +14 -3
  42. package/vendor/node-addon-api/test/addon.cc +7 -1
  43. package/vendor/node-addon-api/test/addon.js +5 -9
  44. package/vendor/node-addon-api/test/addon_data.cc +3 -3
  45. package/vendor/node-addon-api/test/addon_data.js +16 -38
  46. package/vendor/node-addon-api/test/bigint.cc +0 -1
  47. package/vendor/node-addon-api/test/binding.cc +12 -1
  48. package/vendor/node-addon-api/test/binding.gyp +10 -8
  49. package/vendor/node-addon-api/test/child_processes/addon.js +11 -0
  50. package/vendor/node-addon-api/test/child_processes/addon_data.js +24 -0
  51. package/vendor/node-addon-api/test/child_processes/objectwrap_function.js +22 -0
  52. package/vendor/node-addon-api/test/child_processes/threadsafe_function_exception.js +33 -0
  53. package/vendor/node-addon-api/test/child_processes/typed_threadsafe_function_exception.js +19 -0
  54. package/vendor/node-addon-api/test/common/index.js +57 -3
  55. package/vendor/node-addon-api/test/env_misc.cc +25 -0
  56. package/vendor/node-addon-api/test/env_misc.js +12 -0
  57. package/vendor/node-addon-api/test/error.cc +47 -0
  58. package/vendor/node-addon-api/test/error.js +16 -0
  59. package/vendor/node-addon-api/test/index.js +5 -0
  60. package/vendor/node-addon-api/test/objectwrap_function.cc +10 -12
  61. package/vendor/node-addon-api/test/objectwrap_function.js +4 -20
  62. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.cc +50 -0
  63. package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_exception.js +20 -0
  64. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.cc +39 -0
  65. package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_exception.js +13 -0
@@ -17,84 +17,66 @@ To use **Node-API** in a native module:
17
17
 
18
18
  1. Add a dependency on this package to `package.json`:
19
19
 
20
- ```json
21
- "dependencies": {
22
- "node-addon-api": "*",
23
- }
24
- ```
25
-
26
- 2. Reference this package's include directory and gyp file in `binding.gyp`:
27
-
28
- ```gyp
29
- 'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
30
- ```
31
-
32
- 3. Decide whether the package will enable C++ exceptions in the Node-API wrapper.
20
+ ```json
21
+ "dependencies": {
22
+ "node-addon-api": "*",
23
+ }
24
+ ```
25
+
26
+ 2. Decide whether the package will enable C++ exceptions in the Node-API
27
+ wrapper, and reference this package as a dependency in `binding.gyp`.
33
28
  The base ABI-stable C APIs do not throw or handle C++ exceptions, but the
34
29
  Node-API C++ wrapper classes may _optionally_
35
30
  [integrate C++ and JavaScript exception-handling
36
31
  ](https://github.com/nodejs/node-addon-api/blob/HEAD/doc/error_handling.md).
37
- To enable that capability, C++ exceptions must be enabled in `binding.gyp`:
38
-
39
- ```gyp
40
- 'cflags!': [ '-fno-exceptions' ],
41
- 'cflags_cc!': [ '-fno-exceptions' ],
42
- 'conditions': [
43
- ["OS=='win'", {
44
- "defines": [
45
- "_HAS_EXCEPTIONS=1"
46
- ],
47
- "msvs_settings": {
48
- "VCCLCompilerTool": {
49
- "ExceptionHandling": 1
50
- },
51
- },
52
- }],
53
- ["OS=='mac'", {
54
- 'xcode_settings': {
55
- 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
56
- 'CLANG_CXX_LIBRARY': 'libc++',
57
- 'MACOSX_DEPLOYMENT_TARGET': '10.7',
58
- },
59
- }],
60
- ],
61
- ```
62
-
63
- Alternatively, disable use of C++ exceptions in Node-API:
64
-
65
- ```gyp
66
- 'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
67
- ```
68
-
69
- If you decide to use node-addon-api without C++ exceptions enabled, please
70
- consider enabling node-addon-api safe API type guards to ensure the proper
71
- exception handling pattern:
72
-
73
- ```gyp
74
- 'defines': [ 'NODE_ADDON_API_ENABLE_MAYBE' ],
75
- ```
76
-
77
- 4. If you would like your native addon to support OSX, please also add the
78
- following settings in the `binding.gyp` file:
79
-
80
- ```gyp
81
- 'conditions': [
82
- ['OS=="mac"', {
83
- 'cflags+': ['-fvisibility=hidden'],
84
- 'xcode_settings': {
85
- 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
86
- }
87
- }]
88
- ]
89
- ```
90
-
91
- 5. Include `napi.h` in the native module code.
32
+
33
+ To use without C++ exceptions, add the following to `binding.gyp`:
34
+
35
+ ```gyp
36
+ 'dependencies': [
37
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api",
38
+ ],
39
+ ```
40
+
41
+ To enable that capability, add an alternative dependency in `binding.gyp`:
42
+
43
+ ```gyp
44
+ 'dependencies': [
45
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
46
+ ],
47
+ ```
48
+
49
+ If you decide to use node-addon-api without C++ exceptions enabled, please
50
+ consider enabling node-addon-api safe API type guards to ensure the proper
51
+ exception handling pattern:
52
+
53
+ ```gyp
54
+ 'dependencies': [
55
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_maybe",
56
+ ],
57
+ ```
58
+
59
+ 3. If you would like your native addon to support OSX, please also add the
60
+ following settings in the `binding.gyp` file:
61
+
62
+ ```gyp
63
+ 'conditions': [
64
+ ['OS=="mac"', {
65
+ 'cflags+': ['-fvisibility=hidden'],
66
+ 'xcode_settings': {
67
+ 'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
68
+ }
69
+ }]
70
+ ]
71
+ ```
72
+
73
+ 4. Include `napi.h` in the native module code.
92
74
  To ensure only ABI-stable APIs are used, DO NOT include
93
75
  `node.h`, `nan.h`, or `v8.h`.
94
76
 
95
- ```C++
96
- #include "napi.h"
97
- ```
77
+ ```C++
78
+ #include "napi.h"
79
+ ```
98
80
 
99
81
  At build time, the Node-API back-compat library code will be used only when the
100
82
  targeted node version *does not* have Node-API built-in.
@@ -0,0 +1,66 @@
1
+ # SyntaxError
2
+
3
+ The `Napi::SyntaxError` class is a representation of the JavaScript
4
+ `SyntaxError` that is thrown when the engine encounters tokens or token order
5
+ that does not conform to the syntax of the language when parsing code.
6
+
7
+ The `Napi::SyntaxError` class inherits its behaviors from the `Napi::Error`
8
+ class (for more info see: [`Napi::Error`](error.md)).
9
+
10
+ For more details about error handling refer to the section titled [Error
11
+ handling](error_handling.md).
12
+
13
+ ## Methods
14
+
15
+ ### New
16
+
17
+ Creates a new instance of a `Napi::SyntaxError` object.
18
+
19
+ ```cpp
20
+ Napi::SyntaxError::New(Napi::Env env, const char* message);
21
+ ```
22
+
23
+ - `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
24
+ object.
25
+ - `[in] message`: Null-terminated string to be used as the message for the
26
+ `Napi::SyntaxError`.
27
+
28
+ Returns an instance of a `Napi::SyntaxError` object.
29
+
30
+ ### New
31
+
32
+ Creates a new instance of a `Napi::SyntaxError` object.
33
+
34
+ ```cpp
35
+ Napi::SyntaxError::New(Napi::Env env, const std::string& message);
36
+ ```
37
+
38
+ - `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
39
+ object.
40
+ - `[in] message`: Reference string to be used as the message for the
41
+ `Napi::SyntaxError`.
42
+
43
+ Returns an instance of a `Napi::SyntaxError` object.
44
+
45
+ ### Constructor
46
+
47
+ Creates a new empty instance of a `Napi::SyntaxError`.
48
+
49
+ ```cpp
50
+ Napi::SyntaxError::SyntaxError();
51
+ ```
52
+
53
+ ### Constructor
54
+
55
+ Initializes a `Napi::SyntaxError` instance from an existing Javascript error
56
+ object.
57
+
58
+ ```cpp
59
+ Napi::SyntaxError::SyntaxError(napi_env env, napi_value value);
60
+ ```
61
+
62
+ - `[in] Env`: The environment in which to construct the `Napi::SyntaxError`
63
+ object.
64
+ - `[in] value`: The `Napi::Error` reference to wrap.
65
+
66
+ Returns an instance of a `Napi::SyntaxError` object.
@@ -141,6 +141,8 @@ bool Napi::Value::IsArrayBuffer() const;
141
141
  Returns `true` if the underlying value is a JavaScript `Napi::ArrayBuffer` or
142
142
  `false` otherwise.
143
143
 
144
+ ### IsBigInt
145
+
144
146
  ```cpp
145
147
  bool Napi::Value::IsBigInt() const;
146
148
  ```
@@ -5,7 +5,8 @@ const includeDir = path.relative('.', __dirname);
5
5
  module.exports = {
6
6
  include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
7
7
  include_dir: includeDir,
8
- gyp: path.join(includeDir, 'node_api.gyp:nothing'),
8
+ gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
9
+ targets: path.join(includeDir, 'node_addon_api.gyp'),
9
10
  isNodeApiBuiltin: true,
10
11
  needsFlag: false
11
12
  };
@@ -31,22 +31,22 @@ namespace details {
31
31
  // Node.js releases. Only necessary when they are used in napi.h and napi-inl.h.
32
32
  constexpr int napi_no_external_buffers_allowed = 22;
33
33
 
34
+ template <typename FreeType>
35
+ inline void default_finalizer(napi_env /*env*/, void* data, void* /*hint*/) {
36
+ delete static_cast<FreeType*>(data);
37
+ }
38
+
34
39
  // Attach a data item to an object and delete it when the object gets
35
40
  // garbage-collected.
36
41
  // TODO: Replace this code with `napi_add_finalizer()` whenever it becomes
37
42
  // available on all supported versions of Node.js.
38
- template <typename FreeType>
43
+ template <typename FreeType,
44
+ napi_finalize finalizer = default_finalizer<FreeType>>
39
45
  inline napi_status AttachData(napi_env env,
40
46
  napi_value obj,
41
47
  FreeType* data,
42
- napi_finalize finalizer = nullptr,
43
48
  void* hint = nullptr) {
44
49
  napi_status status;
45
- if (finalizer == nullptr) {
46
- finalizer = [](napi_env /*env*/, void* data, void* /*hint*/) {
47
- delete static_cast<FreeType*>(data);
48
- };
49
- }
50
50
  #if (NAPI_VERSION < 5)
51
51
  napi_value symbol, external;
52
52
  status = napi_create_symbol(env, nullptr, &symbol);
@@ -263,10 +263,12 @@ struct ThreadSafeFinalize {
263
263
  template <typename ContextType, typename DataType, typename CallJs, CallJs call>
264
264
  inline typename std::enable_if<call != static_cast<CallJs>(nullptr)>::type
265
265
  CallJsWrapper(napi_env env, napi_value jsCallback, void* context, void* data) {
266
- call(env,
267
- Function(env, jsCallback),
268
- static_cast<ContextType*>(context),
269
- static_cast<DataType*>(data));
266
+ details::WrapVoidCallback([&]() {
267
+ call(env,
268
+ Function(env, jsCallback),
269
+ static_cast<ContextType*>(context),
270
+ static_cast<DataType*>(data));
271
+ });
270
272
  }
271
273
 
272
274
  template <typename ContextType, typename DataType, typename CallJs, CallJs call>
@@ -275,9 +277,11 @@ CallJsWrapper(napi_env env,
275
277
  napi_value jsCallback,
276
278
  void* /*context*/,
277
279
  void* /*data*/) {
278
- if (jsCallback != nullptr) {
279
- Function(env, jsCallback).Call(0, nullptr);
280
- }
280
+ details::WrapVoidCallback([&]() {
281
+ if (jsCallback != nullptr) {
282
+ Function(env, jsCallback).Call(0, nullptr);
283
+ }
284
+ });
281
285
  }
282
286
 
283
287
  #if NAPI_VERSION > 4
@@ -572,6 +576,14 @@ void Env::DefaultFiniWithHint(Env, DataType* data, HintType*) {
572
576
  }
573
577
  #endif // NAPI_VERSION > 5
574
578
 
579
+ #if NAPI_VERSION > 8
580
+ inline const char* Env::GetModuleFileName() const {
581
+ const char* result;
582
+ napi_status status = node_api_get_module_file_name(_env, &result);
583
+ NAPI_THROW_IF_FAILED(*this, status, nullptr);
584
+ return result;
585
+ }
586
+ #endif // NAPI_VERSION > 8
575
587
  ////////////////////////////////////////////////////////////////////////////////
576
588
  // Value class
577
589
  ////////////////////////////////////////////////////////////////////////////////
@@ -1624,11 +1636,8 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback, T* data) const {
1624
1636
  new details::FinalizeData<T, Finalizer>(
1625
1637
  {std::move(finalizeCallback), nullptr});
1626
1638
  napi_status status =
1627
- details::AttachData(_env,
1628
- *this,
1629
- data,
1630
- details::FinalizeData<T, Finalizer>::Wrapper,
1631
- finalizeData);
1639
+ details::AttachData<T, details::FinalizeData<T, Finalizer>::Wrapper>(
1640
+ _env, *this, data, finalizeData);
1632
1641
  if (status != napi_ok) {
1633
1642
  delete finalizeData;
1634
1643
  NAPI_THROW_IF_FAILED_VOID(_env, status);
@@ -1642,12 +1651,9 @@ inline void Object::AddFinalizer(Finalizer finalizeCallback,
1642
1651
  details::FinalizeData<T, Finalizer, Hint>* finalizeData =
1643
1652
  new details::FinalizeData<T, Finalizer, Hint>(
1644
1653
  {std::move(finalizeCallback), finalizeHint});
1645
- napi_status status = details::AttachData(
1646
- _env,
1647
- *this,
1648
- data,
1649
- details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint,
1650
- finalizeData);
1654
+ napi_status status = details::
1655
+ AttachData<T, details::FinalizeData<T, Finalizer, Hint>::WrapperWithHint>(
1656
+ _env, *this, data, finalizeData);
1651
1657
  if (status != napi_ok) {
1652
1658
  delete finalizeData;
1653
1659
  NAPI_THROW_IF_FAILED_VOID(_env, status);
@@ -2623,7 +2629,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env, size_t length) {
2623
2629
  napi_status status =
2624
2630
  napi_create_buffer(env, length * sizeof(T), &data, &value);
2625
2631
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2626
- return Buffer(env, value, length, static_cast<T*>(data));
2632
+ return Buffer(env, value);
2627
2633
  }
2628
2634
 
2629
2635
  #ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
@@ -2633,7 +2639,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env, T* data, size_t length) {
2633
2639
  napi_status status = napi_create_external_buffer(
2634
2640
  env, length * sizeof(T), data, nullptr, nullptr, &value);
2635
2641
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2636
- return Buffer(env, value, length, data);
2642
+ return Buffer(env, value);
2637
2643
  }
2638
2644
 
2639
2645
  template <typename T>
@@ -2657,7 +2663,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
2657
2663
  delete finalizeData;
2658
2664
  NAPI_THROW_IF_FAILED(env, status, Buffer());
2659
2665
  }
2660
- return Buffer(env, value, length, data);
2666
+ return Buffer(env, value);
2661
2667
  }
2662
2668
 
2663
2669
  template <typename T>
@@ -2682,7 +2688,7 @@ inline Buffer<T> Buffer<T>::New(napi_env env,
2682
2688
  delete finalizeData;
2683
2689
  NAPI_THROW_IF_FAILED(env, status, Buffer());
2684
2690
  }
2685
- return Buffer(env, value, length, data);
2691
+ return Buffer(env, value);
2686
2692
  }
2687
2693
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
2688
2694
 
@@ -2699,7 +2705,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env, T* data, size_t length) {
2699
2705
  #ifndef NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
2700
2706
  }
2701
2707
  NAPI_THROW_IF_FAILED(env, status, Buffer<T>());
2702
- return Buffer(env, value, length, data);
2708
+ return Buffer(env, value);
2703
2709
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
2704
2710
  }
2705
2711
 
@@ -2733,7 +2739,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
2733
2739
  delete finalizeData;
2734
2740
  NAPI_THROW_IF_FAILED(env, status, Buffer());
2735
2741
  }
2736
- return Buffer(env, value, length, data);
2742
+ return Buffer(env, value);
2737
2743
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
2738
2744
  }
2739
2745
 
@@ -2769,7 +2775,7 @@ inline Buffer<T> Buffer<T>::NewOrCopy(napi_env env,
2769
2775
  delete finalizeData;
2770
2776
  NAPI_THROW_IF_FAILED(env, status, Buffer());
2771
2777
  }
2772
- return Buffer(env, value, length, data);
2778
+ return Buffer(env, value);
2773
2779
  #endif
2774
2780
  }
2775
2781
 
@@ -2793,42 +2799,20 @@ inline void Buffer<T>::CheckCast(napi_env env, napi_value value) {
2793
2799
  }
2794
2800
 
2795
2801
  template <typename T>
2796
- inline Buffer<T>::Buffer() : Uint8Array(), _length(0), _data(nullptr) {}
2802
+ inline Buffer<T>::Buffer() : Uint8Array() {}
2797
2803
 
2798
2804
  template <typename T>
2799
2805
  inline Buffer<T>::Buffer(napi_env env, napi_value value)
2800
- : Uint8Array(env, value), _length(0), _data(nullptr) {}
2801
-
2802
- template <typename T>
2803
- inline Buffer<T>::Buffer(napi_env env, napi_value value, size_t length, T* data)
2804
- : Uint8Array(env, value), _length(length), _data(data) {}
2806
+ : Uint8Array(env, value) {}
2805
2807
 
2806
2808
  template <typename T>
2807
2809
  inline size_t Buffer<T>::Length() const {
2808
- EnsureInfo();
2809
- return _length;
2810
+ return ByteLength() / sizeof(T);
2810
2811
  }
2811
2812
 
2812
2813
  template <typename T>
2813
2814
  inline T* Buffer<T>::Data() const {
2814
- EnsureInfo();
2815
- return _data;
2816
- }
2817
-
2818
- template <typename T>
2819
- inline void Buffer<T>::EnsureInfo() const {
2820
- // The Buffer instance may have been constructed from a napi_value whose
2821
- // length/data are not yet known. Fetch and cache these values just once,
2822
- // since they can never change during the lifetime of the Buffer.
2823
- if (_data == nullptr) {
2824
- size_t byteLength;
2825
- void* voidData;
2826
- napi_status status =
2827
- napi_get_buffer_info(_env, _value, &voidData, &byteLength);
2828
- NAPI_THROW_IF_FAILED_VOID(_env, status);
2829
- _length = byteLength / sizeof(T);
2830
- _data = static_cast<T*>(voidData);
2831
- }
2815
+ return reinterpret_cast<T*>(const_cast<uint8_t*>(Uint8Array::Data()));
2832
2816
  }
2833
2817
 
2834
2818
  ////////////////////////////////////////////////////////////////////////////////
@@ -3157,6 +3141,23 @@ inline RangeError::RangeError() : Error() {}
3157
3141
  inline RangeError::RangeError(napi_env env, napi_value value)
3158
3142
  : Error(env, value) {}
3159
3143
 
3144
+ #if NAPI_VERSION > 8
3145
+ inline SyntaxError SyntaxError::New(napi_env env, const char* message) {
3146
+ return Error::New<SyntaxError>(
3147
+ env, message, std::strlen(message), node_api_create_syntax_error);
3148
+ }
3149
+
3150
+ inline SyntaxError SyntaxError::New(napi_env env, const std::string& message) {
3151
+ return Error::New<SyntaxError>(
3152
+ env, message.c_str(), message.size(), node_api_create_syntax_error);
3153
+ }
3154
+
3155
+ inline SyntaxError::SyntaxError() : Error() {}
3156
+
3157
+ inline SyntaxError::SyntaxError(napi_env env, napi_value value)
3158
+ : Error(env, value) {}
3159
+ #endif // NAPI_VERSION > 8
3160
+
3160
3161
  ////////////////////////////////////////////////////////////////////////////////
3161
3162
  // Reference<T> class
3162
3163
  ////////////////////////////////////////////////////////////////////////////////
@@ -6110,13 +6111,15 @@ inline void ThreadSafeFunction::CallJS(napi_env env,
6110
6111
  return;
6111
6112
  }
6112
6113
 
6113
- if (data != nullptr) {
6114
- auto* callbackWrapper = static_cast<CallbackWrapper*>(data);
6115
- (*callbackWrapper)(env, Function(env, jsCallback));
6116
- delete callbackWrapper;
6117
- } else if (jsCallback != nullptr) {
6118
- Function(env, jsCallback).Call({});
6119
- }
6114
+ details::WrapVoidCallback([&]() {
6115
+ if (data != nullptr) {
6116
+ auto* callbackWrapper = static_cast<CallbackWrapper*>(data);
6117
+ (*callbackWrapper)(env, Function(env, jsCallback));
6118
+ delete callbackWrapper;
6119
+ } else if (jsCallback != nullptr) {
6120
+ Function(env, jsCallback).Call({});
6121
+ }
6122
+ });
6120
6123
  }
6121
6124
 
6122
6125
  ////////////////////////////////////////////////////////////////////////////////
@@ -367,6 +367,10 @@ class Env {
367
367
  } * data;
368
368
  };
369
369
  #endif // NAPI_VERSION > 2
370
+
371
+ #if NAPI_VERSION > 8
372
+ const char* GetModuleFileName() const;
373
+ #endif // NAPI_VERSION > 8
370
374
  };
371
375
 
372
376
  /// A JavaScript value of unknown type.
@@ -1531,11 +1535,6 @@ class Buffer : public Uint8Array {
1531
1535
  T* Data() const;
1532
1536
 
1533
1537
  private:
1534
- mutable size_t _length;
1535
- mutable T* _data;
1536
-
1537
- Buffer(napi_env env, napi_value value, size_t length, T* data);
1538
- void EnsureInfo() const;
1539
1538
  };
1540
1539
 
1541
1540
  /// Holds a counted reference to a value; initially a weak reference unless
@@ -1853,6 +1852,17 @@ class RangeError : public Error {
1853
1852
  RangeError(napi_env env, napi_value value);
1854
1853
  };
1855
1854
 
1855
+ #if NAPI_VERSION > 8
1856
+ class SyntaxError : public Error {
1857
+ public:
1858
+ static SyntaxError New(napi_env env, const char* message);
1859
+ static SyntaxError New(napi_env env, const std::string& message);
1860
+
1861
+ SyntaxError();
1862
+ SyntaxError(napi_env env, napi_value value);
1863
+ };
1864
+ #endif // NAPI_VERSION > 8
1865
+
1856
1866
  class CallbackInfo {
1857
1867
  public:
1858
1868
  CallbackInfo(napi_env env, napi_callback_info info);
@@ -0,0 +1,32 @@
1
+ {
2
+ 'targets': [
3
+ {
4
+ 'target_name': 'node_addon_api',
5
+ 'type': 'none',
6
+ 'sources': [ 'napi.h', 'napi-inl.h' ],
7
+ 'direct_dependent_settings': {
8
+ 'include_dirs': [ '.' ],
9
+ 'includes': ['noexcept.gypi'],
10
+ }
11
+ },
12
+ {
13
+ 'target_name': 'node_addon_api_except',
14
+ 'type': 'none',
15
+ 'sources': [ 'napi.h', 'napi-inl.h' ],
16
+ 'direct_dependent_settings': {
17
+ 'include_dirs': [ '.' ],
18
+ 'includes': ['except.gypi'],
19
+ }
20
+ },
21
+ {
22
+ 'target_name': 'node_addon_api_maybe',
23
+ 'type': 'none',
24
+ 'sources': [ 'napi.h', 'napi-inl.h' ],
25
+ 'direct_dependent_settings': {
26
+ 'include_dirs': [ '.' ],
27
+ 'includes': ['noexcept.gypi'],
28
+ 'defines': ['NODE_ADDON_API_ENABLE_MAYBE']
29
+ }
30
+ },
31
+ ]
32
+ }
@@ -407,6 +407,14 @@
407
407
  {
408
408
  "name": "Caleb Hearon",
409
409
  "url": "https://github.com/chearon"
410
+ },
411
+ {
412
+ "name": "Marx",
413
+ "url": "https://github.com/MarxJiao"
414
+ },
415
+ {
416
+ "name": "Ömer AKGÜL",
417
+ "url": "https://github.com/tuhalf"
410
418
  }
411
419
  ],
412
420
  "description": "Node.js API (Node-API)",
@@ -420,7 +428,7 @@
420
428
  "eslint-plugin-import": "^2.24.2",
421
429
  "eslint-plugin-node": "^11.1.0",
422
430
  "eslint-plugin-promise": "^5.1.0",
423
- "fs-extra": "^9.0.1",
431
+ "fs-extra": "^11.1.1",
424
432
  "path": "^0.12.7",
425
433
  "pre-commit": "^1.2.2",
426
434
  "safe-buffer": "^5.1.1"
@@ -467,6 +475,9 @@
467
475
  "lint:fix": "node tools/clang-format --fix && node tools/eslint-format --fix"
468
476
  },
469
477
  "pre-commit": "lint",
470
- "version": "7.0.0",
471
- "support": true
478
+ "version": "7.1.0",
479
+ "support": true,
480
+ "engines": {
481
+ "node": "^16 || ^18 || >= 20"
482
+ }
472
483
  }
@@ -17,6 +17,8 @@ class TestAddon : public Napi::Addon<TestAddon> {
17
17
  {InstanceMethod("decrement", &TestAddon::Decrement)}))});
18
18
  }
19
19
 
20
+ ~TestAddon() { fprintf(stderr, "TestAddon::~TestAddon\n"); }
21
+
20
22
  private:
21
23
  Napi::Value Increment(const Napi::CallbackInfo& info) {
22
24
  return Napi::Number::New(info.Env(), ++value);
@@ -29,10 +31,14 @@ class TestAddon : public Napi::Addon<TestAddon> {
29
31
  uint32_t value = 42;
30
32
  };
31
33
 
34
+ Napi::Value CreateAddon(const Napi::CallbackInfo& info) {
35
+ return TestAddon::Init(info.Env(), Napi::Object::New(info.Env()));
36
+ }
37
+
32
38
  } // end of anonymous namespace
33
39
 
34
40
  Napi::Object InitAddon(Napi::Env env) {
35
- return TestAddon::Init(env, Napi::Object::New(env));
41
+ return Napi::Function::New<CreateAddon>(env, "CreateAddon");
36
42
  }
37
43
 
38
44
  #endif // (NAPI_VERSION > 5)
@@ -1,11 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const assert = require('assert');
4
-
5
- module.exports = require('./common').runTest(test);
6
-
7
- function test (binding) {
8
- assert.strictEqual(binding.addon.increment(), 43);
9
- assert.strictEqual(binding.addon.increment(), 44);
10
- assert.strictEqual(binding.addon.subObject.decrement(), 43);
11
- }
3
+ module.exports = require('./common').runTestInChildProcess({
4
+ suite: 'addon',
5
+ testName: 'workingCode',
6
+ expectedStderr: ['TestAddon::~TestAddon']
7
+ });
@@ -4,10 +4,10 @@
4
4
  #include "test_helper.h"
5
5
 
6
6
  // An overly elaborate way to get/set a boolean stored in the instance data:
7
- // 0. A boolean named "verbose" is stored in the instance data. The constructor
8
- // for JS `VerboseIndicator` instances is also stored in the instance data.
7
+ // 0. The constructor for JS `VerboseIndicator` instances, which have a private
8
+ // member named "verbose", is stored in the instance data.
9
9
  // 1. Add a property named "verbose" onto exports served by a getter/setter.
10
- // 2. The getter returns a object of type VerboseIndicator, which itself has a
10
+ // 2. The getter returns an object of type VerboseIndicator, which itself has a
11
11
  // property named "verbose", also served by a getter/setter:
12
12
  // * The getter returns a boolean, indicating whether "verbose" is set.
13
13
  // * The setter sets "verbose" on the instance data.