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
@@ -0,0 +1,145 @@
1
+ # node-addon-api Documents
2
+
3
+ * [Setup](#setup)
4
+ * [API Documentation](#api)
5
+ * [Examples](#examples)
6
+ * [ABI Stability Guideline](#abi-stability-guideline)
7
+ * [More resource and info about native Addons](#resources)
8
+
9
+ Node-API is an ABI stable C interface provided by Node.js for building native
10
+ addons. It is independent of the underlying JavaScript runtime (e.g. V8 or ChakraCore)
11
+ and is maintained as part of Node.js itself. It is intended to insulate
12
+ native addons from changes in the underlying JavaScript engine and allow
13
+ modules compiled for one version to run on later versions of Node.js without
14
+ recompilation.
15
+
16
+ The `node-addon-api` module, which is not part of Node.js, preserves the benefits
17
+ of the Node-API as it consists only of inline code that depends only on the stable API
18
+ provided by Node-API. As such, modules built against one version of Node.js
19
+ using node-addon-api should run without having to be rebuilt with newer versions
20
+ of Node.js.
21
+
22
+ ## Setup
23
+ - [Installation and usage](setup.md)
24
+ - [node-gyp](node-gyp.md)
25
+ - [cmake-js](cmake-js.md)
26
+ - [Conversion tool](conversion-tool.md)
27
+ - [Checker tool](checker-tool.md)
28
+ - [Generator](generator.md)
29
+ - [Prebuild tools](prebuild_tools.md)
30
+
31
+ <a name="api"></a>
32
+
33
+ ## API Documentation
34
+
35
+ The following is the documentation for node-addon-api.
36
+
37
+ - [Full Class Hierarchy](hierarchy.md)
38
+ - [Addon Structure](addon.md)
39
+ - Data Types:
40
+ - [BasicEnv](basic_env.md)
41
+ - [Env](env.md)
42
+ - [CallbackInfo](callbackinfo.md)
43
+ - [Reference](reference.md)
44
+ - [Value](value.md)
45
+ - [Name](name.md)
46
+ - [Symbol](symbol.md)
47
+ - [String](string.md)
48
+ - [Number](number.md)
49
+ - [Date](date.md)
50
+ - [BigInt](bigint.md)
51
+ - [Boolean](boolean.md)
52
+ - [External](external.md)
53
+ - [Object](object.md)
54
+ - [Array](array.md)
55
+ - [ObjectReference](object_reference.md)
56
+ - [PropertyDescriptor](property_descriptor.md)
57
+ - [Function](function.md)
58
+ - [FunctionReference](function_reference.md)
59
+ - [ObjectWrap](object_wrap.md)
60
+ - [ClassPropertyDescriptor](class_property_descriptor.md)
61
+ - [Buffer](buffer.md)
62
+ - [ArrayBuffer](array_buffer.md)
63
+ - [TypedArray](typed_array.md)
64
+ - [TypedArrayOf](typed_array_of.md)
65
+ - [DataView](dataview.md)
66
+ - [Error Handling](error_handling.md)
67
+ - [Error](error.md)
68
+ - [TypeError](type_error.md)
69
+ - [RangeError](range_error.md)
70
+ - [SyntaxError](syntax_error.md)
71
+ - [Object Lifetime Management](object_lifetime_management.md)
72
+ - [HandleScope](handle_scope.md)
73
+ - [EscapableHandleScope](escapable_handle_scope.md)
74
+ - [Finalization](finalization.md)
75
+ - [Memory Management](memory_management.md)
76
+ - [Async Operations](async_operations.md)
77
+ - [AsyncWorker](async_worker.md)
78
+ - [AsyncContext](async_context.md)
79
+ - [AsyncWorker Variants](async_worker_variants.md)
80
+ - [Thread-safe Functions](threadsafe.md)
81
+ - [ThreadSafeFunction](threadsafe_function.md)
82
+ - [TypedThreadSafeFunction](typed_threadsafe_function.md)
83
+ - [Promises](promises.md)
84
+ - [Version management](version_management.md)
85
+
86
+ <a name="examples"></a>
87
+
88
+ ## Examples
89
+
90
+ Are you new to **node-addon-api**? Take a look at our **[examples](https://github.com/nodejs/node-addon-examples)**
91
+
92
+ - [Hello World](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/1_hello_world)
93
+ - [Pass arguments to a function](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/2_function_arguments/node-addon-api)
94
+ - [Callbacks](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/3_callbacks/node-addon-api)
95
+ - [Object factory](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/4_object_factory/node-addon-api)
96
+ - [Function factory](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/5_function_factory/node-addon-api)
97
+ - [Wrapping C++ Object](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/6_object_wrap/node-addon-api)
98
+ - [Factory of wrapped object](https://github.com/nodejs/node-addon-examples/tree/main/src/1-getting-started/7_factory_wrap/node-addon-api)
99
+ - [Passing wrapped object around](https://github.com/nodejs/node-addon-examples/tree/main/src/2-js-to-native-conversion/8_passing_wrapped/node-addon-api)
100
+
101
+ <a name="abi-stability-guideline"></a>
102
+
103
+ ## ABI Stability Guideline
104
+
105
+ It is important to remember that *other* Node.js interfaces such as
106
+ `libuv` (included in a project via `#include <uv.h>`) are not ABI-stable across
107
+ Node.js major versions. Thus, an addon must use Node-API and/or `node-addon-api`
108
+ exclusively and build against a version of Node.js that includes an
109
+ implementation of Node-API (meaning an active LTS version of Node.js) in
110
+ order to benefit from ABI stability across Node.js major versions. Node.js
111
+ provides an [ABI stability guide][] containing a detailed explanation of ABI
112
+ stability in general, and the Node-API ABI stability guarantee in particular.
113
+
114
+ <a name="resources"></a>
115
+
116
+ ## More resource and info about native Addons
117
+
118
+ There are three options for implementing addons: Node-API, nan, or direct
119
+ use of internal V8, libuv, and Node.js libraries. Unless there is a need for
120
+ direct access to functionality that is not exposed by Node-API as outlined
121
+ in [C/C++ addons](https://nodejs.org/dist/latest/docs/api/addons.html)
122
+ in Node.js core, use Node-API. Refer to
123
+ [C/C++ addons with Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
124
+ for more information on Node-API.
125
+
126
+ - [C++ Addons](https://nodejs.org/dist/latest/docs/api/addons.html)
127
+ - [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
128
+ - [Node-API - Next Generation Node API for Native Modules](https://youtu.be/-Oniup60Afs)
129
+ - [How We Migrated Realm JavaScript From NAN to Node-API](https://developer.mongodb.com/article/realm-javascript-nan-to-n-api)
130
+
131
+ As node-addon-api's core mission is to expose the plain C Node-API as C++
132
+ wrappers, tools that facilitate n-api/node-addon-api providing more
133
+ convenient patterns for developing a Node.js add-on with n-api/node-addon-api
134
+ can be published to NPM as standalone packages. It is also recommended to tag
135
+ such packages with `node-addon-api` to provide more visibility to the community.
136
+
137
+ Quick links to NPM searches: [keywords:node-addon-api](https://www.npmjs.com/search?q=keywords%3Anode-addon-api).
138
+
139
+ <a name="other-bindings"></a>
140
+
141
+ ## Other bindings
142
+
143
+ - [napi-rs](https://napi.rs) - (`Rust`)
144
+
145
+ [ABI stability guide]: https://nodejs.org/en/docs/guides/abi-stability/
@@ -31,13 +31,13 @@ Wraps the provided external data into a new `Napi::ArrayBuffer` instance.
31
31
  The `Napi::ArrayBuffer` instance does not assume ownership for the data and
32
32
  expects it to be valid for the lifetime of the instance. Since the
33
33
  `Napi::ArrayBuffer` is subject to garbage collection this overload is only
34
- suitable for data which is static and never needs to be freed.
35
- This factory method will not provide the caller with an opportunity to free the
36
- data when the `Napi::ArrayBuffer` gets garbage-collected. If you need to free
37
- the data retained by the `Napi::ArrayBuffer` object please use other
38
- variants of the `Napi::ArrayBuffer::New` factory method that accept
39
- `Napi::Finalizer`, which is a function that will be invoked when the
40
- `Napi::ArrayBuffer` object has been destroyed.
34
+ suitable for data which is static and never needs to be freed. This factory
35
+ method will not provide the caller with an opportunity to free the data when the
36
+ `Napi::ArrayBuffer` gets garbage-collected. If you need to free the data
37
+ retained by the `Napi::ArrayBuffer` object please use other variants of the
38
+ `Napi::ArrayBuffer::New` factory method that accept `Napi::Finalizer`, which is
39
+ a function that will be invoked when the `Napi::ArrayBuffer` object has been
40
+ destroyed. See [Finalization][] for more details.
41
41
 
42
42
  ```cpp
43
43
  static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength);
@@ -72,9 +72,9 @@ static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env,
72
72
  - `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance.
73
73
  - `[in] externalData`: The pointer to the external data to wrap.
74
74
  - `[in] byteLength`: The length of the `externalData`, in bytes.
75
- - `[in] finalizeCallback`: A function to be called when the `Napi::ArrayBuffer` is
76
- destroyed. It must implement `operator()`, accept an Napi::Env, a `void*` (which is the
77
- `externalData` pointer), and return `void`.
75
+ - `[in] finalizeCallback`: A function called when the engine destroys the
76
+ `Napi::ArrayBuffer` object, implementing `operator()(Napi::BasicEnv, void*)`.
77
+ See [Finalization][] for more details.
78
78
 
79
79
  Returns a new `Napi::ArrayBuffer` instance.
80
80
 
@@ -102,11 +102,10 @@ static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env,
102
102
  - `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance.
103
103
  - `[in] externalData`: The pointer to the external data to wrap.
104
104
  - `[in] byteLength`: The length of the `externalData`, in bytes.
105
- - `[in] finalizeCallback`: The function to be called when the `Napi::ArrayBuffer` is
106
- destroyed. It must implement `operator()`, accept an Napi::Env, a `void*` (which is the
107
- `externalData` pointer) and `Hint*`, and return `void`.
108
- - `[in] finalizeHint`: The hint to be passed as the second parameter of the
109
- finalize callback.
105
+ - `[in] finalizeCallback`: A function called when the engine destroys the
106
+ `Napi::ArrayBuffer` object, implementing `operator()(Napi::BasicEnv, void*,
107
+ Hint*)`. See [Finalization][] for more details.
108
+ - `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.
110
109
 
111
110
  Returns a new `Napi::ArrayBuffer` instance.
112
111
 
@@ -163,3 +162,4 @@ Returns `true` if this `ArrayBuffer` has been detached.
163
162
 
164
163
  [`Napi::Object`]: ./object.md
165
164
  [External Buffer]: ./external_buffer.md
165
+ [Finalization]: ./finalization.md
@@ -0,0 +1,200 @@
1
+ # BasicEnv
2
+
3
+ The data structure containing the environment in which the request is being run.
4
+
5
+ The `Napi::BasicEnv` object is usually created and passed by the Node.js runtime
6
+ or node-addon-api infrastructure.
7
+
8
+ The `Napi::BasicEnv` object represents an environment that has a limited subset
9
+ of APIs when compared to `Napi::Env` and can be used in basic finalizers. See
10
+ [Finalization][] for more details.
11
+
12
+ ## Methods
13
+
14
+ ### Constructor
15
+
16
+ ```cpp
17
+ Napi::BasicEnv::BasicEnv(node_api_nogc_env env);
18
+ ```
19
+
20
+ - `[in] env`: The `node_api_nogc_env` environment from which to construct the
21
+ `Napi::BasicEnv` object.
22
+
23
+ ### node_api_nogc_env
24
+
25
+ ```cpp
26
+ operator node_api_nogc_env() const;
27
+ ```
28
+
29
+ Returns the `node_api_nogc_env` opaque data structure representing the
30
+ environment.
31
+
32
+ ### GetInstanceData
33
+ ```cpp
34
+ template <typename T> T* GetInstanceData() const;
35
+ ```
36
+
37
+ Returns the instance data that was previously associated with the environment,
38
+ or `nullptr` if none was associated.
39
+
40
+ ### SetInstanceData
41
+
42
+
43
+ ```cpp
44
+ template <typename T> using Finalizer = void (*)(Env, T*);
45
+ template <typename T, Finalizer<T> fini = Env::DefaultFini<T>>
46
+ void SetInstanceData(T* data) const;
47
+ ```
48
+
49
+ - `[template] fini`: A function to call when the instance data is to be deleted.
50
+ Accepts a function of the form `void CleanupData(Napi::Env env, T* data)`. If
51
+ not given, the default finalizer will be used, which simply uses the `delete`
52
+ operator to destroy `T*` when the add-on instance is unloaded.
53
+ - `[in] data`: A pointer to data that will be associated with the instance of
54
+ the add-on for the duration of its lifecycle.
55
+
56
+ Associates a data item stored at `T* data` with the current instance of the
57
+ add-on. The item will be passed to the function `fini` which gets called when an
58
+ instance of the add-on is unloaded.
59
+
60
+ ### SetInstanceData
61
+
62
+ ```cpp
63
+ template <typename DataType, typename HintType>
64
+ using FinalizerWithHint = void (*)(Env, DataType*, HintType*);
65
+ template <typename DataType,
66
+ typename HintType,
67
+ FinalizerWithHint<DataType, HintType> fini =
68
+ Env::DefaultFiniWithHint<DataType, HintType>>
69
+ void SetInstanceData(DataType* data, HintType* hint) const;
70
+ ```
71
+
72
+ - `[template] fini`: A function to call when the instance data is to be deleted.
73
+ Accepts a function of the form `void CleanupData(Napi::Env env, DataType* data,
74
+ HintType* hint)`. If not given, the default finalizer will be used, which simply
75
+ uses the `delete` operator to destroy `T*` when the add-on instance is unloaded.
76
+ - `[in] data`: A pointer to data that will be associated with the instance of
77
+ the add-on for the duration of its lifecycle.
78
+ - `[in] hint`: A pointer to data that will be associated with the instance of
79
+ the add-on for the duration of its lifecycle and will be passed as a hint to
80
+ `fini` when the add-on instance is unloaded.
81
+
82
+ Associates a data item stored at `T* data` with the current instance of the
83
+ add-on. The item will be passed to the function `fini` which gets called when an
84
+ instance of the add-on is unloaded. This overload accepts an additional hint to
85
+ be passed to `fini`.
86
+
87
+ ### GetModuleFileName
88
+
89
+ ```cpp
90
+ const char* Napi::Env::GetModuleFileName() const;
91
+ ```
92
+
93
+ Returns a URL containing the absolute path of the location from which the add-on
94
+ was loaded. For a file on the local file system it will start with `file://`.
95
+ The string is null-terminated and owned by env and must thus not be modified or
96
+ freed. It is only valid while the add-on is loaded.
97
+
98
+ ### AddCleanupHook
99
+
100
+ ```cpp
101
+ template <typename Hook>
102
+ CleanupHook<Hook> AddCleanupHook(Hook hook);
103
+ ```
104
+
105
+ - `[in] hook`: A function to call when the environment exits. Accepts a function
106
+ of the form `void ()`.
107
+
108
+ Registers `hook` as a function to be run once the current Node.js environment
109
+ exits. Unlike the underlying C-based Node-API, providing the same `hook`
110
+ multiple times **is** allowed. The hooks will be called in reverse order, i.e.
111
+ the most recently added one will be called first.
112
+
113
+ Returns an `Env::CleanupHook` object, which can be used to remove the hook via
114
+ its `Remove()` method.
115
+
116
+ ### PostFinalizer
117
+
118
+ ```cpp
119
+ template <typename FinalizerType>
120
+ inline void PostFinalizer(FinalizerType finalizeCallback) const;
121
+ ```
122
+
123
+ - `[in] finalizeCallback`: The function to queue for execution outside of the GC
124
+ finalization, implementing `operator()(Napi::Env)`. See [Finalization][] for
125
+ more details.
126
+
127
+ ### PostFinalizer
128
+
129
+ ```cpp
130
+ template <typename FinalizerType, typename T>
131
+ inline void PostFinalizer(FinalizerType finalizeCallback, T* data) const;
132
+ ```
133
+
134
+ - `[in] finalizeCallback`: The function to queue for execution outside of the GC
135
+ finalization, implementing `operator()(Napi::Env, T*)`. See [Finalization][]
136
+ for more details.
137
+ - `[in] data`: The data to associate with the object.
138
+
139
+ ### PostFinalizer
140
+
141
+ ```cpp
142
+ template <typename FinalizerType, typename T, typename Hint>
143
+ inline void PostFinalizer(FinalizerType finalizeCallback,
144
+ T* data,
145
+ Hint* finalizeHint) const;
146
+ ```
147
+
148
+ - `[in] finalizeCallback`: The function to queue for execution outside of the GC
149
+ finalization, implementing `operator()(Napi::Env, T*, Hint*)`. See
150
+ [Finalization][] for more details.
151
+ - `[in] data`: The data to associate with the object.
152
+ - `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.
153
+
154
+ ### AddCleanupHook
155
+
156
+ ```cpp
157
+ template <typename Hook, typename Arg>
158
+ CleanupHook<Hook, Arg> AddCleanupHook(Hook hook, Arg* arg);
159
+ ```
160
+
161
+ - `[in] hook`: A function to call when the environment exits. Accepts a function
162
+ of the form `void (Arg* arg)`.
163
+ - `[in] arg`: A pointer to data that will be passed as the argument to `hook`.
164
+
165
+ Registers `hook` as a function to be run with the `arg` parameter once the
166
+ current Node.js environment exits. Unlike the underlying C-based Node-API,
167
+ providing the same `hook` and `arg` pair multiple times **is** allowed. The
168
+ hooks will be called in reverse order, i.e. the most recently added one will be
169
+ called first.
170
+
171
+ Returns an `Env::CleanupHook` object, which can be used to remove the hook via
172
+ its `Remove()` method.
173
+
174
+ # Env::CleanupHook
175
+
176
+ The `Env::CleanupHook` object allows removal of the hook added via
177
+ `Env::AddCleanupHook()`
178
+
179
+ ## Methods
180
+
181
+ ### IsEmpty
182
+
183
+ ```cpp
184
+ bool IsEmpty();
185
+ ```
186
+
187
+ Returns `true` if the cleanup hook was **not** successfully registered.
188
+
189
+ ### Remove
190
+
191
+ ```cpp
192
+ bool Remove(Env env);
193
+ ```
194
+
195
+ Unregisters the hook from running once the current Node.js environment exits.
196
+
197
+ Returns `true` if the hook was successfully removed from the Node.js
198
+ environment.
199
+
200
+ [Finalization]: ./finalization.md
@@ -27,16 +27,15 @@ Returns a new `Napi::Buffer` object.
27
27
 
28
28
  Wraps the provided external data into a new `Napi::Buffer` object.
29
29
 
30
- The `Napi::Buffer` object does not assume ownership for the data and expects it to be
31
- valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
32
- collection this overload is only suitable for data which is static and never
33
- needs to be freed.
34
- This factory method will not provide the caller with an opportunity to free the
35
- data when the `Napi::Buffer` gets garbage-collected. If you need to free the
36
- data retained by the `Napi::Buffer` object please use other variants of the
37
- `Napi::Buffer::New` factory method that accept `Napi::Finalizer`, which is a
38
- function that will be invoked when the `Napi::Buffer` object has been
39
- destroyed.
30
+ The `Napi::Buffer` object does not assume ownership for the data and expects it
31
+ to be valid for the lifetime of the object. Since the `Napi::Buffer` is subject
32
+ to garbage collection this overload is only suitable for data which is static
33
+ and never needs to be freed. This factory method will not provide the caller
34
+ with an opportunity to free the data when the `Napi::Buffer` gets
35
+ garbage-collected. If you need to free the data retained by the `Napi::Buffer`
36
+ object please use other variants of the `Napi::Buffer::New` factory method that
37
+ accept `Finalizer`, which is a function that will be invoked when the
38
+ `Napi::Buffer` object has been destroyed. See [Finalization][] for more details.
40
39
 
41
40
  ```cpp
42
41
  static Napi::Buffer<T> Napi::Buffer::New(napi_env env, T* data, size_t length);
@@ -70,9 +69,9 @@ static Napi::Buffer<T> Napi::Buffer::New(napi_env env,
70
69
  - `[in] env`: The environment in which to create the `Napi::Buffer` object.
71
70
  - `[in] data`: The pointer to the external data to expose.
72
71
  - `[in] length`: The number of `T` elements in the external data.
73
- - `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
74
- destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
75
- external data pointer), and return `void`.
72
+ - `[in] finalizeCallback`: The function called when the engine destroys the
73
+ `Napi::Buffer` object, implementing `operator()(Napi::BasicEnv, T*)`. See
74
+ [Finalization][] for more details.
76
75
 
77
76
  Returns a new `Napi::Buffer` object.
78
77
 
@@ -99,11 +98,10 @@ static Napi::Buffer<T> Napi::Buffer::New(napi_env env,
99
98
  - `[in] env`: The environment in which to create the `Napi::Buffer` object.
100
99
  - `[in] data`: The pointer to the external data to expose.
101
100
  - `[in] length`: The number of `T` elements in the external data.
102
- - `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
103
- destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
104
- external data pointer) and `Hint*`, and return `void`.
105
- - `[in] finalizeHint`: The hint to be passed as the second parameter of the
106
- finalize callback.
101
+ - `[in] finalizeCallback`: The function called when the engine destroys the
102
+ `Napi::Buffer` object, implementing `operator()(Napi::BasicEnv, T*, Hint*)`.
103
+ See [Finalization][] for more details.
104
+ - `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.
107
105
 
108
106
  Returns a new `Napi::Buffer` object.
109
107
 
@@ -157,9 +155,9 @@ static Napi::Buffer<T> Napi::Buffer::NewOrCopy(napi_env env,
157
155
  - `[in] env`: The environment in which to create the `Napi::Buffer` object.
158
156
  - `[in] data`: The pointer to the external data to expose.
159
157
  - `[in] length`: The number of `T` elements in the external data.
160
- - `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
161
- destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
162
- external data pointer), and return `void`.
158
+ - `[in] finalizeCallback`: The function called when the engine destroys the
159
+ `Napi::Buffer` object, implementing `operator()(Napi::BasicEnv, T*)`. See
160
+ [Finalization][] for more details.
163
161
 
164
162
  Returns a new `Napi::Buffer` object.
165
163
 
@@ -186,11 +184,10 @@ static Napi::Buffer<T> Napi::Buffer::NewOrCopy(napi_env env,
186
184
  - `[in] env`: The environment in which to create the `Napi::Buffer` object.
187
185
  - `[in] data`: The pointer to the external data to expose.
188
186
  - `[in] length`: The number of `T` elements in the external data.
189
- - `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
190
- destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
191
- external data pointer) and `Hint*`, and return `void`.
192
- - `[in] finalizeHint`: The hint to be passed as the second parameter of the
193
- finalize callback.
187
+ - `[in] finalizeCallback`: The function called when the engine destroys the
188
+ `Napi::Buffer` object, implementing `operator()(Napi::BasicEnv, T*, Hint*)`.
189
+ See [Finalization][] for more details.
190
+ - `[in] finalizeHint`: The hint value passed to the `finalizeCallback` function.
194
191
 
195
192
  Returns a new `Napi::Buffer` object.
196
193
 
@@ -245,3 +242,4 @@ Returns the number of `T` elements in the external data.
245
242
 
246
243
  [`Napi::Uint8Array`]: ./typed_array_of.md
247
244
  [External Buffer]: ./external_buffer.md
245
+ [Finalization]: ./finalization.md
@@ -45,6 +45,25 @@ The following line in the `CMakeLists.txt` file will enable Node-API experimenta
45
45
  add_definitions(-DNAPI_EXPERIMENTAL)
46
46
  ```
47
47
 
48
+ ### Exception Handling
49
+
50
+ To enable C++ exception handling (for more info see: [Setup](setup.md)), define
51
+ the corresponding preprocessor directives depending on which exception handling
52
+ behavior is desired.
53
+
54
+ To enable C++ exception handling with `Napi::Error` objects only:
55
+
56
+ ```
57
+ add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS)
58
+ ```
59
+
60
+ To enable C++ exception handling for all exceptions thrown:
61
+
62
+ ```
63
+ add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS)
64
+ add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS_ALL)
65
+ ```
66
+
48
67
  ### node-addon-api
49
68
 
50
69
  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).
@@ -6,7 +6,17 @@ collaborators to add you. If necessary you can ask the build
6
6
  Working Group who manages the Node.js npm user to add you if
7
7
  there are no other active collaborators.
8
8
 
9
- ## Prerequisites
9
+ Generally, the release is handled by the
10
+ [release-please](https://github.com/nodejs/node-addon-api/blob/main/.github/workflows/release-please.yml)
11
+ GitHub action. It will bump the version in `package.json` and publish
12
+ node-addon-api to npm.
13
+
14
+ In cases that the release-please action is not working, please follow the steps
15
+ below to publish node-addon-api manually.
16
+
17
+ ## Publish new release manually
18
+
19
+ ### Prerequisites
10
20
 
11
21
  Before to start creating a new release check if you have installed the following
12
22
  tools:
@@ -16,7 +26,7 @@ tools:
16
26
  If not please follow the instruction reported in the tool's documentation to
17
27
  install it.
18
28
 
19
- ## Publish new release
29
+ ### Steps
20
30
 
21
31
  These are the steps to follow to create a new release:
22
32
 
@@ -34,14 +44,16 @@ to show the new version as the latest.
34
44
  the route folder of the repo launch the following command:
35
45
 
36
46
  ```bash
37
- > changelog-maker
47
+ > changelog-maker --md --group --filter-release
38
48
  ```
39
49
  * Use the output generated by **changelog maker** to update the [CHANGELOG.md](https://github.com/nodejs/node-addon-api/blob/main/CHANGELOG.md)
40
50
  following the style used in publishing the previous release.
41
51
 
42
52
  * Add any new contributors to the "contributors" section in the package.json
43
53
 
44
- * Validate all tests pass by running `npm test` on the `main` branch.
54
+ * Commit with a message containing _only_ an x.y.z semver designator. "x.y.z" (so that the commit can be filtered by changelog-maker)
55
+
56
+ * Create a release proposal pull request.
45
57
 
46
58
  * Use **[CI](https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/)**
47
59
  to validate tests pass (note there are still some issues on SmartOS and