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