summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/sharedbuf/growable-sab-over-mailbox.js
blob: 3ffb29cc3de9e9eaf4d9813a794110142a0b7f87 (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| --enable-arraybuffer-resizable; skip-if: !this.SharedArrayBuffer?.prototype?.grow

var gsab = new SharedArrayBuffer(4, {maxByteLength: 16});

// Test byte lengths are correct.
assertEq(gsab.byteLength, 4);
assertEq(gsab.maxByteLength, 16);

// Pass |gsab| to the mailbox.
setSharedObject(gsab);

// Retrieve again from the mailbox to create a new growable shared array buffer
// which points to the same memory.
var gsab2 = getSharedObject();

assertEq(gsab !== gsab2, true, "different objects expected");

// Byte lengths are correct for both objects.
assertEq(gsab.byteLength, 4);
assertEq(gsab.maxByteLength, 16);
assertEq(gsab2.byteLength, 4);
assertEq(gsab2.maxByteLength, 16);

// Grow the original object.
gsab.grow(6);

// Byte lengths are correct for both objects.
assertEq(gsab.byteLength, 6);
assertEq(gsab.maxByteLength, 16);
assertEq(gsab2.byteLength, 6);
assertEq(gsab2.maxByteLength, 16);

// Grow the copy.
gsab2.grow(8);

// Byte lengths are correct for both objects.
assertEq(gsab.byteLength, 8);
assertEq(gsab.maxByteLength, 16);
assertEq(gsab2.byteLength, 8);
assertEq(gsab2.maxByteLength, 16);