koffi 1.1.0-beta.0 → 1.1.0-beta.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.
- package/CMakeLists.txt +4 -0
- package/README.md +16 -11
- package/build/qemu/1.1.0-beta.3/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.3/koffi_win32_x64.tar.gz +0 -0
- package/package.json +1 -1
- package/qemu/qemu.js +1 -0
- package/src/abi_arm32.cc +27 -45
- package/src/abi_arm64.cc +58 -132
- package/src/abi_x64_sysv.cc +24 -7
- package/src/abi_x64_win.cc +3 -0
- package/src/abi_x86.cc +3 -0
- package/src/call.cc +540 -33
- package/src/call.hh +5 -3
- package/src/ffi.cc +69 -4
- package/src/ffi.hh +3 -1
- package/src/parser.cc +7 -2
- package/src/util.cc +72 -0
- package/src/util.hh +2 -0
- package/test/misc.c +14 -8
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +4 -0
- package/vendor/node-addon-api/CONTRIBUTING.md +93 -0
- package/vendor/node-addon-api/appveyor.yml +37 -0
- package/vendor/node-addon-api/benchmark/README.md +47 -0
- package/vendor/node-addon-api/benchmark/binding.gyp +25 -0
- package/vendor/node-addon-api/benchmark/function_args.cc +217 -0
- package/vendor/node-addon-api/benchmark/function_args.js +60 -0
- package/vendor/node-addon-api/benchmark/index.js +34 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +91 -0
- package/vendor/node-addon-api/benchmark/property_descriptor.js +37 -0
- package/vendor/node-addon-api/doc/addon.md +163 -0
- package/vendor/node-addon-api/doc/array.md +81 -0
- package/vendor/node-addon-api/doc/array_buffer.md +155 -0
- package/vendor/node-addon-api/doc/async_context.md +86 -0
- package/vendor/node-addon-api/doc/async_operations.md +31 -0
- package/vendor/node-addon-api/doc/async_worker.md +427 -0
- package/vendor/node-addon-api/doc/async_worker_variants.md +557 -0
- package/vendor/node-addon-api/doc/bigint.md +97 -0
- package/vendor/node-addon-api/doc/boolean.md +68 -0
- package/vendor/node-addon-api/doc/buffer.md +150 -0
- package/vendor/node-addon-api/doc/callback_scope.md +54 -0
- package/vendor/node-addon-api/doc/callbackinfo.md +97 -0
- package/vendor/node-addon-api/doc/checker-tool.md +32 -0
- package/vendor/node-addon-api/doc/class_property_descriptor.md +123 -0
- package/vendor/node-addon-api/doc/cmake-js.md +68 -0
- package/vendor/node-addon-api/doc/conversion-tool.md +28 -0
- package/vendor/node-addon-api/doc/creating_a_release.md +62 -0
- package/vendor/node-addon-api/doc/dataview.md +248 -0
- package/vendor/node-addon-api/doc/date.md +68 -0
- package/vendor/node-addon-api/doc/env.md +196 -0
- package/vendor/node-addon-api/doc/error.md +120 -0
- package/vendor/node-addon-api/doc/error_handling.md +254 -0
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +80 -0
- package/vendor/node-addon-api/doc/external.md +63 -0
- package/vendor/node-addon-api/doc/function.md +402 -0
- package/vendor/node-addon-api/doc/function_reference.md +238 -0
- package/vendor/node-addon-api/doc/generator.md +13 -0
- package/vendor/node-addon-api/doc/handle_scope.md +63 -0
- package/vendor/node-addon-api/doc/hierarchy.md +91 -0
- package/vendor/node-addon-api/doc/instance_wrap.md +408 -0
- package/vendor/node-addon-api/doc/maybe.md +76 -0
- package/vendor/node-addon-api/doc/memory_management.md +27 -0
- package/vendor/node-addon-api/doc/name.md +29 -0
- package/vendor/node-addon-api/doc/node-gyp.md +82 -0
- package/vendor/node-addon-api/doc/number.md +163 -0
- package/vendor/node-addon-api/doc/object.md +411 -0
- package/vendor/node-addon-api/doc/object_lifetime_management.md +83 -0
- package/vendor/node-addon-api/doc/object_reference.md +117 -0
- package/vendor/node-addon-api/doc/object_wrap.md +588 -0
- package/vendor/node-addon-api/doc/prebuild_tools.md +16 -0
- package/vendor/node-addon-api/doc/promises.md +79 -0
- package/vendor/node-addon-api/doc/property_descriptor.md +286 -0
- package/vendor/node-addon-api/doc/propertylvalue.md +50 -0
- package/vendor/node-addon-api/doc/range_error.md +59 -0
- package/vendor/node-addon-api/doc/reference.md +113 -0
- package/vendor/node-addon-api/doc/setup.md +110 -0
- package/vendor/node-addon-api/doc/string.md +93 -0
- package/vendor/node-addon-api/doc/symbol.md +61 -0
- package/vendor/node-addon-api/doc/threadsafe.md +121 -0
- package/vendor/node-addon-api/doc/threadsafe_function.md +290 -0
- package/vendor/node-addon-api/doc/type_error.md +59 -0
- package/vendor/node-addon-api/doc/typed_array.md +78 -0
- package/vendor/node-addon-api/doc/typed_array_of.md +137 -0
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +306 -0
- package/vendor/node-addon-api/doc/value.md +340 -0
- package/vendor/node-addon-api/doc/version_management.md +43 -0
- package/vendor/node-addon-api/package.json +415 -0
- package/vendor/node-addon-api/test/README.md +91 -0
- package/vendor/node-addon-api/test/addon.cc +36 -0
- package/vendor/node-addon-api/test/addon.js +11 -0
- package/vendor/node-addon-api/test/addon_build/index.js +49 -0
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +17 -0
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +62 -0
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +9 -0
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +11 -0
- package/vendor/node-addon-api/test/addon_data.cc +99 -0
- package/vendor/node-addon-api/test/addon_data.js +46 -0
- package/vendor/node-addon-api/test/array_buffer.cc +243 -0
- package/vendor/node-addon-api/test/array_buffer.js +69 -0
- package/vendor/node-addon-api/test/async_context.cc +36 -0
- package/vendor/node-addon-api/test/async_context.js +122 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +83 -0
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +46 -0
- package/vendor/node-addon-api/test/async_progress_worker.cc +134 -0
- package/vendor/node-addon-api/test/async_progress_worker.js +61 -0
- package/vendor/node-addon-api/test/async_worker.cc +106 -0
- package/vendor/node-addon-api/test/async_worker.js +179 -0
- package/vendor/node-addon-api/test/async_worker_nocallback.js +13 -0
- package/vendor/node-addon-api/test/async_worker_persistent.cc +63 -0
- package/vendor/node-addon-api/test/async_worker_persistent.js +24 -0
- package/vendor/node-addon-api/test/basic_types/array.cc +40 -0
- package/vendor/node-addon-api/test/basic_types/array.js +35 -0
- package/vendor/node-addon-api/test/basic_types/boolean.cc +38 -0
- package/vendor/node-addon-api/test/basic_types/boolean.js +35 -0
- package/vendor/node-addon-api/test/basic_types/number.cc +99 -0
- package/vendor/node-addon-api/test/basic_types/number.js +114 -0
- package/vendor/node-addon-api/test/basic_types/value.cc +120 -0
- package/vendor/node-addon-api/test/basic_types/value.js +133 -0
- package/vendor/node-addon-api/test/bigint.cc +91 -0
- package/vendor/node-addon-api/test/bigint.js +53 -0
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +12 -0
- package/vendor/node-addon-api/test/binding.cc +173 -0
- package/vendor/node-addon-api/test/binding.gyp +124 -0
- package/vendor/node-addon-api/test/buffer.cc +183 -0
- package/vendor/node-addon-api/test/buffer.js +69 -0
- package/vendor/node-addon-api/test/callbackscope.cc +22 -0
- package/vendor/node-addon-api/test/callbackscope.js +49 -0
- package/vendor/node-addon-api/test/common/index.js +114 -0
- package/vendor/node-addon-api/test/common/test_helper.h +71 -0
- package/vendor/node-addon-api/test/dataview/dataview.cc +48 -0
- package/vendor/node-addon-api/test/dataview/dataview.js +35 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +115 -0
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +90 -0
- package/vendor/node-addon-api/test/date.cc +44 -0
- package/vendor/node-addon-api/test/date.js +18 -0
- package/vendor/node-addon-api/test/env_cleanup.cc +88 -0
- package/vendor/node-addon-api/test/env_cleanup.js +56 -0
- package/vendor/node-addon-api/test/error.cc +287 -0
- package/vendor/node-addon-api/test/error.js +81 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +13 -0
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +29 -0
- package/vendor/node-addon-api/test/error_terminating_environment.js +95 -0
- package/vendor/node-addon-api/test/external.cc +81 -0
- package/vendor/node-addon-api/test/external.js +88 -0
- package/vendor/node-addon-api/test/function.cc +324 -0
- package/vendor/node-addon-api/test/function.js +133 -0
- package/vendor/node-addon-api/test/function_reference.cc +202 -0
- package/vendor/node-addon-api/test/function_reference.js +157 -0
- package/vendor/node-addon-api/test/globalObject/global_object.cc +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +61 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +40 -0
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +57 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +28 -0
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +48 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +31 -0
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +58 -0
- package/vendor/node-addon-api/test/handlescope.cc +60 -0
- package/vendor/node-addon-api/test/handlescope.js +14 -0
- package/vendor/node-addon-api/test/index.js +159 -0
- package/vendor/node-addon-api/test/maybe/check.cc +23 -0
- package/vendor/node-addon-api/test/maybe/index.js +38 -0
- package/vendor/node-addon-api/test/memory_management.cc +17 -0
- package/vendor/node-addon-api/test/memory_management.js +9 -0
- package/vendor/node-addon-api/test/movable_callbacks.cc +23 -0
- package/vendor/node-addon-api/test/movable_callbacks.js +21 -0
- package/vendor/node-addon-api/test/name.cc +108 -0
- package/vendor/node-addon-api/test/name.js +59 -0
- package/vendor/node-addon-api/test/napi_child.js +14 -0
- package/vendor/node-addon-api/test/object/delete_property.cc +38 -0
- package/vendor/node-addon-api/test/object/delete_property.js +41 -0
- package/vendor/node-addon-api/test/object/finalizer.cc +29 -0
- package/vendor/node-addon-api/test/object/finalizer.js +28 -0
- package/vendor/node-addon-api/test/object/get_property.cc +34 -0
- package/vendor/node-addon-api/test/object/get_property.js +40 -0
- package/vendor/node-addon-api/test/object/has_own_property.cc +34 -0
- package/vendor/node-addon-api/test/object/has_own_property.js +34 -0
- package/vendor/node-addon-api/test/object/has_property.cc +38 -0
- package/vendor/node-addon-api/test/object/has_property.js +37 -0
- package/vendor/node-addon-api/test/object/object.cc +350 -0
- package/vendor/node-addon-api/test/object/object.js +217 -0
- package/vendor/node-addon-api/test/object/object_deprecated.cc +66 -0
- package/vendor/node-addon-api/test/object/object_deprecated.js +47 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +25 -0
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +61 -0
- package/vendor/node-addon-api/test/object/set_property.cc +45 -0
- package/vendor/node-addon-api/test/object/set_property.js +30 -0
- package/vendor/node-addon-api/test/object/subscript_operator.cc +58 -0
- package/vendor/node-addon-api/test/object/subscript_operator.js +17 -0
- package/vendor/node-addon-api/test/object_reference.cc +219 -0
- package/vendor/node-addon-api/test/object_reference.js +259 -0
- package/vendor/node-addon-api/test/objectwrap.cc +268 -0
- package/vendor/node-addon-api/test/objectwrap.js +284 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +26 -0
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +18 -0
- package/vendor/node-addon-api/test/objectwrap_function.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_function.js +22 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +30 -0
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +13 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +45 -0
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +40 -0
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +19 -0
- package/vendor/node-addon-api/test/promise.cc +29 -0
- package/vendor/node-addon-api/test/promise.js +18 -0
- package/vendor/node-addon-api/test/reference.cc +24 -0
- package/vendor/node-addon-api/test/reference.js +14 -0
- package/vendor/node-addon-api/test/run_script.cc +56 -0
- package/vendor/node-addon-api/test/run_script.js +45 -0
- package/vendor/node-addon-api/test/symbol.cc +79 -0
- package/vendor/node-addon-api/test/symbol.js +73 -0
- package/vendor/node-addon-api/test/testUtil.js +54 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +195 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +63 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +115 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +26 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +225 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +42 -0
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/thunking_manual.cc +140 -0
- package/vendor/node-addon-api/test/thunking_manual.js +17 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +215 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +188 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +68 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +12 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +127 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +14 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +28 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +7 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +237 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +59 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +53 -0
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +53 -0
- package/vendor/node-addon-api/test/typedarray-bigint.js +58 -0
- package/vendor/node-addon-api/test/typedarray.cc +216 -0
- package/vendor/node-addon-api/test/typedarray.js +69 -0
- package/vendor/node-addon-api/test/version_management.cc +27 -0
- package/vendor/node-addon-api/test/version_management.js +31 -0
- package/vendor/node-addon-api/unit-test/README.md +28 -0
- package/vendor/node-addon-api/unit-test/binding-file-template.js +39 -0
- package/vendor/node-addon-api/unit-test/binding.gyp +72 -0
- package/vendor/node-addon-api/unit-test/exceptions.js +32 -0
- package/vendor/node-addon-api/unit-test/generate-binding-cc.js +61 -0
- package/vendor/node-addon-api/unit-test/injectTestParams.js +101 -0
- package/vendor/node-addon-api/unit-test/listOfTestModules.js +88 -0
- package/vendor/node-addon-api/unit-test/matchModules.js +65 -0
- package/vendor/node-addon-api/unit-test/setup.js +13 -0
- package/vendor/node-addon-api/unit-test/spawnTask.js +26 -0
- package/vendor/node-addon-api/unit-test/test.js +30 -0
- package/build/qemu/1.1.0-beta.0/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_arm.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/1.1.0-beta.0/koffi_win32_x64.tar.gz +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Boolean
|
|
2
|
+
|
|
3
|
+
Class `Napi::Boolean` inherits from class [`Napi::Value`][].
|
|
4
|
+
|
|
5
|
+
`Napi::Boolean` class is a representation of the JavaScript `Boolean` object. The
|
|
6
|
+
`Napi::Boolean` class inherits its behavior from the `Napi::Value` class
|
|
7
|
+
(for more info see: [`Napi::Value`](value.md)).
|
|
8
|
+
|
|
9
|
+
## Methods
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
Creates a new empty instance of an `Napi::Boolean` object.
|
|
14
|
+
|
|
15
|
+
```cpp
|
|
16
|
+
Napi::Boolean::Boolean();
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Returns a new _empty_ `Napi::Boolean` object.
|
|
20
|
+
|
|
21
|
+
### Constructor
|
|
22
|
+
|
|
23
|
+
Creates a new instance of the `Napi::Boolean` object.
|
|
24
|
+
|
|
25
|
+
```cpp
|
|
26
|
+
Napi::Boolean(napi_env env, napi_value value);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Boolean` object.
|
|
30
|
+
- `[in] value`: The `napi_value` which is a handle for a JavaScript `Boolean`.
|
|
31
|
+
|
|
32
|
+
Returns a non-empty `Napi::Boolean` object.
|
|
33
|
+
|
|
34
|
+
### New
|
|
35
|
+
|
|
36
|
+
Initializes a new instance of the `Napi::Boolean` object.
|
|
37
|
+
|
|
38
|
+
```cpp
|
|
39
|
+
Napi::Boolean Napi::Boolean::New(napi_env env, bool value);
|
|
40
|
+
```
|
|
41
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Boolean` object.
|
|
42
|
+
- `[in] value`: The primitive boolean value (`true` or `false`).
|
|
43
|
+
|
|
44
|
+
Returns a new instance of the `Napi::Boolean` object.
|
|
45
|
+
|
|
46
|
+
### Value
|
|
47
|
+
|
|
48
|
+
Converts a `Napi::Boolean` value to a boolean primitive.
|
|
49
|
+
|
|
50
|
+
```cpp
|
|
51
|
+
bool Napi::Boolean::Value() const;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Returns the boolean primitive type of the corresponding `Napi::Boolean` object.
|
|
55
|
+
|
|
56
|
+
## Operators
|
|
57
|
+
|
|
58
|
+
### operator bool
|
|
59
|
+
|
|
60
|
+
Converts a `Napi::Boolean` value to a boolean primitive.
|
|
61
|
+
|
|
62
|
+
```cpp
|
|
63
|
+
Napi::Boolean::operator bool() const;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Returns the boolean primitive type of the corresponding `Napi::Boolean` object.
|
|
67
|
+
|
|
68
|
+
[`Napi::Value`]: ./value.md
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Buffer
|
|
2
|
+
|
|
3
|
+
Class `Napi::Buffer` inherits from class [`Napi::Uint8Array`][].
|
|
4
|
+
|
|
5
|
+
The `Napi::Buffer` class creates a projection of raw data that can be consumed by
|
|
6
|
+
script.
|
|
7
|
+
|
|
8
|
+
## Methods
|
|
9
|
+
|
|
10
|
+
### New
|
|
11
|
+
|
|
12
|
+
Allocates a new `Napi::Buffer` object with a given length.
|
|
13
|
+
|
|
14
|
+
```cpp
|
|
15
|
+
static Napi::Buffer<T> Napi::Buffer::New(napi_env env, size_t length);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
19
|
+
- `[in] length`: The number of `T` elements to allocate.
|
|
20
|
+
|
|
21
|
+
Returns a new `Napi::Buffer` object.
|
|
22
|
+
|
|
23
|
+
### New
|
|
24
|
+
|
|
25
|
+
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
26
|
+
|
|
27
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
28
|
+
valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
|
|
29
|
+
collection this overload is only suitable for data which is static and never
|
|
30
|
+
needs to be freed.
|
|
31
|
+
This factory method will not provide the caller with an opportunity to free the
|
|
32
|
+
data when the `Napi::Buffer` gets garbage-collected. If you need to free the
|
|
33
|
+
data retained by the `Napi::Buffer` object please use other variants of the
|
|
34
|
+
`Napi::Buffer::New` factory method that accept `Napi::Finalizer`, which is a
|
|
35
|
+
function that will be invoked when the `Napi::Buffer` object has been
|
|
36
|
+
destroyed.
|
|
37
|
+
|
|
38
|
+
```cpp
|
|
39
|
+
static Napi::Buffer<T> Napi::Buffer::New(napi_env env, T* data, size_t length);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
43
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
44
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
45
|
+
|
|
46
|
+
Returns a new `Napi::Buffer` object.
|
|
47
|
+
|
|
48
|
+
### New
|
|
49
|
+
|
|
50
|
+
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
51
|
+
|
|
52
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it
|
|
53
|
+
to be valid for the lifetime of the object. The data can only be freed once the
|
|
54
|
+
`finalizeCallback` is invoked to indicate that the `Napi::Buffer` has been released.
|
|
55
|
+
|
|
56
|
+
```cpp
|
|
57
|
+
template <typename Finalizer>
|
|
58
|
+
static Napi::Buffer<T> Napi::Buffer::New(napi_env env,
|
|
59
|
+
T* data,
|
|
60
|
+
size_t length,
|
|
61
|
+
Finalizer finalizeCallback);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
65
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
66
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
67
|
+
- `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
|
|
68
|
+
destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
|
|
69
|
+
external data pointer), and return `void`.
|
|
70
|
+
|
|
71
|
+
Returns a new `Napi::Buffer` object.
|
|
72
|
+
|
|
73
|
+
### New
|
|
74
|
+
|
|
75
|
+
Wraps the provided external data into a new `Napi::Buffer` object.
|
|
76
|
+
|
|
77
|
+
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
|
|
78
|
+
valid for the lifetime of the object. The data can only be freed once the
|
|
79
|
+
`finalizeCallback` is invoked to indicate that the `Napi::Buffer` has been released.
|
|
80
|
+
|
|
81
|
+
```cpp
|
|
82
|
+
template <typename Finalizer, typename Hint>
|
|
83
|
+
static Napi::Buffer<T> Napi::Buffer::New(napi_env env,
|
|
84
|
+
T* data,
|
|
85
|
+
size_t length,
|
|
86
|
+
Finalizer finalizeCallback,
|
|
87
|
+
Hint* finalizeHint);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
91
|
+
- `[in] data`: The pointer to the external data to expose.
|
|
92
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
93
|
+
- `[in] finalizeCallback`: The function to be called when the `Napi::Buffer` is
|
|
94
|
+
destroyed. It must implement `operator()`, accept an Napi::Env, a `T*` (which is the
|
|
95
|
+
external data pointer) and `Hint*`, and return `void`.
|
|
96
|
+
- `[in] finalizeHint`: The hint to be passed as the second parameter of the
|
|
97
|
+
finalize callback.
|
|
98
|
+
|
|
99
|
+
Returns a new `Napi::Buffer` object.
|
|
100
|
+
|
|
101
|
+
### Copy
|
|
102
|
+
|
|
103
|
+
Allocates a new `Napi::Buffer` object and copies the provided external data into it.
|
|
104
|
+
|
|
105
|
+
```cpp
|
|
106
|
+
static Napi::Buffer<T> Napi::Buffer::Copy(napi_env env, const T* data, size_t length);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
110
|
+
- `[in] data`: The pointer to the external data to copy.
|
|
111
|
+
- `[in] length`: The number of `T` elements in the external data.
|
|
112
|
+
|
|
113
|
+
Returns a new `Napi::Buffer` object containing a copy of the data.
|
|
114
|
+
|
|
115
|
+
### Constructor
|
|
116
|
+
|
|
117
|
+
Initializes an empty instance of the `Napi::Buffer` class.
|
|
118
|
+
|
|
119
|
+
```cpp
|
|
120
|
+
Napi::Buffer::Buffer();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Constructor
|
|
124
|
+
|
|
125
|
+
Initializes the `Napi::Buffer` object using an existing Uint8Array.
|
|
126
|
+
|
|
127
|
+
```cpp
|
|
128
|
+
Napi::Buffer::Buffer(napi_env env, napi_value value);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- `[in] env`: The environment in which to create the `Napi::Buffer` object.
|
|
132
|
+
- `[in] value`: The Uint8Array reference to wrap.
|
|
133
|
+
|
|
134
|
+
### Data
|
|
135
|
+
|
|
136
|
+
```cpp
|
|
137
|
+
T* Napi::Buffer::Data() const;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Returns a pointer the external data.
|
|
141
|
+
|
|
142
|
+
### Length
|
|
143
|
+
|
|
144
|
+
```cpp
|
|
145
|
+
size_t Napi::Buffer::Length() const;
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Returns the number of `T` elements in the external data.
|
|
149
|
+
|
|
150
|
+
[`Napi::Uint8Array`]: ./typed_array_of.md
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# CallbackScope
|
|
2
|
+
|
|
3
|
+
There are cases (for example, resolving promises) where it is necessary to have
|
|
4
|
+
the equivalent of the scope associated with a callback in place when making
|
|
5
|
+
certain Node-API calls.
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
### Constructor
|
|
10
|
+
|
|
11
|
+
Creates a new callback scope on the stack.
|
|
12
|
+
|
|
13
|
+
```cpp
|
|
14
|
+
Napi::CallbackScope::CallbackScope(napi_env env, napi_callback_scope scope);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
|
|
18
|
+
- `[in] scope`: The pre-existing `napi_callback_scope` or `Napi::CallbackScope`.
|
|
19
|
+
|
|
20
|
+
### Constructor
|
|
21
|
+
|
|
22
|
+
Creates a new callback scope on the stack.
|
|
23
|
+
|
|
24
|
+
```cpp
|
|
25
|
+
Napi::CallbackScope::CallbackScope(napi_env env, napi_async_context context);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `[in] env`: The environment in which to create the `Napi::CallbackScope`.
|
|
29
|
+
- `[in] async_context`: The pre-existing `napi_async_context` or `Napi::AsyncContext`.
|
|
30
|
+
|
|
31
|
+
### Destructor
|
|
32
|
+
|
|
33
|
+
Deletes the instance of `Napi::CallbackScope` object.
|
|
34
|
+
|
|
35
|
+
```cpp
|
|
36
|
+
virtual Napi::CallbackScope::~CallbackScope();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Env
|
|
40
|
+
|
|
41
|
+
```cpp
|
|
42
|
+
Napi::Env Napi::CallbackScope::Env() const;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Returns the `Napi::Env` associated with the `Napi::CallbackScope`.
|
|
46
|
+
|
|
47
|
+
## Operator
|
|
48
|
+
|
|
49
|
+
```cpp
|
|
50
|
+
Napi::CallbackScope::operator napi_callback_scope() const;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Returns the Node-API `napi_callback_scope` wrapped by the `Napi::CallbackScope`
|
|
54
|
+
object. This can be used to mix usage of the C Node-API and node-addon-api.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# CallbackInfo
|
|
2
|
+
|
|
3
|
+
The object representing the components of the JavaScript request being made.
|
|
4
|
+
|
|
5
|
+
The `Napi::CallbackInfo` object is usually created and passed by the Node.js runtime or node-addon-api infrastructure.
|
|
6
|
+
|
|
7
|
+
The `Napi::CallbackInfo` object contains the arguments passed by the caller. The number of arguments is returned by the `Length` method. Each individual argument can be accessed using the `operator[]` method.
|
|
8
|
+
|
|
9
|
+
The `SetData` and `Data` methods are used to set and retrieve the data pointer contained in the `Napi::CallbackInfo` object.
|
|
10
|
+
|
|
11
|
+
## Methods
|
|
12
|
+
|
|
13
|
+
### Constructor
|
|
14
|
+
|
|
15
|
+
```cpp
|
|
16
|
+
Napi::CallbackInfo::CallbackInfo(napi_env env, napi_callback_info info);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- `[in] env`: The `napi_env` environment in which to construct the `Napi::CallbackInfo` object.
|
|
20
|
+
- `[in] info`: The `napi_callback_info` data structure from which to construct the `Napi::CallbackInfo` object.
|
|
21
|
+
|
|
22
|
+
### Env
|
|
23
|
+
|
|
24
|
+
```cpp
|
|
25
|
+
Napi::Env Napi::CallbackInfo::Env() const;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Returns the `Env` object in which the request is being made.
|
|
29
|
+
|
|
30
|
+
### NewTarget
|
|
31
|
+
|
|
32
|
+
```cpp
|
|
33
|
+
Napi::Value Napi::CallbackInfo::NewTarget() const;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Returns the `new.target` value of the constructor call. If the function that was invoked (and for which the `Napi::NCallbackInfo` was passed) is not a constructor call, a call to `IsEmpty()` on the returned value returns true.
|
|
37
|
+
|
|
38
|
+
### IsConstructCall
|
|
39
|
+
|
|
40
|
+
```cpp
|
|
41
|
+
bool Napi::CallbackInfo::IsConstructCall() const;
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Returns a `bool` indicating if the function that was invoked (and for which the `Napi::CallbackInfo` was passed) is a constructor call.
|
|
45
|
+
|
|
46
|
+
### Length
|
|
47
|
+
|
|
48
|
+
```cpp
|
|
49
|
+
size_t Napi::CallbackInfo::Length() const;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Returns the number of arguments passed in the `Napi::CallbackInfo` object.
|
|
53
|
+
|
|
54
|
+
### operator []
|
|
55
|
+
|
|
56
|
+
```cpp
|
|
57
|
+
const Napi::Value operator [](size_t index) const;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- `[in] index`: The zero-based index of the requested argument.
|
|
61
|
+
|
|
62
|
+
Returns a `Napi::Value` object containing the requested argument.
|
|
63
|
+
|
|
64
|
+
### This
|
|
65
|
+
|
|
66
|
+
```cpp
|
|
67
|
+
Napi::Value Napi::CallbackInfo::This() const;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Returns the JavaScript `this` value for the call
|
|
71
|
+
|
|
72
|
+
### Data
|
|
73
|
+
|
|
74
|
+
```cpp
|
|
75
|
+
void* Napi::CallbackInfo::Data() const;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Returns the data pointer for the callback.
|
|
79
|
+
|
|
80
|
+
### SetData
|
|
81
|
+
|
|
82
|
+
```cpp
|
|
83
|
+
void Napi::CallbackInfo::SetData(void* data);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `[in] data`: The new data pointer to associate with this `Napi::CallbackInfo` object.
|
|
87
|
+
|
|
88
|
+
Returns `void`.
|
|
89
|
+
|
|
90
|
+
### Not documented here
|
|
91
|
+
|
|
92
|
+
```cpp
|
|
93
|
+
Napi::CallbackInfo::~CallbackInfo();
|
|
94
|
+
// Disallow copying to prevent multiple free of _dynamicArgs
|
|
95
|
+
Napi::CallbackInfo::CallbackInfo(CallbackInfo const &) = delete;
|
|
96
|
+
void Napi::CallbackInfo::operator=(CallbackInfo const &) = delete;
|
|
97
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Checker Tool
|
|
2
|
+
|
|
3
|
+
**node-addon-api** provides a [checker tool][] that will inspect a given
|
|
4
|
+
directory tree, identifying all Node.js native addons therein, and further
|
|
5
|
+
indicating for each addon whether it is an Node-API addon.
|
|
6
|
+
|
|
7
|
+
## To use the checker tool:
|
|
8
|
+
|
|
9
|
+
1. Install the application with `npm install`.
|
|
10
|
+
|
|
11
|
+
2. If the application does not depend on **node-addon-api**, copy the
|
|
12
|
+
checker tool into the application's directory.
|
|
13
|
+
|
|
14
|
+
3. If the application does not depend on **node-addon-api**, run the checker
|
|
15
|
+
tool from the application's directory:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
node ./check-napi.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Otherwise, the checker tool can be run from the application's
|
|
22
|
+
`node_modules/` subdirectory:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
node ./node_modules/node-addon-api/tools/check-napi.js
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The tool accepts the root directory from which to start checking for Node.js
|
|
29
|
+
native addons as a single optional command line parameter. If omitted it will
|
|
30
|
+
start checking from the current directory (`.`).
|
|
31
|
+
|
|
32
|
+
[checker tool]: ../tools/check-napi.js
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Class property and descriptor
|
|
2
|
+
|
|
3
|
+
Property descriptor for use with `Napi::ObjectWrap<T>` and
|
|
4
|
+
`Napi::InstanceWrap<T>`. This is different from the standalone
|
|
5
|
+
`Napi::PropertyDescriptor` because it is specific to each
|
|
6
|
+
`Napi::ObjectWrap<T>` and `Napi::InstanceWrap<T>` subclasses.
|
|
7
|
+
This prevents using descriptors from a different class when defining a new
|
|
8
|
+
class (preventing the callbacks from having incorrect `this` pointers).
|
|
9
|
+
|
|
10
|
+
`Napi::ClassPropertyDescriptor` is a helper class created with
|
|
11
|
+
`Napi::ObjectWrap<T>` and `Napi::InstanceWrap<T>`. For more reference about it
|
|
12
|
+
see:
|
|
13
|
+
|
|
14
|
+
- [InstanceWrap](./instance_wrap.md)
|
|
15
|
+
- [ObjectWrap](./object_wrap.md)
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
```cpp
|
|
20
|
+
#include <napi.h>
|
|
21
|
+
|
|
22
|
+
class Example : public Napi::ObjectWrap<Example> {
|
|
23
|
+
public:
|
|
24
|
+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
25
|
+
Example(const Napi::CallbackInfo &info);
|
|
26
|
+
|
|
27
|
+
private:
|
|
28
|
+
double _value;
|
|
29
|
+
Napi::Value GetValue(const Napi::CallbackInfo &info);
|
|
30
|
+
void SetValue(const Napi::CallbackInfo &info, const Napi::Value &value);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Napi::Object Example::Init(Napi::Env env, Napi::Object exports) {
|
|
34
|
+
Napi::Function func = DefineClass(env, "Example", {
|
|
35
|
+
// Register a class instance accessor with getter and setter functions.
|
|
36
|
+
InstanceAccessor<&Example::GetValue, &Example::SetValue>("value"),
|
|
37
|
+
// We can also register a readonly accessor by omitting the setter.
|
|
38
|
+
InstanceAccessor<&Example::GetValue>("readOnlyProp")
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
Napi::FunctionReference *constructor = new Napi::FunctionReference();
|
|
42
|
+
*constructor = Napi::Persistent(func);
|
|
43
|
+
env.SetInstanceData(constructor);
|
|
44
|
+
exports.Set("Example", func);
|
|
45
|
+
|
|
46
|
+
return exports;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Example::Example(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Example>(info) {
|
|
50
|
+
Napi::Env env = info.Env();
|
|
51
|
+
// ...
|
|
52
|
+
Napi::Number value = info[0].As<Napi::Number>();
|
|
53
|
+
this->_value = value.DoubleValue();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Napi::Value Example::GetValue(const Napi::CallbackInfo &info) {
|
|
57
|
+
Napi::Env env = info.Env();
|
|
58
|
+
return Napi::Number::New(env, this->_value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void Example::SetValue(const Napi::CallbackInfo &info, const Napi::Value &value) {
|
|
62
|
+
Napi::Env env = info.Env();
|
|
63
|
+
// ...
|
|
64
|
+
Napi::Number arg = value.As<Napi::Number>();
|
|
65
|
+
this->_value = arg.DoubleValue();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Initialize native add-on
|
|
69
|
+
Napi::Object Init (Napi::Env env, Napi::Object exports) {
|
|
70
|
+
Example::Init(env, exports);
|
|
71
|
+
return exports;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Register and initialize native add-on
|
|
75
|
+
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The above code can be used from JavaScript as follows:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
'use strict';
|
|
82
|
+
|
|
83
|
+
const { Example } = require('bindings')('addon');
|
|
84
|
+
|
|
85
|
+
const example = new Example(11);
|
|
86
|
+
console.log(example.value);
|
|
87
|
+
// It prints 11
|
|
88
|
+
example.value = 19;
|
|
89
|
+
console.log(example.value);
|
|
90
|
+
// It prints 19
|
|
91
|
+
example.readOnlyProp = 500;
|
|
92
|
+
console.log(example.readOnlyProp);
|
|
93
|
+
// Unchanged. It prints 19
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Methods
|
|
97
|
+
|
|
98
|
+
### Constructor
|
|
99
|
+
|
|
100
|
+
Creates new instance of `Napi::ClassPropertyDescriptor` descriptor object.
|
|
101
|
+
|
|
102
|
+
```cpp
|
|
103
|
+
Napi::ClassPropertyDescriptor(napi_property_descriptor desc) : _desc(desc) {}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- `[in] desc`: The `napi_property_descriptor`
|
|
107
|
+
|
|
108
|
+
Returns new instance of `Napi::ClassPropertyDescriptor` that is used as property descriptor
|
|
109
|
+
inside the `Napi::ObjectWrap<T>` class.
|
|
110
|
+
|
|
111
|
+
### Operator
|
|
112
|
+
|
|
113
|
+
```cpp
|
|
114
|
+
operator napi_property_descriptor&() { return _desc; }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Returns the original Node-API `napi_property_descriptor` wrapped inside the `Napi::ClassPropertyDescriptor`
|
|
118
|
+
|
|
119
|
+
```cpp
|
|
120
|
+
operator const napi_property_descriptor&() const { return _desc; }
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Returns the original Node-API `napi_property_descriptor` wrapped inside the `Napi::ClassPropertyDescriptor`
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# CMake.js
|
|
2
|
+
|
|
3
|
+
[**CMake.js**](https://github.com/cmake-js/cmake-js) is a build tool that allow native addon developers to compile their
|
|
4
|
+
C or C++ code into executable form. It works like **[node-gyp](node-gyp.md)** but
|
|
5
|
+
instead of Google's [**gyp**](https://gyp.gsrc.io) tool it is based on the [**CMake**](https://cmake.org) build system.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
### Install CMake
|
|
10
|
+
|
|
11
|
+
CMake.js requires that CMake be installed. Installers for a variety of platforms can be found on the [CMake website](https://cmake.org).
|
|
12
|
+
|
|
13
|
+
### Install CMake.js
|
|
14
|
+
|
|
15
|
+
For developers, CMake.js is typically installed as a global package:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g cmake-js
|
|
19
|
+
cmake-js --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> For *users* of your native addon, CMake.js should be configured as a dependency in your `package.json` as described in the [CMake.js documentation](https://github.com/cmake-js/cmake-js).
|
|
23
|
+
|
|
24
|
+
### CMakeLists.txt
|
|
25
|
+
|
|
26
|
+
Your project will require a `CMakeLists.txt` file. The [CMake.js README file](https://github.com/cmake-js/cmake-js#usage) shows what's necessary.
|
|
27
|
+
|
|
28
|
+
### NAPI_VERSION
|
|
29
|
+
|
|
30
|
+
When building Node-API addons, it's crucial to specify the Node-API version your code is designed to work with. With CMake.js, this information is specified in the `CMakeLists.txt` file:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
add_definitions(-DNAPI_VERSION=3)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Since Node-API is ABI-stable, your Node-API addon will work, without recompilation, with the Node-API version you specify in `NAPI_VERSION` and all subsequent Node-API versions.
|
|
37
|
+
|
|
38
|
+
In the absence of a need for features available only in a specific Node-API version, version 3 is a good choice as it is the version of Node-API that was active when Node-API left experimental status.
|
|
39
|
+
|
|
40
|
+
### NAPI_EXPERIMENTAL
|
|
41
|
+
|
|
42
|
+
The following line in the `CMakeLists.txt` file will enable Node-API experimental features if your code requires them:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
add_definitions(-DNAPI_EXPERIMENTAL)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### node-addon-api
|
|
49
|
+
|
|
50
|
+
If your Node-API native add-on uses the optional [**node-addon-api**](https://github.com/nodejs/node-addon-api#node-addon-api-module) C++ wrapper, the `CMakeLists.txt` file requires additional configuration information as described on the [CMake.js README file](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api).
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
|
|
54
|
+
A working example of an Node-API native addon built using CMake.js can be found on the [node-addon-examples repository](https://github.com/nodejs/node-addon-examples/tree/HEAD/build_with_cmake#building-n-api-addons-using-cmakejs).
|
|
55
|
+
|
|
56
|
+
## **CMake** Reference
|
|
57
|
+
|
|
58
|
+
- [Installation](https://github.com/cmake-js/cmake-js#installation)
|
|
59
|
+
- [How to use](https://github.com/cmake-js/cmake-js#usage)
|
|
60
|
+
- [Using Node-API and node-addon-api](https://github.com/cmake-js/cmake-js#n-api-and-node-addon-api)
|
|
61
|
+
- [Tutorials](https://github.com/cmake-js/cmake-js#tutorials)
|
|
62
|
+
- [Use case in the works - ArrayFire.js](https://github.com/cmake-js/cmake-js#use-case-in-the-works---arrayfirejs)
|
|
63
|
+
|
|
64
|
+
Sometimes finding the right settings is not easy so to accomplish at most
|
|
65
|
+
complicated task please refer to:
|
|
66
|
+
|
|
67
|
+
- [CMake documentation](https://cmake.org/)
|
|
68
|
+
- [CMake.js wiki](https://github.com/cmake-js/cmake-js/wiki)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Conversion Tool
|
|
2
|
+
|
|
3
|
+
To make the migration to **node-addon-api** easier, we have provided a script to
|
|
4
|
+
help complete some tasks.
|
|
5
|
+
|
|
6
|
+
## To use the conversion script:
|
|
7
|
+
|
|
8
|
+
1. Go to your module directory
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
cd [module_path]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
2. Install node-addon-api module
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install node-addon-api
|
|
18
|
+
```
|
|
19
|
+
3. Run node-addon-api conversion script
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
node ./node_modules/node-addon-api/tools/conversion.js ./
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
4. While this script makes conversion easier, it still cannot fully convert
|
|
26
|
+
the module. The next step is to try to build the module and complete the
|
|
27
|
+
remaining conversions necessary to allow it to compile and pass all of the
|
|
28
|
+
module's tests.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Creating a release
|
|
2
|
+
|
|
3
|
+
Only collaborators in npm for **node-addon-api** can create releases.
|
|
4
|
+
If you want to be able to do releases ask one of the existing
|
|
5
|
+
collaborators to add you. If necessary you can ask the build
|
|
6
|
+
Working Group who manages the Node.js npm user to add you if
|
|
7
|
+
there are no other active collaborators.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
Before to start creating a new release check if you have installed the following
|
|
12
|
+
tools:
|
|
13
|
+
|
|
14
|
+
* [Changelog maker](https://www.npmjs.com/package/changelog-maker)
|
|
15
|
+
|
|
16
|
+
If not please follow the instruction reported in the tool's documentation to
|
|
17
|
+
install it.
|
|
18
|
+
|
|
19
|
+
## Publish new release
|
|
20
|
+
|
|
21
|
+
These are the steps to follow to create a new release:
|
|
22
|
+
|
|
23
|
+
* Open an issue in the **node-addon-api** repo documenting the intent to create a
|
|
24
|
+
new release. Give people some time to comment or suggest PRs that should land first.
|
|
25
|
+
|
|
26
|
+
* Validate all tests pass by running `npm test` on the `main` branch.
|
|
27
|
+
|
|
28
|
+
* Update the version in **package.json** appropriately.
|
|
29
|
+
|
|
30
|
+
* Update the [README.md](https://github.com/nodejs/node-addon-api/blob/main/README.md)
|
|
31
|
+
to show the new version as the latest.
|
|
32
|
+
|
|
33
|
+
* Generate the changelog for the new version using **changelog maker** tool. From
|
|
34
|
+
the route folder of the repo launch the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
> changelog-maker
|
|
38
|
+
```
|
|
39
|
+
* Use the output generated by **changelog maker** to update the [CHANGELOG.md](https://github.com/nodejs/node-addon-api/blob/main/CHANGELOG.md)
|
|
40
|
+
following the style used in publishing the previous release.
|
|
41
|
+
|
|
42
|
+
* Add any new contributors to the "contributors" section in the package.json
|
|
43
|
+
|
|
44
|
+
* Validate all tests pass by running `npm test` on the `main` branch.
|
|
45
|
+
|
|
46
|
+
* Use **[CI](https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/)**
|
|
47
|
+
to validate tests pass (note there are still some issues on SmartOS and
|
|
48
|
+
Windows in the testing).
|
|
49
|
+
|
|
50
|
+
* Do a clean checkout of node-addon-api.
|
|
51
|
+
|
|
52
|
+
* Login and then run `npm publish`.
|
|
53
|
+
|
|
54
|
+
* Create a release in Github (look at existing releases for an example).
|
|
55
|
+
|
|
56
|
+
* Validate that you can run `npm install node-addon-api` successfully
|
|
57
|
+
and that the correct version is installed.
|
|
58
|
+
|
|
59
|
+
* Comment on the issue opened in the first step that the release has been created
|
|
60
|
+
and close the issue.
|
|
61
|
+
|
|
62
|
+
* Tweet that the release has been created.
|