diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js')
-rw-r--r-- | js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js b/js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js new file mode 100644 index 0000000000..3f522e741c --- /dev/null +++ b/js/src/jit-test/tests/large-arraybuffers/arraybuffer-transfer.js @@ -0,0 +1,64 @@ +const gb = 1 * 1024 * 1024 * 1024; + +const smallByteLength = 1024; +const largeByteLength = 4 * gb; + +// Fast alternative to |assertEq| to avoid a slow VM-call. +// Should only be used when looping over the TypedArray contents to avoid +// unnecessary test slowdowns. +function assertEqNum(e, a) { + if (e !== a) { + assertEq(e, a); + } +} + +{ + let smallBuffer = new ArrayBuffer(smallByteLength); + + let i8 = new Uint8Array(smallBuffer); + for (let i = 0; i < smallByteLength; ++i) { + assertEqNum(i8[i], 0); + i8[i] = i; + } + + assertEq(smallBuffer.byteLength, smallByteLength); + assertEq(smallBuffer.detached, false); + + // Copy from a small into a large buffer. + let largeBuffer = smallBuffer.transfer(largeByteLength); + + assertEq(smallBuffer.byteLength, 0); + assertEq(smallBuffer.detached, true); + + assertEq(largeBuffer.byteLength, largeByteLength); + assertEq(largeBuffer.detached, false); + + i8 = new Uint8Array(largeBuffer); + for (let i = 0; i < smallByteLength; ++i) { + assertEqNum(i8[i], i & 0xff); + } + + // Test the first 100 new bytes. + for (let i = smallByteLength; i < smallByteLength + 100; ++i) { + assertEqNum(i8[i], 0); + } + + // And the last 100 new bytes. + for (let i = largeByteLength - 100; i < largeByteLength; ++i) { + assertEqNum(i8[i], 0); + } + + // Copy back from a large into a small buffer. + smallBuffer = largeBuffer.transfer(smallByteLength); + + assertEq(largeBuffer.byteLength, 0); + assertEq(largeBuffer.detached, true); + + assertEq(smallBuffer.byteLength, smallByteLength); + assertEq(smallBuffer.detached, false); + + i8 = new Uint8Array(smallBuffer); + for (let i = 0; i < smallByteLength; ++i) { + assertEqNum(i8[i], i & 0xff); + } +} |