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
package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
|
|
5
|
-
const isMainProcess = process.argv[1]
|
|
5
|
+
const isMainProcess = process.argv[1] !== __filename;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* In order to test that the event loop exits even with an active TSFN, we need
|
|
@@ -11,43 +11,88 @@ const isMainProcess = process.argv[1] != __filename;
|
|
|
11
11
|
* - Child process: creates TSFN. Native module Unref's via setTimeout after some time but does NOT call Release.
|
|
12
12
|
*
|
|
13
13
|
* Main process should expect child process to exit.
|
|
14
|
+
*
|
|
15
|
+
* We also added a new test case for `Ref`. The idea being, if a TSFN is active, the event loop that it belongs to should not exit
|
|
16
|
+
* Our setup is similar to the test for the `Unref` case, with the difference being now we are expecting the child process to hang
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
19
|
if (isMainProcess) {
|
|
17
20
|
module.exports = require('../common').runTestWithBindingPath(test);
|
|
18
21
|
} else {
|
|
19
|
-
|
|
22
|
+
const isTestingRef = (process.argv[3] === 'true');
|
|
23
|
+
|
|
24
|
+
if (isTestingRef) {
|
|
25
|
+
execTSFNRefTest(process.argv[2]);
|
|
26
|
+
} else {
|
|
27
|
+
execTSFNUnrefTest(process.argv[2]);
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
function testUnRefCallback (resolve, reject, bindingFile) {
|
|
32
|
+
const child = require('../napi_child').spawn(process.argv[0], [
|
|
33
|
+
'--expose-gc', __filename, bindingFile, false
|
|
34
|
+
], { stdio: 'inherit' });
|
|
35
|
+
|
|
36
|
+
let timeout = setTimeout(function () {
|
|
37
|
+
child.kill();
|
|
38
|
+
timeout = 0;
|
|
39
|
+
reject(new Error('Expected child to die'));
|
|
40
|
+
}, 5000);
|
|
41
|
+
|
|
42
|
+
child.on('error', (err) => {
|
|
43
|
+
clearTimeout(timeout);
|
|
44
|
+
timeout = 0;
|
|
45
|
+
reject(new Error(err));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.on('close', (code) => {
|
|
49
|
+
if (timeout) clearTimeout(timeout);
|
|
50
|
+
assert.strictEqual(code, 0, 'Expected return value 0');
|
|
51
|
+
resolve();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function testRefCallback (resolve, reject, bindingFile) {
|
|
56
|
+
const child = require('../napi_child').spawn(process.argv[0], [
|
|
57
|
+
'--expose-gc', __filename, bindingFile, true
|
|
58
|
+
], { stdio: 'inherit' });
|
|
59
|
+
|
|
60
|
+
let timeout = setTimeout(function () {
|
|
61
|
+
child.kill();
|
|
62
|
+
timeout = 0;
|
|
63
|
+
resolve();
|
|
64
|
+
}, 1000);
|
|
65
|
+
|
|
66
|
+
child.on('error', (err) => {
|
|
67
|
+
clearTimeout(timeout);
|
|
68
|
+
timeout = 0;
|
|
69
|
+
reject(new Error(err));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
child.on('close', (code) => {
|
|
73
|
+
if (timeout) clearTimeout(timeout);
|
|
74
|
+
|
|
75
|
+
reject(new Error('We expected Child to hang'));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function test (bindingFile) {
|
|
80
|
+
// Main process
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
testUnRefCallback(resolve, reject, bindingFile);
|
|
83
|
+
}).then(() => {
|
|
25
84
|
return new Promise((resolve, reject) => {
|
|
26
|
-
|
|
27
|
-
'--expose-gc', __filename, bindingFile
|
|
28
|
-
], { stdio: 'inherit' });
|
|
29
|
-
|
|
30
|
-
let timeout = setTimeout( function() {
|
|
31
|
-
child.kill();
|
|
32
|
-
timeout = 0;
|
|
33
|
-
reject(new Error("Expected child to die"));
|
|
34
|
-
}, 5000);
|
|
35
|
-
|
|
36
|
-
child.on("error", (err) => {
|
|
37
|
-
clearTimeout(timeout);
|
|
38
|
-
timeout = 0;
|
|
39
|
-
reject(new Error(err));
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
child.on("close", (code) => {
|
|
43
|
-
if (timeout) clearTimeout(timeout);
|
|
44
|
-
assert.strictEqual(code, 0, "Expected return value 0");
|
|
45
|
-
resolve();
|
|
46
|
-
});
|
|
85
|
+
testRefCallback(resolve, reject, bindingFile);
|
|
47
86
|
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function execTSFNUnrefTest (bindingFile) {
|
|
91
|
+
const binding = require(bindingFile);
|
|
92
|
+
binding.typed_threadsafe_function_unref.testUnref({}, () => { });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function execTSFNRefTest (bindingFile) {
|
|
96
|
+
const binding = require(bindingFile);
|
|
97
|
+
binding.typed_threadsafe_function_unref.testRef({}, () => { });
|
|
53
98
|
}
|
|
@@ -4,10 +4,10 @@ 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
|
[
|
|
9
9
|
['bigint64', BigInt64Array],
|
|
10
|
-
['biguint64', BigUint64Array]
|
|
10
|
+
['biguint64', BigUint64Array]
|
|
11
11
|
].forEach(([type, Constructor]) => {
|
|
12
12
|
try {
|
|
13
13
|
const length = 4;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
#include <vector>
|
|
1
2
|
#include "napi.h"
|
|
2
|
-
|
|
3
3
|
using namespace Napi;
|
|
4
4
|
|
|
5
5
|
#if defined(NAPI_HAS_CONSTEXPR)
|
|
6
|
-
#define NAPI_TYPEDARRAY_NEW(className, env, length, type)
|
|
7
|
-
|
|
6
|
+
#define NAPI_TYPEDARRAY_NEW(className, env, length, type) \
|
|
7
|
+
className::New(env, length)
|
|
8
|
+
#define NAPI_TYPEDARRAY_NEW_BUFFER( \
|
|
9
|
+
className, env, length, buffer, bufferOffset, type) \
|
|
8
10
|
className::New(env, length, buffer, bufferOffset)
|
|
9
11
|
#else
|
|
10
|
-
#define NAPI_TYPEDARRAY_NEW(className, env, length, type)
|
|
11
|
-
|
|
12
|
+
#define NAPI_TYPEDARRAY_NEW(className, env, length, type) \
|
|
13
|
+
className::New(env, length, type)
|
|
14
|
+
#define NAPI_TYPEDARRAY_NEW_BUFFER( \
|
|
15
|
+
className, env, length, buffer, bufferOffset, type) \
|
|
12
16
|
className::New(env, length, buffer, bufferOffset, type)
|
|
13
17
|
#endif
|
|
14
18
|
|
|
@@ -18,91 +22,253 @@ Value CreateTypedArray(const CallbackInfo& info) {
|
|
|
18
22
|
std::string arrayType = info[0].As<String>();
|
|
19
23
|
size_t length = info[1].As<Number>().Uint32Value();
|
|
20
24
|
ArrayBuffer buffer = info[2].As<ArrayBuffer>();
|
|
21
|
-
size_t bufferOffset =
|
|
25
|
+
size_t bufferOffset =
|
|
26
|
+
info[3].IsUndefined() ? 0 : info[3].As<Number>().Uint32Value();
|
|
22
27
|
|
|
23
28
|
if (arrayType == "int8") {
|
|
24
|
-
return buffer.IsUndefined()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
return buffer.IsUndefined()
|
|
30
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
31
|
+
Int8Array, info.Env(), length, napi_int8_array)
|
|
32
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Int8Array,
|
|
33
|
+
info.Env(),
|
|
34
|
+
length,
|
|
35
|
+
buffer,
|
|
36
|
+
bufferOffset,
|
|
37
|
+
napi_int8_array);
|
|
28
38
|
} else if (arrayType == "uint8") {
|
|
29
|
-
return buffer.IsUndefined()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
return buffer.IsUndefined()
|
|
40
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
41
|
+
Uint8Array, info.Env(), length, napi_uint8_array)
|
|
42
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Uint8Array,
|
|
43
|
+
info.Env(),
|
|
44
|
+
length,
|
|
45
|
+
buffer,
|
|
46
|
+
bufferOffset,
|
|
47
|
+
napi_uint8_array);
|
|
33
48
|
} else if (arrayType == "uint8_clamped") {
|
|
34
|
-
return buffer.IsUndefined()
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
return buffer.IsUndefined()
|
|
50
|
+
? Uint8Array::New(info.Env(), length, napi_uint8_clamped_array)
|
|
51
|
+
: Uint8Array::New(info.Env(),
|
|
52
|
+
length,
|
|
53
|
+
buffer,
|
|
54
|
+
bufferOffset,
|
|
55
|
+
napi_uint8_clamped_array);
|
|
37
56
|
} else if (arrayType == "int16") {
|
|
38
|
-
return buffer.IsUndefined()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
57
|
+
return buffer.IsUndefined()
|
|
58
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
59
|
+
Int16Array, info.Env(), length, napi_int16_array)
|
|
60
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Int16Array,
|
|
61
|
+
info.Env(),
|
|
62
|
+
length,
|
|
63
|
+
buffer,
|
|
64
|
+
bufferOffset,
|
|
65
|
+
napi_int16_array);
|
|
42
66
|
} else if (arrayType == "uint16") {
|
|
43
|
-
return buffer.IsUndefined()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
return buffer.IsUndefined()
|
|
68
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
69
|
+
Uint16Array, info.Env(), length, napi_uint16_array)
|
|
70
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Uint16Array,
|
|
71
|
+
info.Env(),
|
|
72
|
+
length,
|
|
73
|
+
buffer,
|
|
74
|
+
bufferOffset,
|
|
75
|
+
napi_uint16_array);
|
|
47
76
|
} else if (arrayType == "int32") {
|
|
48
|
-
return buffer.IsUndefined()
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
return buffer.IsUndefined()
|
|
78
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
79
|
+
Int32Array, info.Env(), length, napi_int32_array)
|
|
80
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Int32Array,
|
|
81
|
+
info.Env(),
|
|
82
|
+
length,
|
|
83
|
+
buffer,
|
|
84
|
+
bufferOffset,
|
|
85
|
+
napi_int32_array);
|
|
52
86
|
} else if (arrayType == "uint32") {
|
|
53
|
-
return buffer.IsUndefined()
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
return buffer.IsUndefined()
|
|
88
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
89
|
+
Uint32Array, info.Env(), length, napi_uint32_array)
|
|
90
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Uint32Array,
|
|
91
|
+
info.Env(),
|
|
92
|
+
length,
|
|
93
|
+
buffer,
|
|
94
|
+
bufferOffset,
|
|
95
|
+
napi_uint32_array);
|
|
57
96
|
} else if (arrayType == "float32") {
|
|
58
|
-
return buffer.IsUndefined()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
97
|
+
return buffer.IsUndefined()
|
|
98
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
99
|
+
Float32Array, info.Env(), length, napi_float32_array)
|
|
100
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Float32Array,
|
|
101
|
+
info.Env(),
|
|
102
|
+
length,
|
|
103
|
+
buffer,
|
|
104
|
+
bufferOffset,
|
|
105
|
+
napi_float32_array);
|
|
62
106
|
} else if (arrayType == "float64") {
|
|
63
|
-
return buffer.IsUndefined()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
107
|
+
return buffer.IsUndefined()
|
|
108
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
109
|
+
Float64Array, info.Env(), length, napi_float64_array)
|
|
110
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array,
|
|
111
|
+
info.Env(),
|
|
112
|
+
length,
|
|
113
|
+
buffer,
|
|
114
|
+
bufferOffset,
|
|
115
|
+
napi_float64_array);
|
|
67
116
|
#if (NAPI_VERSION > 5)
|
|
68
117
|
} else if (arrayType == "bigint64") {
|
|
69
|
-
return buffer.IsUndefined()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
118
|
+
return buffer.IsUndefined()
|
|
119
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
120
|
+
BigInt64Array, info.Env(), length, napi_bigint64_array)
|
|
121
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(BigInt64Array,
|
|
122
|
+
info.Env(),
|
|
123
|
+
length,
|
|
124
|
+
buffer,
|
|
125
|
+
bufferOffset,
|
|
126
|
+
napi_bigint64_array);
|
|
73
127
|
} else if (arrayType == "biguint64") {
|
|
74
|
-
return buffer.IsUndefined()
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
128
|
+
return buffer.IsUndefined()
|
|
129
|
+
? NAPI_TYPEDARRAY_NEW(
|
|
130
|
+
BigUint64Array, info.Env(), length, napi_biguint64_array)
|
|
131
|
+
: NAPI_TYPEDARRAY_NEW_BUFFER(BigUint64Array,
|
|
132
|
+
info.Env(),
|
|
133
|
+
length,
|
|
134
|
+
buffer,
|
|
135
|
+
bufferOffset,
|
|
136
|
+
napi_biguint64_array);
|
|
78
137
|
#endif
|
|
79
138
|
} else {
|
|
80
|
-
Error::New(info.Env(), "Invalid typed-array type.")
|
|
139
|
+
Error::New(info.Env(), "Invalid typed-array type.")
|
|
140
|
+
.ThrowAsJavaScriptException();
|
|
81
141
|
return Value();
|
|
82
142
|
}
|
|
83
143
|
}
|
|
84
144
|
|
|
85
145
|
Value CreateInvalidTypedArray(const CallbackInfo& info) {
|
|
86
|
-
return NAPI_TYPEDARRAY_NEW_BUFFER(
|
|
146
|
+
return NAPI_TYPEDARRAY_NEW_BUFFER(
|
|
147
|
+
Int8Array, info.Env(), 1, ArrayBuffer(), 0, napi_int8_array);
|
|
87
148
|
}
|
|
88
149
|
|
|
89
150
|
Value GetTypedArrayType(const CallbackInfo& info) {
|
|
90
151
|
TypedArray array = info[0].As<TypedArray>();
|
|
91
152
|
switch (array.TypedArrayType()) {
|
|
92
|
-
case napi_int8_array:
|
|
93
|
-
|
|
94
|
-
case
|
|
95
|
-
|
|
96
|
-
case
|
|
97
|
-
|
|
98
|
-
case
|
|
99
|
-
|
|
100
|
-
case
|
|
153
|
+
case napi_int8_array:
|
|
154
|
+
return String::New(info.Env(), "int8");
|
|
155
|
+
case napi_uint8_array:
|
|
156
|
+
return String::New(info.Env(), "uint8");
|
|
157
|
+
case napi_uint8_clamped_array:
|
|
158
|
+
return String::New(info.Env(), "uint8_clamped");
|
|
159
|
+
case napi_int16_array:
|
|
160
|
+
return String::New(info.Env(), "int16");
|
|
161
|
+
case napi_uint16_array:
|
|
162
|
+
return String::New(info.Env(), "uint16");
|
|
163
|
+
case napi_int32_array:
|
|
164
|
+
return String::New(info.Env(), "int32");
|
|
165
|
+
case napi_uint32_array:
|
|
166
|
+
return String::New(info.Env(), "uint32");
|
|
167
|
+
case napi_float32_array:
|
|
168
|
+
return String::New(info.Env(), "float32");
|
|
169
|
+
case napi_float64_array:
|
|
170
|
+
return String::New(info.Env(), "float64");
|
|
171
|
+
#if (NAPI_VERSION > 5)
|
|
172
|
+
case napi_bigint64_array:
|
|
173
|
+
return String::New(info.Env(), "bigint64");
|
|
174
|
+
case napi_biguint64_array:
|
|
175
|
+
return String::New(info.Env(), "biguint64");
|
|
176
|
+
#endif
|
|
177
|
+
default:
|
|
178
|
+
return String::New(info.Env(), "invalid");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
template <typename type>
|
|
183
|
+
bool TypedArrayDataIsEquivalent(TypedArrayOf<type> arr,
|
|
184
|
+
TypedArrayOf<type> inputArr) {
|
|
185
|
+
if (arr.ElementLength() != inputArr.ElementLength()) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
std::vector<type> bufferContent(arr.Data(), arr.Data() + arr.ElementLength());
|
|
189
|
+
std::vector<type> inputContent(inputArr.Data(),
|
|
190
|
+
inputArr.Data() + inputArr.ElementLength());
|
|
191
|
+
if (bufferContent != inputContent) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Value CheckBufferContent(const CallbackInfo& info) {
|
|
198
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
199
|
+
|
|
200
|
+
switch (array.TypedArrayType()) {
|
|
201
|
+
case napi_int8_array:
|
|
202
|
+
return Boolean::New(
|
|
203
|
+
info.Env(),
|
|
204
|
+
TypedArrayDataIsEquivalent<int8_t>(info[0].As<Int8Array>(),
|
|
205
|
+
info[1].As<Int8Array>()));
|
|
206
|
+
|
|
207
|
+
break;
|
|
208
|
+
case napi_uint8_array:
|
|
209
|
+
return Boolean::New(
|
|
210
|
+
info.Env(),
|
|
211
|
+
TypedArrayDataIsEquivalent<int8_t>(info[0].As<Int8Array>(),
|
|
212
|
+
info[1].As<Int8Array>()));
|
|
213
|
+
|
|
214
|
+
case napi_uint8_clamped_array:
|
|
215
|
+
return Boolean::New(
|
|
216
|
+
info.Env(),
|
|
217
|
+
TypedArrayDataIsEquivalent<uint8_t>(info[0].As<Uint8Array>(),
|
|
218
|
+
info[1].As<Uint8Array>()));
|
|
219
|
+
|
|
220
|
+
case napi_int16_array:
|
|
221
|
+
return Boolean::New(
|
|
222
|
+
info.Env(),
|
|
223
|
+
TypedArrayDataIsEquivalent<int16_t>(info[0].As<Int16Array>(),
|
|
224
|
+
info[1].As<Int16Array>()));
|
|
225
|
+
|
|
226
|
+
case napi_uint16_array:
|
|
227
|
+
return Boolean::New(
|
|
228
|
+
info.Env(),
|
|
229
|
+
TypedArrayDataIsEquivalent<uint16_t>(info[0].As<Uint16Array>(),
|
|
230
|
+
info[1].As<Uint16Array>()));
|
|
231
|
+
|
|
232
|
+
case napi_int32_array:
|
|
233
|
+
return Boolean::New(
|
|
234
|
+
info.Env(),
|
|
235
|
+
TypedArrayDataIsEquivalent<int32_t>(info[0].As<Int32Array>(),
|
|
236
|
+
info[1].As<Int32Array>()));
|
|
237
|
+
|
|
238
|
+
case napi_uint32_array:
|
|
239
|
+
return Boolean::New(
|
|
240
|
+
info.Env(),
|
|
241
|
+
TypedArrayDataIsEquivalent<uint32_t>(info[0].As<Uint32Array>(),
|
|
242
|
+
info[1].As<Uint32Array>()));
|
|
243
|
+
|
|
244
|
+
case napi_float32_array:
|
|
245
|
+
return Boolean::New(
|
|
246
|
+
info.Env(),
|
|
247
|
+
TypedArrayDataIsEquivalent<float>(info[0].As<Float32Array>(),
|
|
248
|
+
info[1].As<Float32Array>()));
|
|
249
|
+
|
|
250
|
+
case napi_float64_array:
|
|
251
|
+
return Boolean::New(
|
|
252
|
+
info.Env(),
|
|
253
|
+
TypedArrayDataIsEquivalent<double>(info[0].As<Float64Array>(),
|
|
254
|
+
info[1].As<Float64Array>()));
|
|
255
|
+
|
|
101
256
|
#if (NAPI_VERSION > 5)
|
|
102
|
-
case napi_bigint64_array:
|
|
103
|
-
|
|
257
|
+
case napi_bigint64_array:
|
|
258
|
+
return Boolean::New(
|
|
259
|
+
info.Env(),
|
|
260
|
+
TypedArrayDataIsEquivalent<int64_t>(info[0].As<BigInt64Array>(),
|
|
261
|
+
info[1].As<BigInt64Array>()));
|
|
262
|
+
|
|
263
|
+
case napi_biguint64_array:
|
|
264
|
+
return Boolean::New(
|
|
265
|
+
info.Env(),
|
|
266
|
+
TypedArrayDataIsEquivalent<uint64_t>(info[0].As<BigUint64Array>(),
|
|
267
|
+
info[1].As<BigUint64Array>()));
|
|
268
|
+
|
|
104
269
|
#endif
|
|
105
|
-
default:
|
|
270
|
+
default:
|
|
271
|
+
return Boolean::New(info.Env(), false);
|
|
106
272
|
}
|
|
107
273
|
}
|
|
108
274
|
|
|
@@ -111,6 +277,21 @@ Value GetTypedArrayLength(const CallbackInfo& info) {
|
|
|
111
277
|
return Number::New(info.Env(), static_cast<double>(array.ElementLength()));
|
|
112
278
|
}
|
|
113
279
|
|
|
280
|
+
Value GetTypedArraySize(const CallbackInfo& info) {
|
|
281
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
282
|
+
return Number::New(info.Env(), static_cast<double>(array.ElementSize()));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
Value GetTypedArrayByteOffset(const CallbackInfo& info) {
|
|
286
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
287
|
+
return Number::New(info.Env(), static_cast<double>(array.ByteOffset()));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
Value GetTypedArrayByteLength(const CallbackInfo& info) {
|
|
291
|
+
TypedArray array = info[0].As<TypedArray>();
|
|
292
|
+
return Number::New(info.Env(), static_cast<double>(array.ByteLength()));
|
|
293
|
+
}
|
|
294
|
+
|
|
114
295
|
Value GetTypedArrayBuffer(const CallbackInfo& info) {
|
|
115
296
|
TypedArray array = info[0].As<TypedArray>();
|
|
116
297
|
return array.ArrayBuffer();
|
|
@@ -145,7 +326,8 @@ Value GetTypedArrayElement(const CallbackInfo& info) {
|
|
|
145
326
|
return BigInt::New(info.Env(), array.As<BigUint64Array>()[index]);
|
|
146
327
|
#endif
|
|
147
328
|
default:
|
|
148
|
-
Error::New(info.Env(), "Invalid typed-array type.")
|
|
329
|
+
Error::New(info.Env(), "Invalid typed-array type.")
|
|
330
|
+
.ThrowAsJavaScriptException();
|
|
149
331
|
return Value();
|
|
150
332
|
}
|
|
151
333
|
}
|
|
@@ -168,7 +350,8 @@ void SetTypedArrayElement(const CallbackInfo& info) {
|
|
|
168
350
|
array.As<Int16Array>()[index] = static_cast<int16_t>(value.Int32Value());
|
|
169
351
|
break;
|
|
170
352
|
case napi_uint16_array:
|
|
171
|
-
array.As<Uint16Array>()[index] =
|
|
353
|
+
array.As<Uint16Array>()[index] =
|
|
354
|
+
static_cast<uint16_t>(value.Uint32Value());
|
|
172
355
|
break;
|
|
173
356
|
case napi_int32_array:
|
|
174
357
|
array.As<Int32Array>()[index] = value.Int32Value();
|
|
@@ -185,32 +368,42 @@ void SetTypedArrayElement(const CallbackInfo& info) {
|
|
|
185
368
|
#if (NAPI_VERSION > 5)
|
|
186
369
|
case napi_bigint64_array: {
|
|
187
370
|
bool lossless;
|
|
188
|
-
array.As<BigInt64Array>()[index] =
|
|
371
|
+
array.As<BigInt64Array>()[index] =
|
|
372
|
+
value.As<BigInt>().Int64Value(&lossless);
|
|
189
373
|
break;
|
|
190
374
|
}
|
|
191
375
|
case napi_biguint64_array: {
|
|
192
376
|
bool lossless;
|
|
193
|
-
array.As<BigUint64Array>()[index] =
|
|
377
|
+
array.As<BigUint64Array>()[index] =
|
|
378
|
+
value.As<BigInt>().Uint64Value(&lossless);
|
|
194
379
|
break;
|
|
195
380
|
}
|
|
196
381
|
#endif
|
|
197
382
|
default:
|
|
198
|
-
Error::New(info.Env(), "Invalid typed-array type.")
|
|
383
|
+
Error::New(info.Env(), "Invalid typed-array type.")
|
|
384
|
+
.ThrowAsJavaScriptException();
|
|
199
385
|
}
|
|
200
386
|
}
|
|
201
387
|
|
|
202
|
-
}
|
|
388
|
+
} // end anonymous namespace
|
|
203
389
|
|
|
204
390
|
Object InitTypedArray(Env env) {
|
|
205
391
|
Object exports = Object::New(env);
|
|
206
392
|
|
|
207
393
|
exports["createTypedArray"] = Function::New(env, CreateTypedArray);
|
|
208
|
-
exports["createInvalidTypedArray"] =
|
|
394
|
+
exports["createInvalidTypedArray"] =
|
|
395
|
+
Function::New(env, CreateInvalidTypedArray);
|
|
209
396
|
exports["getTypedArrayType"] = Function::New(env, GetTypedArrayType);
|
|
210
397
|
exports["getTypedArrayLength"] = Function::New(env, GetTypedArrayLength);
|
|
398
|
+
exports["getTypedArraySize"] = Function::New(env, GetTypedArraySize);
|
|
399
|
+
exports["getTypedArrayByteOffset"] =
|
|
400
|
+
Function::New(env, GetTypedArrayByteOffset);
|
|
401
|
+
exports["getTypedArrayByteLength"] =
|
|
402
|
+
Function::New(env, GetTypedArrayByteLength);
|
|
211
403
|
exports["getTypedArrayBuffer"] = Function::New(env, GetTypedArrayBuffer);
|
|
212
404
|
exports["getTypedArrayElement"] = Function::New(env, GetTypedArrayElement);
|
|
213
405
|
exports["setTypedArrayElement"] = Function::New(env, SetTypedArrayElement);
|
|
406
|
+
exports["checkBufferContent"] = Function::New(env, CheckBufferContent);
|
|
214
407
|
|
|
215
408
|
return exports;
|
|
216
409
|
}
|
|
@@ -4,19 +4,44 @@ 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 testData = [
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
9
|
+
['int8', Int8Array, 1, new Int8Array([0, 124, 24, 44])],
|
|
10
|
+
['uint8', Uint8Array, 1, new Uint8Array([0, 255, 2, 14])],
|
|
11
|
+
['uint8_clamped', Uint8ClampedArray, 1, new Uint8ClampedArray([0, 256, 0, 255])],
|
|
12
|
+
['int16', Int16Array, 2, new Int16Array([-32768, 32767, 1234, 42])],
|
|
13
|
+
['uint16', Uint16Array, 2, new Uint16Array([0, 65535, 4, 12])],
|
|
14
|
+
['int32', Int32Array, 4, new Int32Array([Math.pow(2, 31), Math.pow(-2, 31), 255, 4])],
|
|
15
|
+
['uint32', Uint32Array, 4, new Uint32Array([0, Math.pow(2, 32), 24, 125])],
|
|
16
|
+
['float32', Float32Array, 4, new Float32Array([0, 21, 34, 45])],
|
|
17
|
+
['float64', Float64Array, 8, new Float64Array([0, 4124, 45, 90])]
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
+
const bigIntTests = [
|
|
21
|
+
['bigint64', BigInt64Array, 8, new BigInt64Array([9007199254740991n, 9007199254740991n, 24n, 125n])],
|
|
22
|
+
['biguint64', BigUint64Array, 8, new BigUint64Array([9007199254740991n, 9007199254740991n, 2345n, 345n])]
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
bigIntTests.forEach(data => {
|
|
26
|
+
const length = 4;
|
|
27
|
+
const t = binding.typedarray.createTypedArray(data[0], length);
|
|
28
|
+
assert.ok(t instanceof data[1]);
|
|
29
|
+
assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]);
|
|
30
|
+
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
31
|
+
assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]);
|
|
32
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), 0);
|
|
33
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);
|
|
34
|
+
|
|
35
|
+
t[3] = 11n;
|
|
36
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11n);
|
|
37
|
+
binding.typedarray.setTypedArrayElement(t, 3, 22n);
|
|
38
|
+
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22n);
|
|
39
|
+
assert.strictEqual(t[3], 22n);
|
|
40
|
+
|
|
41
|
+
const nonEmptyTypedArray = binding.typedarray.createTypedArray(data[0], length, data[3].buffer);
|
|
42
|
+
binding.typedarray.checkBufferContent(nonEmptyTypedArray, data[3]);
|
|
43
|
+
});
|
|
44
|
+
|
|
20
45
|
testData.forEach(data => {
|
|
21
46
|
try {
|
|
22
47
|
const length = 4;
|
|
@@ -24,6 +49,9 @@ function test(binding) {
|
|
|
24
49
|
assert.ok(t instanceof data[1]);
|
|
25
50
|
assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]);
|
|
26
51
|
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
52
|
+
assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]);
|
|
53
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), 0);
|
|
54
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);
|
|
27
55
|
|
|
28
56
|
t[3] = 11;
|
|
29
57
|
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
|
|
@@ -49,6 +77,9 @@ function test(binding) {
|
|
|
49
77
|
assert.ok(t instanceof data[1]);
|
|
50
78
|
assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]);
|
|
51
79
|
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
|
|
80
|
+
assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]);
|
|
81
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), offset);
|
|
82
|
+
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);
|
|
52
83
|
|
|
53
84
|
t[3] = 11;
|
|
54
85
|
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
|
|
@@ -57,6 +88,9 @@ function test(binding) {
|
|
|
57
88
|
assert.strictEqual(t[3], 22);
|
|
58
89
|
|
|
59
90
|
assert.strictEqual(binding.typedarray.getTypedArrayBuffer(t), b);
|
|
91
|
+
|
|
92
|
+
const nonEmptyTypedArray = binding.typedarray.createTypedArray(data[0], length, data[3].buffer);
|
|
93
|
+
assert.strictEqual(binding.typedarray.checkBufferContent(nonEmptyTypedArray, data[3]), true);
|
|
60
94
|
} catch (e) {
|
|
61
95
|
console.log(data);
|
|
62
96
|
throw e;
|