summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testArrayBufferSlice.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/basic/testArrayBufferSlice.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/basic/testArrayBufferSlice.js')
-rw-r--r--js/src/jit-test/tests/basic/testArrayBufferSlice.js57
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 000000000..3b1f353de
--- /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();