diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/testArrayBufferSlice.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/jit-test/tests/basic/testArrayBufferSlice.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/testArrayBufferSlice.js b/js/src/jit-test/tests/basic/testArrayBufferSlice.js new file mode 100644 index 0000000000..3b1f353def --- /dev/null +++ b/js/src/jit-test/tests/basic/testArrayBufferSlice.js @@ -0,0 +1,57 @@ +function testSlice() { + function test(subBuf, starts, size) { + var byteLength = size; + var subBuffer = eval(subBuf); + var subArray = new Int8Array(subBuffer); + assertEq(subBuffer.byteLength, byteLength); + for (var i = 0; i < size; ++i) + assertEq(starts + i, subArray[i]); + } + + var buffer = new ArrayBuffer(32); + var array = new Int8Array(buffer); + for (var i = 0; i < 32; ++i) + array[i] = i; + + test("buffer.slice(0)", 0, 32); + test("buffer.slice(16)", 16, 16); + test("buffer.slice(24)", 24, 8); + test("buffer.slice(32)", 32, 0); + test("buffer.slice(40)", 32, 0); + test("buffer.slice(80)", 32, 0); + + test("buffer.slice(-8)", 24, 8); + test("buffer.slice(-16)", 16, 16); + test("buffer.slice(-24)", 8, 24); + test("buffer.slice(-32)", 0, 32); + test("buffer.slice(-40)", 0, 32); + test("buffer.slice(-80)", 0, 32); + + test("buffer.slice(0, 32)", 0, 32); + test("buffer.slice(0, 16)", 0, 16); + test("buffer.slice(8, 24)", 8, 16); + test("buffer.slice(16, 32)", 16, 16); + test("buffer.slice(24, 16)", 24, 0); + + test("buffer.slice(16, -8)", 16, 8); + test("buffer.slice(-20, 30)", 12, 18); + + test("buffer.slice(-8, -20)", 24, 0); + test("buffer.slice(-20, -8)", 12, 12); + test("buffer.slice(-40, 16)", 0, 16); + test("buffer.slice(-40, 40)", 0, 32); + + gczeal(7, 100000); + var nurseryBuf = new ArrayBuffer(32); + var arr = new Int8Array(nurseryBuf); + arr[0] = 77; + + // tenure nurseryBuf during the slice operation + nurseryBuf.slice; // Creates an object + schedulegc(1); + var newbuf = nurseryBuf.slice(0); + var arr2 = new Int8Array(newbuf); + assertEq(arr2[0], 77); +} + +testSlice(); |