|
| 1 | +// includes, indexOf, and lastIndexOf on BigInt typed arrays compare exact values, so a BigInt |
| 2 | +// outside the element type's range is never found. |
| 3 | + |
| 4 | +function check(actual, expected, what) { |
| 5 | + if (actual !== expected) |
| 6 | + throw new Error(what + ": expected " + expected + " but got " + actual); |
| 7 | +} |
| 8 | + |
| 9 | +const unsigned = new BigUint64Array([1n, 2n ** 64n - 1n, 0n]); |
| 10 | +check(unsigned.includes(-1n), false, "BigUint64Array includes -1n"); |
| 11 | +check(unsigned.indexOf(-1n), -1, "BigUint64Array indexOf -1n"); |
| 12 | +check(unsigned.lastIndexOf(-1n), -1, "BigUint64Array lastIndexOf -1n"); |
| 13 | +check(unsigned.indexOf(2n ** 64n), -1, "BigUint64Array indexOf 2n ** 64n"); |
| 14 | +check(unsigned.indexOf(2n ** 64n - 1n), 1, "BigUint64Array indexOf its maximum"); |
| 15 | +check(unsigned.indexOf(0n), 2, "BigUint64Array indexOf 0n"); |
| 16 | + |
| 17 | +const signed = new BigInt64Array([-1n, 5n, -(2n ** 63n), 2n ** 63n - 1n]); |
| 18 | +check(signed.includes(2n ** 64n - 1n), false, "BigInt64Array includes 2n ** 64n - 1n"); |
| 19 | +check(signed.indexOf(5n + 2n ** 64n), -1, "BigInt64Array indexOf 5n + 2n ** 64n"); |
| 20 | +check(signed.indexOf(2n ** 63n), -1, "BigInt64Array indexOf 2n ** 63n"); |
| 21 | +check(signed.indexOf(-(2n ** 63n) - 1n), -1, "BigInt64Array indexOf below its minimum"); |
| 22 | +check(signed.indexOf(-(2n ** 63n)), 2, "BigInt64Array indexOf its minimum"); |
| 23 | +check(signed.indexOf(2n ** 63n - 1n), 3, "BigInt64Array indexOf its maximum"); |
| 24 | +check(signed.lastIndexOf(-1n), 0, "BigInt64Array lastIndexOf -1n"); |
0 commit comments