summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/dataview/resizable-dataview-byteoffset-sab.js
blob: e671700586d3ac0a56a283f0f4dfa4f09ce387f5 (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
// |jit-test| --enable-arraybuffer-resizable; skip-if: !ArrayBuffer.prototype.resize||!this.SharedArrayBuffer

function testResizableArrayBufferAutoLength() {
  for (let i = 0; i < 4; ++i) {
    let sab = new SharedArrayBuffer(i, {maxByteLength: i + 100});
    let ta = new DataView(sab);
    for (let j = 0; j < 100; ++j) {
      assertEq(ta.byteOffset, 0);

      sab.grow(i + j + 1);
      assertEq(ta.byteOffset, 0);
    }
  }
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferAutoLength();

function testResizableArrayBufferAutoLengthNonZeroOffset() {
  for (let i = 1; i < 4 + 1; ++i) {
    let sab = new SharedArrayBuffer(i + 1, {maxByteLength: i + 100 + 1});
    let ta = new DataView(sab, 1);
    for (let j = 0; j < 100; ++j) {
      assertEq(ta.byteOffset, 1);

      sab.grow(i + j + 2);
      assertEq(ta.byteOffset, 1);
    }
  }
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferAutoLengthNonZeroOffset();

function testResizableArrayBufferNonZeroOffset() {
  for (let i = 2; i < 4 + 2; ++i) {
    let sab = new SharedArrayBuffer(i + 2, {maxByteLength: i + 100 + 2});
    let ta = new DataView(sab, 1, 1);
    for (let j = 0; j < 100; ++j) {
      assertEq(ta.byteOffset, 1);

      sab.grow(i + j + 3);
      assertEq(ta.byteOffset, 1);
    }
  }
}
for (let i = 0; i < 2; ++i) testResizableArrayBufferNonZeroOffset();