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.
- package/CHANGELOG.md +17 -0
- package/LICENSE.txt +2 -2
- package/README.md +8 -8
- package/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_armhf/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_loong64/koffi.node +0 -0
- package/build/koffi/linux_riscv64d/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_arm64/koffi.exp +0 -0
- package/build/koffi/win32_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.exp +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.exp +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/assets.ini +3 -3
- package/doc/develop.sh +4 -3
- package/doc/pages/platforms.md +1 -1
- package/doc/static/highlight.js +1 -1
- package/doc/static/koffi.css +3 -2
- package/doc/static/print.css +1 -1
- package/doc/templates/code.html +5 -5
- package/doc/templates/page.html +4 -4
- package/index.d.ts +2 -2
- package/index.js +25 -25
- package/indirect.js +25 -5
- package/package.json +2 -2
- package/src/cnoke/LICENSE.txt +2 -2
- package/src/cnoke/README.md +2 -0
- package/src/cnoke/assets/FindCNoke.cmake +12 -2
- package/src/cnoke/assets/win_delay_hook.c +4 -4
- package/src/cnoke/cnoke.js +4 -2
- package/src/cnoke/package.json +1 -1
- package/src/cnoke/src/builder.js +11 -14
- package/src/cnoke/src/index.js +2 -2
- package/src/cnoke/src/tools.js +34 -2
- package/src/core/{libcc/libcc.cc → base/base.cc} +3092 -1674
- package/src/core/{libcc/libcc.hh → base/base.hh} +3059 -2432
- package/src/core/{libcc → base}/mimetypes.inc +42 -4
- package/src/core/{libcc → base}/mimetypes_gen.py +3 -3
- package/src/core/unicode/generate.py +124 -0
- package/src/core/unicode/xid.cc +52 -0
- package/src/core/unicode/xid.hh +29 -0
- package/src/core/unicode/xid.inc +465 -0
- package/src/koffi/CMakeLists.txt +8 -5
- package/src/koffi/cmake/raylib.cmake +6 -2
- package/src/koffi/cmake/{sqlite.cmake → sqlite3.cmake} +3 -3
- package/src/koffi/examples/electron-forge/forge.config.js +23 -3
- package/src/koffi/examples/electron-forge/package.json +18 -16
- package/src/koffi/src/abi_arm32.cc +8 -21
- package/src/koffi/src/abi_arm32_asm.S +2 -2
- package/src/koffi/src/abi_arm64.cc +46 -59
- package/src/koffi/src/abi_arm64_asm.S +4 -4
- package/src/koffi/src/abi_arm64_asm.asm +2 -2
- package/src/koffi/src/abi_loong64_asm.S +2 -2
- package/src/koffi/src/abi_riscv64.cc +6 -19
- package/src/koffi/src/abi_riscv64_asm.S +2 -2
- package/src/koffi/src/abi_x64_sysv.cc +4 -17
- package/src/koffi/src/abi_x64_sysv_asm.S +5 -5
- package/src/koffi/src/abi_x64_win.cc +4 -17
- package/src/koffi/src/abi_x64_win_asm.asm +2 -2
- package/src/koffi/src/abi_x86.cc +9 -22
- package/src/koffi/src/abi_x86_asm.S +2 -2
- package/src/koffi/src/abi_x86_asm.asm +2 -2
- package/src/koffi/src/call.cc +49 -42
- package/src/koffi/src/call.hh +9 -8
- package/src/koffi/src/errno.inc +152 -152
- package/src/koffi/src/ffi.cc +45 -39
- package/src/koffi/src/ffi.hh +6 -6
- package/src/koffi/src/init.js +1 -1
- package/src/koffi/src/parser.cc +6 -5
- package/src/koffi/src/parser.hh +3 -3
- package/src/koffi/src/trampolines/armasm.inc +2 -2
- package/src/koffi/src/trampolines/gnu.inc +2 -2
- package/src/koffi/src/trampolines/masm32.inc +2 -2
- package/src/koffi/src/trampolines/masm64.inc +2 -2
- package/src/koffi/src/trampolines/prototypes.inc +2 -2
- package/src/koffi/src/util.cc +9 -9
- package/src/koffi/src/util.hh +3 -3
- package/src/koffi/src/win32.cc +5 -5
- package/src/koffi/src/win32.hh +9 -9
- package/vendor/node-addon-api/CHANGELOG.md +97 -2
- package/vendor/node-addon-api/CONTRIBUTING.md +117 -7
- package/vendor/node-addon-api/README.md +25 -249
- package/vendor/node-addon-api/common.gypi +1 -0
- package/vendor/node-addon-api/doc/README.md +145 -0
- package/vendor/node-addon-api/doc/array_buffer.md +15 -15
- package/vendor/node-addon-api/doc/basic_env.md +200 -0
- package/vendor/node-addon-api/doc/buffer.md +24 -26
- package/vendor/node-addon-api/doc/cmake-js.md +19 -0
- package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md} +16 -4
- package/vendor/node-addon-api/doc/env.md +11 -131
- package/vendor/node-addon-api/doc/error_handling.md +12 -0
- package/vendor/node-addon-api/doc/external.md +13 -4
- package/vendor/node-addon-api/doc/finalization.md +153 -0
- package/vendor/node-addon-api/doc/memory_management.md +1 -1
- package/vendor/node-addon-api/doc/object_wrap.md +19 -3
- package/vendor/node-addon-api/doc/promises.md +51 -0
- package/vendor/node-addon-api/doc/setup.md +29 -6
- package/vendor/node-addon-api/doc/value.md +13 -0
- package/vendor/node-addon-api/doc/version_management.md +2 -2
- package/vendor/node-addon-api/eslint.config.js +5 -0
- package/vendor/node-addon-api/index.js +2 -0
- package/vendor/node-addon-api/napi-inl.h +592 -166
- package/vendor/node-addon-api/napi.h +167 -59
- package/vendor/node-addon-api/node_addon_api.gyp +10 -0
- package/vendor/node-addon-api/noexcept.gypi +1 -1
- package/vendor/node-addon-api/package.json +10 -13
- package/vendor/node-addon-api/release-please-config.json +15 -0
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +2 -1
- package/vendor/node-addon-api/test/array_buffer.js +1 -1
- package/vendor/node-addon-api/test/async_context.js +2 -2
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +3 -3
- package/vendor/node-addon-api/test/async_progress_worker.js +3 -3
- package/vendor/node-addon-api/test/async_worker.cc +15 -13
- package/vendor/node-addon-api/test/async_worker.js +5 -5
- package/vendor/node-addon-api/test/basic_types/value.cc +6 -0
- package/vendor/node-addon-api/test/basic_types/value.js +17 -0
- package/vendor/node-addon-api/test/binding.cc +8 -0
- package/vendor/node-addon-api/test/binding.gyp +23 -1
- package/vendor/node-addon-api/test/buffer.js +1 -2
- package/vendor/node-addon-api/test/common/index.js +1 -1
- package/vendor/node-addon-api/test/except_all.cc +22 -0
- package/vendor/node-addon-api/test/except_all.js +14 -0
- package/vendor/node-addon-api/test/exports.js +19 -0
- package/vendor/node-addon-api/test/finalizer_order.cc +152 -0
- package/vendor/node-addon-api/test/finalizer_order.js +98 -0
- package/vendor/node-addon-api/test/function.js +2 -2
- package/vendor/node-addon-api/test/function_reference.js +2 -2
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +4 -4
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +4 -4
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +3 -3
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +5 -5
- package/vendor/node-addon-api/test/name.cc +10 -8
- package/vendor/node-addon-api/test/object/delete_property.cc +5 -5
- package/vendor/node-addon-api/test/object/get_property.cc +5 -5
- package/vendor/node-addon-api/test/object/has_own_property.cc +4 -4
- package/vendor/node-addon-api/test/object/has_property.cc +5 -5
- package/vendor/node-addon-api/test/object/object.cc +1 -1
- package/vendor/node-addon-api/test/object/set_property.cc +5 -5
- package/vendor/node-addon-api/test/object/subscript_operator.cc +3 -3
- package/vendor/node-addon-api/test/object_reference.cc +18 -18
- package/vendor/node-addon-api/test/promise.cc +75 -0
- package/vendor/node-addon-api/test/promise.js +23 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/index.js +38 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/addon.cc +12 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/binding.gyp +48 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/index.js +3 -0
- package/vendor/node-addon-api/test/require_basic_finalizers/tpl/package.json +11 -0
- package/vendor/node-addon-api/test/run_script.cc +1 -1
- package/vendor/node-addon-api/test/type_taggable.cc +1 -1
- package/vendor/node-addon-api/test/type_taggable.js +3 -4
- package/vendor/node-addon-api/test/typedarray.cc +28 -24
- package/vendor/node-addon-api/tools/conversion.js +1 -1
- package/vendor/node-api-headers/CHANGELOG.md +29 -0
- package/vendor/node-api-headers/CREATING_A_RELEASE.md +12 -2
- package/vendor/node-api-headers/def/js_native_api.def +6 -1
- package/vendor/node-api-headers/def/node_api.def +7 -1
- package/vendor/node-api-headers/include/js_native_api.h +56 -24
- package/vendor/node-api-headers/include/js_native_api_types.h +27 -0
- package/vendor/node-api-headers/include/node_api.h +38 -29
- package/vendor/node-api-headers/lib/parse-utils.js +92 -0
- package/vendor/node-api-headers/package.json +7 -7
- package/vendor/node-api-headers/release-please-config.json +12 -0
- package/vendor/node-api-headers/scripts/update-headers.js +63 -12
- package/vendor/node-api-headers/scripts/write-symbols.js +1 -1
- package/vendor/node-api-headers/symbols.js +17 -1
- package/vendor/node-api-headers/test/parse-utils.js +21 -0
- package/doc/flat/flat.css +0 -27
- package/doc/flat/normal.css +0 -429
- package/doc/flat/print.css +0 -29
- package/doc/flat/reset.css +0 -41
- package/doc/flat/small.css +0 -104
- package/doc/flat/static.js +0 -161
- package/src/core/libcc/brotli.cc +0 -186
- package/src/core/libcc/lz4.cc +0 -197
- package/src/core/libcc/miniz.cc +0 -353
- package/vendor/node-addon-api/tools/eslint-format.js +0 -79
- /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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
76
|
-
|
|
77
|
-
|
|
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`:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
- `[in] finalizeHint`: The hint
|
|
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
|
|
31
|
-
valid for the lifetime of the object. Since the `Napi::Buffer` is subject
|
|
32
|
-
collection this overload is only suitable for data which is static
|
|
33
|
-
needs to be freed.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
- `[in] finalizeHint`: The hint
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
- `[in] finalizeHint`: The hint
|
|
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).
|
package/vendor/node-addon-api/doc/{creating_a_release.md → contributing/creating_a_release.md}
RENAMED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|