summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/large-buffers/shared-array-buffer.js
blob: 608744b39268959915cf52b8de7a2fde055a51ad (plain)
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
// |jit-test| skip-if: !this.SharedArrayBuffer

var gb = 1 * 1024 * 1024 * 1024;
var sab = new SharedArrayBuffer(4 * gb + 10);
var ta = new Uint8Array(sab);

function testSlice() {
    // Large |start| and |end|.
    ta[4 * gb + 0] = 11;
    ta[4 * gb + 1] = 22;
    ta[4 * gb + 2] = 33;
    ta[4 * gb + 3] = 44;
    var ta2 = new Uint8Array(sab.slice(4 * gb, 4 * gb + 4));
    assertEq(ta2.toString(), "11,22,33,44");

    // Large |start|.
    ta[ta.length - 3] = 99;
    ta[ta.length - 2] = 88;
    ta[ta.length - 1] = 77;
    ta2 = new Uint8Array(sab.slice(4 * gb + 8));
    assertEq(ta2.toString(), "88,77");

    // Relative values.
    ta2 = new Uint8Array(sab.slice(-3, -1));
    assertEq(ta2.toString(), "99,88");

    // Large relative values.
    ta[0] = 100;
    ta[1] = 101;
    ta[2] = 102;
    ta2 = new Uint8Array(sab.slice(-ta.length, -ta.length + 3));
    assertEq(ta2.toString(), "100,101,102");
}
testSlice();

function testSharedMailbox() {
    setSharedObject(sab);
    assertEq(getSharedObject().byteLength, 4 * gb + 10);
}
testSharedMailbox();