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
|
@@ -3,12 +3,12 @@ const assert = require('assert');
|
|
|
3
3
|
|
|
4
4
|
// we only check async hooks on 8.x an higher were
|
|
5
5
|
// they are closer to working properly
|
|
6
|
-
const nodeVersion = process.versions.node.split('.')[0]
|
|
7
|
-
let
|
|
8
|
-
function checkAsyncHooks() {
|
|
6
|
+
const nodeVersion = process.versions.node.split('.')[0];
|
|
7
|
+
let asyncHooks;
|
|
8
|
+
function checkAsyncHooks () {
|
|
9
9
|
if (nodeVersion >= 8) {
|
|
10
|
-
if (
|
|
11
|
-
|
|
10
|
+
if (asyncHooks === undefined) {
|
|
11
|
+
asyncHooks = require('async_hooks');
|
|
12
12
|
}
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
@@ -17,33 +17,33 @@ function checkAsyncHooks() {
|
|
|
17
17
|
|
|
18
18
|
module.exports = require('./common').runTest(test);
|
|
19
19
|
|
|
20
|
-
function test(binding) {
|
|
21
|
-
if (!checkAsyncHooks())
|
|
22
|
-
return;
|
|
20
|
+
function test (binding) {
|
|
21
|
+
if (!checkAsyncHooks()) { return; }
|
|
23
22
|
|
|
24
23
|
let id;
|
|
25
24
|
let insideHook = false;
|
|
26
|
-
const hook =
|
|
27
|
-
init(asyncId, type, triggerAsyncId, resource) {
|
|
28
|
-
if (id === undefined && type === 'callback_scope_test') {
|
|
25
|
+
const hook = asyncHooks.createHook({
|
|
26
|
+
init (asyncId, type, triggerAsyncId, resource) {
|
|
27
|
+
if (id === undefined && (type === 'callback_scope_test' || type === 'existing_callback_scope_test')) {
|
|
29
28
|
id = asyncId;
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
|
-
before(asyncId) {
|
|
33
|
-
if (asyncId === id)
|
|
34
|
-
insideHook = true;
|
|
31
|
+
before (asyncId) {
|
|
32
|
+
if (asyncId === id) { insideHook = true; }
|
|
35
33
|
},
|
|
36
|
-
after(asyncId) {
|
|
37
|
-
if (asyncId === id)
|
|
38
|
-
insideHook = false;
|
|
34
|
+
after (asyncId) {
|
|
35
|
+
if (asyncId === id) { insideHook = false; }
|
|
39
36
|
}
|
|
40
37
|
}).enable();
|
|
41
38
|
|
|
42
39
|
return new Promise(resolve => {
|
|
43
|
-
binding.callbackscope.runInCallbackScope(function() {
|
|
40
|
+
binding.callbackscope.runInCallbackScope(function () {
|
|
44
41
|
assert(insideHook);
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
binding.callbackscope.runInPreExistingCbScope(function () {
|
|
43
|
+
assert(insideHook);
|
|
44
|
+
hook.disable();
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const { access } = require('node:fs/promises');
|
|
5
6
|
|
|
6
7
|
const noop = () => {};
|
|
7
8
|
|
|
@@ -75,9 +76,41 @@ exports.mustNotCall = function (msg) {
|
|
|
75
76
|
};
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const buildTypes = {
|
|
80
|
+
Release: 'Release',
|
|
81
|
+
Debug: 'Debug'
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
async function checkBuildType (buildType) {
|
|
85
|
+
try {
|
|
86
|
+
await access(path.join(path.resolve('./test/build'), buildType));
|
|
87
|
+
return true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function whichBuildType () {
|
|
94
|
+
let buildType = 'Release';
|
|
95
|
+
const envBuildType = process.env.NODE_API_BUILD_CONFIG;
|
|
96
|
+
if (envBuildType) {
|
|
97
|
+
if (Object.values(buildTypes).includes(envBuildType)) {
|
|
98
|
+
if (await checkBuildType(envBuildType)) {
|
|
99
|
+
buildType = envBuildType;
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error(`The ${envBuildType} build doesn't exists.`);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
throw new Error('Invalid value for NODE_API_BUILD_CONFIG environment variable. It should be set to Release or Debug.');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return buildType;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.whichBuildType = whichBuildType;
|
|
80
111
|
|
|
112
|
+
exports.runTest = async function (test, buildType, buildPathRoot = process.env.BUILD_PATH || '') {
|
|
113
|
+
buildType = buildType || await whichBuildType();
|
|
81
114
|
const bindings = [
|
|
82
115
|
path.join(buildPathRoot, `../build/${buildType}/binding.node`),
|
|
83
116
|
path.join(buildPathRoot, `../build/${buildType}/binding_noexcept.node`),
|
|
@@ -92,7 +125,7 @@ exports.runTest = async function (test, buildType, buildPathRoot = process.env.B
|
|
|
92
125
|
};
|
|
93
126
|
|
|
94
127
|
exports.runTestWithBindingPath = async function (test, buildType, buildPathRoot = process.env.BUILD_PATH || '') {
|
|
95
|
-
buildType = buildType ||
|
|
128
|
+
buildType = buildType || await whichBuildType();
|
|
96
129
|
|
|
97
130
|
const bindings = [
|
|
98
131
|
path.join(buildPathRoot, `../build/${buildType}/binding.node`),
|
|
@@ -107,7 +140,7 @@ exports.runTestWithBindingPath = async function (test, buildType, buildPathRoot
|
|
|
107
140
|
};
|
|
108
141
|
|
|
109
142
|
exports.runTestWithBuildType = async function (test, buildType) {
|
|
110
|
-
buildType = buildType ||
|
|
143
|
+
buildType = buildType || await whichBuildType();
|
|
111
144
|
|
|
112
145
|
await Promise.resolve(test(buildType))
|
|
113
146
|
.finally(exports.mustCall());
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
module.exports = require('../common').runTest(test);
|
|
5
5
|
|
|
6
|
-
function test(binding) {
|
|
7
|
-
function testDataViewCreation(factory, arrayBuffer, offset, length) {
|
|
6
|
+
function test (binding) {
|
|
7
|
+
function testDataViewCreation (factory, arrayBuffer, offset, length) {
|
|
8
8
|
const view = factory(arrayBuffer, offset, length);
|
|
9
|
-
offset = offset
|
|
9
|
+
offset = offset || 0;
|
|
10
10
|
assert.ok(dataview.getArrayBuffer(view) instanceof ArrayBuffer);
|
|
11
11
|
assert.strictEqual(dataview.getArrayBuffer(view), arrayBuffer);
|
|
12
12
|
assert.strictEqual(dataview.getByteOffset(view), offset);
|
|
13
13
|
assert.strictEqual(dataview.getByteLength(view),
|
|
14
|
-
|
|
14
|
+
length || arrayBuffer.byteLength - offset);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function testInvalidRange(factory, arrayBuffer, offset, length) {
|
|
17
|
+
function testInvalidRange (factory, arrayBuffer, offset, length) {
|
|
18
18
|
assert.throws(() => {
|
|
19
19
|
factory(arrayBuffer, offset, length);
|
|
20
20
|
}, RangeError);
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
+
/* eslint-disable no-eval */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
const assert = require('assert');
|
|
4
5
|
|
|
5
6
|
module.exports = require('../common').runTest(test);
|
|
6
7
|
|
|
7
|
-
function test(binding) {
|
|
8
|
-
function expected(type, value) {
|
|
8
|
+
function test (binding) {
|
|
9
|
+
function expected (type, value) {
|
|
9
10
|
return eval(`(new ${type}Array([${value}]))[0]`);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
function nativeReadDataView(dataview, type, offset, value) {
|
|
13
|
+
function nativeReadDataView (dataview, type, offset, value) {
|
|
13
14
|
return eval(`binding.dataview_read_write.get${type}(dataview, offset)`);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
function nativeWriteDataView(dataview, type, offset, value) {
|
|
17
|
+
function nativeWriteDataView (dataview, type, offset, value) {
|
|
17
18
|
eval(`binding.dataview_read_write.set${type}(dataview, offset, value)`);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
function isLittleEndian () {
|
|
21
23
|
const buffer = new ArrayBuffer(2);
|
|
22
24
|
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
|
23
25
|
return new Int16Array(buffer)[0] === 256;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
function jsReadDataView(dataview, type, offset, value) {
|
|
28
|
+
function jsReadDataView (dataview, type, offset, value) {
|
|
27
29
|
return eval(`dataview.get${type}(offset, isLittleEndian())`);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
function jsWriteDataView(dataview, type, offset, value) {
|
|
32
|
+
function jsWriteDataView (dataview, type, offset, value) {
|
|
31
33
|
eval(`dataview.set${type}(offset, value, isLittleEndian())`);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
function testReadData(dataview, type, offset, value) {
|
|
36
|
+
function testReadData (dataview, type, offset, value) {
|
|
35
37
|
jsWriteDataView(dataview, type, offset, 0);
|
|
36
38
|
assert.strictEqual(jsReadDataView(dataview, type, offset), 0);
|
|
37
39
|
|
|
38
40
|
jsWriteDataView(dataview, type, offset, value);
|
|
39
41
|
assert.strictEqual(
|
|
40
|
-
|
|
42
|
+
nativeReadDataView(dataview, type, offset), expected(type, value));
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
function testWriteData(dataview, type, offset, value) {
|
|
45
|
+
function testWriteData (dataview, type, offset, value) {
|
|
44
46
|
jsWriteDataView(dataview, type, offset, 0);
|
|
45
47
|
assert.strictEqual(jsReadDataView(dataview, type, offset), 0);
|
|
46
48
|
|
|
47
49
|
nativeWriteDataView(dataview, type, offset, value);
|
|
48
50
|
assert.strictEqual(
|
|
49
|
-
|
|
51
|
+
jsReadDataView(dataview, type, offset), expected(type, value));
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function testInvalidOffset(dataview, type, offset, value) {
|
|
54
|
+
function testInvalidOffset (dataview, type, offset, value) {
|
|
53
55
|
assert.throws(() => {
|
|
54
56
|
nativeReadDataView(dataview, type, offset);
|
|
55
57
|
}, RangeError);
|
|
@@ -26,7 +26,8 @@ Value ValueOf(const CallbackInfo& info) {
|
|
|
26
26
|
Value OperatorValue(const CallbackInfo& info) {
|
|
27
27
|
Date input = info[0].As<Date>();
|
|
28
28
|
|
|
29
|
-
return Boolean::New(info.Env(),
|
|
29
|
+
return Boolean::New(info.Env(),
|
|
30
|
+
input.ValueOf() == static_cast<double>(input));
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
} // anonymous namespace
|
|
@@ -4,12 +4,12 @@ const assert = require('assert');
|
|
|
4
4
|
|
|
5
5
|
module.exports = require('./common').runTest(test);
|
|
6
6
|
|
|
7
|
-
function test(binding) {
|
|
7
|
+
function test (binding) {
|
|
8
8
|
const {
|
|
9
9
|
CreateDate,
|
|
10
10
|
IsDate,
|
|
11
11
|
ValueOf,
|
|
12
|
-
OperatorValue
|
|
12
|
+
OperatorValue
|
|
13
13
|
} = binding.date;
|
|
14
14
|
assert.deepStrictEqual(CreateDate(0), new Date(0));
|
|
15
15
|
assert.strictEqual(IsDate(new Date(0)), true);
|
|
@@ -20,6 +20,13 @@ static void cleanupVoid() {
|
|
|
20
20
|
static int secret1 = 42;
|
|
21
21
|
static int secret2 = 43;
|
|
22
22
|
|
|
23
|
+
class TestClass {
|
|
24
|
+
public:
|
|
25
|
+
Env::CleanupHook<void (*)(void* arg), int> hook;
|
|
26
|
+
|
|
27
|
+
void removeHook(Env env) { hook.Remove(env); }
|
|
28
|
+
};
|
|
29
|
+
|
|
23
30
|
Value AddHooks(const CallbackInfo& info) {
|
|
24
31
|
auto env = info.Env();
|
|
25
32
|
|
|
@@ -72,6 +79,11 @@ Value AddHooks(const CallbackInfo& info) {
|
|
|
72
79
|
added += !hook5.IsEmpty();
|
|
73
80
|
added += !hook6.IsEmpty();
|
|
74
81
|
|
|
82
|
+
// Test store a hook in a member class variable
|
|
83
|
+
auto myclass = TestClass();
|
|
84
|
+
myclass.hook = env.AddCleanupHook(cleanup, &secret1);
|
|
85
|
+
myclass.removeHook(env);
|
|
86
|
+
|
|
75
87
|
return Number::New(env, added);
|
|
76
88
|
}
|
|
77
89
|
|
|
@@ -3,54 +3,53 @@
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
|
|
5
5
|
if (process.argv[2] === 'runInChildProcess') {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const bindingPath = process.argv[3];
|
|
7
|
+
const removeHooks = process.argv[4] === 'true';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = require('./common').runTestWithBindingPath(test);
|
|
9
|
+
const binding = require(bindingPath);
|
|
10
|
+
const actualAdded = binding.env_cleanup.addHooks(removeHooks);
|
|
11
|
+
const expectedAdded = removeHooks === true ? 0 : 8;
|
|
12
|
+
assert(actualAdded === expectedAdded, 'Incorrect number of hooks added');
|
|
13
|
+
} else {
|
|
14
|
+
module.exports = require('./common').runTestWithBindingPath(test);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
function test(bindingPath) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
function test (bindingPath) {
|
|
18
|
+
for (const removeHooks of [false, true]) {
|
|
19
|
+
const { status, output } = require('./napi_child').spawnSync(
|
|
20
|
+
process.execPath,
|
|
21
|
+
[
|
|
22
|
+
__filename,
|
|
23
|
+
'runInChildProcess',
|
|
24
|
+
bindingPath,
|
|
25
|
+
removeHooks
|
|
26
|
+
],
|
|
27
|
+
{ encoding: 'utf8' }
|
|
28
|
+
);
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const stdout = output[1].trim();
|
|
31
|
+
/**
|
|
33
32
|
* There is no need to sort the lines, as per Node-API documentation:
|
|
34
33
|
* > The hooks will be called in reverse order, i.e. the most recently
|
|
35
34
|
* > added one will be called first.
|
|
36
35
|
*/
|
|
37
|
-
|
|
36
|
+
const lines = stdout.split(/[\r\n]+/);
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
assert(status === 0, `Process aborted with status ${status}`);
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
40
|
+
if (removeHooks) {
|
|
41
|
+
assert.deepStrictEqual(lines, [''], 'Child process had console output when none expected');
|
|
42
|
+
} else {
|
|
43
|
+
assert.deepStrictEqual(lines, [
|
|
44
|
+
'lambda cleanup()',
|
|
45
|
+
'lambda cleanup(void)',
|
|
46
|
+
'lambda cleanup(42)',
|
|
47
|
+
'static cleanup()',
|
|
48
|
+
'static cleanup()',
|
|
49
|
+
'static cleanup(43)',
|
|
50
|
+
'static cleanup(42)',
|
|
51
|
+
'static cleanup(42)'
|
|
52
|
+
], 'Child process console output mismisatch');
|
|
55
53
|
}
|
|
54
|
+
}
|
|
56
55
|
}
|
|
@@ -140,7 +140,7 @@ void CatchAndRethrowErrorThatEscapesScope(const CallbackInfo& info) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
#else
|
|
143
|
+
#else // NAPI_CPP_EXCEPTIONS
|
|
144
144
|
|
|
145
145
|
void ThrowJSError(const CallbackInfo& info) {
|
|
146
146
|
std::string message = info[0].As<String>().Utf8Value();
|
|
@@ -219,7 +219,7 @@ void CatchAndRethrowErrorThatEscapesScope(const CallbackInfo& info) {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
#endif
|
|
222
|
+
#endif // NAPI_CPP_EXCEPTIONS
|
|
223
223
|
|
|
224
224
|
void ThrowFatalError(const CallbackInfo& /*info*/) {
|
|
225
225
|
Error::Fatal("Error::ThrowFatalError", "This is a fatal error");
|
|
@@ -261,7 +261,7 @@ void ThrowDefaultError(const CallbackInfo& info) {
|
|
|
261
261
|
NAPI_THROW_IF_FAILED_VOID(env, status);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
}
|
|
264
|
+
} // end anonymous namespace
|
|
265
265
|
|
|
266
266
|
Object InitError(Env env) {
|
|
267
267
|
Object exports = Object::New(env);
|
|
@@ -275,9 +275,10 @@ Object InitError(Env env) {
|
|
|
275
275
|
exports["catchErrorMessage"] = Function::New(env, CatchErrorMessage);
|
|
276
276
|
exports["doNotCatch"] = Function::New(env, DoNotCatch);
|
|
277
277
|
exports["catchAndRethrowError"] = Function::New(env, CatchAndRethrowError);
|
|
278
|
-
exports["throwErrorThatEscapesScope"] =
|
|
278
|
+
exports["throwErrorThatEscapesScope"] =
|
|
279
|
+
Function::New(env, ThrowErrorThatEscapesScope);
|
|
279
280
|
exports["catchAndRethrowErrorThatEscapesScope"] =
|
|
280
|
-
|
|
281
|
+
Function::New(env, CatchAndRethrowErrorThatEscapesScope);
|
|
281
282
|
exports["throwFatalError"] = Function::New(env, ThrowFatalError);
|
|
282
283
|
exports["throwDefaultError"] = Function::New(env, ThrowDefaultError);
|
|
283
284
|
exports["resetPromises"] = Function::New(env, ResetPromises);
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
const assert = require('assert');
|
|
4
|
+
const { whichBuildType } = require('./common');
|
|
4
5
|
|
|
5
6
|
// These tests ensure that Error types can be used in a terminating
|
|
6
7
|
// environment without triggering any fatal errors.
|
|
7
8
|
|
|
8
9
|
if (process.argv[2] === 'runInChildProcess') {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const bindingPath = process.argv[3];
|
|
11
|
+
const indexForTestCase = Number(process.argv[4]);
|
|
11
12
|
|
|
12
|
-
const binding = require(
|
|
13
|
+
const binding = require(bindingPath);
|
|
13
14
|
|
|
14
15
|
// Use C++ promises to ensure the worker thread is terminated right
|
|
15
16
|
// before running the testable code in the binding.
|
|
16
17
|
|
|
17
|
-
binding.error.resetPromises()
|
|
18
|
+
binding.error.resetPromises();
|
|
18
19
|
|
|
19
20
|
const { Worker } = require('worker_threads');
|
|
20
21
|
|
|
@@ -23,73 +24,76 @@ if (process.argv[2] === 'runInChildProcess') {
|
|
|
23
24
|
{
|
|
24
25
|
argv: [
|
|
25
26
|
'runInWorkerThread',
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
bindingPath,
|
|
28
|
+
indexForTestCase
|
|
28
29
|
]
|
|
29
30
|
}
|
|
30
31
|
);
|
|
31
32
|
|
|
32
|
-
binding.error.waitForWorkerThread()
|
|
33
|
+
binding.error.waitForWorkerThread();
|
|
33
34
|
|
|
34
35
|
worker.terminate();
|
|
35
36
|
|
|
36
|
-
binding.error.releaseWorkerThread()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
binding.error.releaseWorkerThread();
|
|
38
|
+
} else {
|
|
39
|
+
if (process.argv[2] === 'runInWorkerThread') {
|
|
40
|
+
const bindingPath = process.argv[3];
|
|
41
|
+
const indexForTestCase = Number(process.argv[4]);
|
|
42
|
+
|
|
43
|
+
const binding = require(bindingPath);
|
|
44
|
+
|
|
45
|
+
switch (indexForTestCase) {
|
|
46
|
+
case 0:
|
|
47
|
+
binding.error.throwJSError('test', true);
|
|
48
|
+
break;
|
|
49
|
+
case 1:
|
|
50
|
+
binding.error.throwTypeError('test', true);
|
|
51
|
+
break;
|
|
52
|
+
case 2:
|
|
53
|
+
binding.error.throwRangeError('test', true);
|
|
54
|
+
break;
|
|
55
|
+
case 3:
|
|
56
|
+
binding.error.throwDefaultError(false, true);
|
|
57
|
+
break;
|
|
58
|
+
case 4:
|
|
59
|
+
binding.error.throwDefaultError(true, true);
|
|
60
|
+
break;
|
|
61
|
+
default: assert.fail('Invalid index');
|
|
62
|
+
}
|
|
40
63
|
|
|
41
|
-
|
|
42
|
-
const binding_path = process.argv[3];
|
|
43
|
-
const index_for_test_case = Number(process.argv[4]);
|
|
44
|
-
|
|
45
|
-
const binding = require(binding_path);
|
|
46
|
-
|
|
47
|
-
switch (index_for_test_case) {
|
|
48
|
-
case 0:
|
|
49
|
-
binding.error.throwJSError('test', true);
|
|
50
|
-
break;
|
|
51
|
-
case 1:
|
|
52
|
-
binding.error.throwTypeError('test', true);
|
|
53
|
-
break;
|
|
54
|
-
case 2:
|
|
55
|
-
binding.error.throwRangeError('test', true);
|
|
56
|
-
break;
|
|
57
|
-
case 3:
|
|
58
|
-
binding.error.throwDefaultError(false, true);
|
|
59
|
-
break;
|
|
60
|
-
case 4:
|
|
61
|
-
binding.error.throwDefaultError(true, true);
|
|
62
|
-
break;
|
|
63
|
-
default: assert.fail('Invalid index');
|
|
64
|
+
assert.fail('This should not be reachable');
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
}
|
|
67
|
+
wrapTest();
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
test(`./build/${buildType}/
|
|
72
|
-
test(`./build/${buildType}/
|
|
73
|
-
test(`./build/${buildType}/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < number_of_test_cases; ++i) {
|
|
79
|
-
const child_process = require('./napi_child').spawnSync(
|
|
80
|
-
process.execPath,
|
|
81
|
-
[
|
|
82
|
-
__filename,
|
|
83
|
-
'runInChildProcess',
|
|
84
|
-
bindingPath,
|
|
85
|
-
i,
|
|
86
|
-
]
|
|
87
|
-
);
|
|
69
|
+
async function wrapTest () {
|
|
70
|
+
const buildType = await whichBuildType();
|
|
71
|
+
test(`./build/${buildType}/binding.node`, true);
|
|
72
|
+
test(`./build/${buildType}/binding_noexcept.node`, true);
|
|
73
|
+
test(`./build/${buildType}/binding_swallowexcept.node`, false);
|
|
74
|
+
test(`./build/${buildType}/binding_swallowexcept_noexcept.node`, false);
|
|
75
|
+
test(`./build/${buildType}/binding_custom_namespace.node`, true);
|
|
76
|
+
}
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
function test (bindingPath, processShouldAbort) {
|
|
79
|
+
const numberOfTestCases = 5;
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i < numberOfTestCases; ++i) {
|
|
82
|
+
const childProcess = require('./napi_child').spawnSync(
|
|
83
|
+
process.execPath,
|
|
84
|
+
[
|
|
85
|
+
__filename,
|
|
86
|
+
'runInChildProcess',
|
|
87
|
+
bindingPath,
|
|
88
|
+
i
|
|
89
|
+
]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (processShouldAbort) {
|
|
93
|
+
assert(childProcess.status !== 0, `Test case ${bindingPath} ${i} failed: Process exited with status code 0.`);
|
|
94
|
+
} else {
|
|
95
|
+
assert(childProcess.status === 0, `Test case ${bindingPath} ${i} failed: Process status ${childProcess.status} is non-zero`);
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
}
|