forked from nodejs/node-addon-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypedarray-bigint.js
58 lines (48 loc) · 1.87 KB
/
typedarray-bigint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const assert = require('assert');
module.exports = require('./common').runTest(test);
function test (binding) {
[
['bigint64', BigInt64Array],
['biguint64', BigUint64Array]
].forEach(([type, Constructor]) => {
try {
const length = 4;
const t = binding.typedarray.createTypedArray(type, length);
assert.ok(t instanceof Constructor);
assert.strictEqual(binding.typedarray.getTypedArrayType(t), type);
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
t[3] = 11n;
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11n);
binding.typedarray.setTypedArrayElement(t, 3, 22n);
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22n);
assert.strictEqual(t[3], 22n);
const b = binding.typedarray.getTypedArrayBuffer(t);
assert.ok(b instanceof ArrayBuffer);
} catch (e) {
console.log(type, Constructor);
throw e;
}
try {
const length = 4;
const offset = 8;
const b = new ArrayBuffer(offset + 64 * 4);
const t = binding.typedarray.createTypedArray(type, length, b, offset);
assert.ok(t instanceof Constructor);
assert.strictEqual(binding.typedarray.getTypedArrayType(t), type);
assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length);
t[3] = 11n;
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11n);
binding.typedarray.setTypedArrayElement(t, 3, 22n);
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 22n);
assert.strictEqual(t[3], 22n);
assert.strictEqual(binding.typedarray.getTypedArrayBuffer(t), b);
} catch (e) {
console.log(type, Constructor);
throw e;
}
});
assert.throws(() => {
binding.typedarray.createInvalidTypedArray();
}, /Invalid (pointer passed as )?argument/);
}