summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/typedarray/resizable-buffer-inlined-data-moved.js
blob: 1206edd5e502ca4f1180c414553299871365c5d9 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
// |jit-test| --enable-arraybuffer-resizable; skip-if: !ArrayBuffer.prototype.resize

function fillArrayBuffer(rab) {
  let fill = new Int8Array(rab);
  for (let i = 0; i < fill.length; ++i) fill[i] = i + 1;
}

function test() {
  let rab = new ArrayBuffer(4, {maxByteLength: 4});
  let ta = new Int8Array(rab, 2, 2);

  fillArrayBuffer(rab);

  assertEq(ta[0], 3);
  assertEq(ta[1], 4);

  // Shrink to make |ta| out-of-bounds.
  rab.resize(3);

  // Request GC to move inline data.
  gc();

  // Grow to make |ta| in-bounds again.
  rab.resize(4);

  assertEq(ta[0], 3);
  assertEq(ta[1], 0);
}
test();


function testAutoLength() {
  let rab = new ArrayBuffer(4, {maxByteLength: 4});
  let ta = new Int8Array(rab, 2);

  fillArrayBuffer(rab);

  assertEq(ta[0], 3);
  assertEq(ta[1], 4);

  // Shrink to make |ta| out-of-bounds.
  rab.resize(1);

  // Request GC to move inline data.
  gc();

  // Grow to make |ta| in-bounds again.
  rab.resize(4);

  assertEq(ta[0], 0);
  assertEq(ta[1], 0);
}
testAutoLength();