summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/testPossiblyWrappedArrayBufferByteLength.js
blob: ef41f89c8ba2ebbf5812556b4bd6531af77dd3e7 (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
var PossiblyWrappedArrayBufferByteLength = getSelfHostedValue("PossiblyWrappedArrayBufferByteLength");

setJitCompilerOption("ion.warmup.trigger", 50);

function testBasic() {
  var arr = [1, 2, 3];
  var tarr = new Int32Array(arr);
  var abuf = tarr.buffer;

  var arrLength = arr.length;
  var bytesPerElement = Int32Array.BYTES_PER_ELEMENT;

  var f = function() {
    assertEq(PossiblyWrappedArrayBufferByteLength(abuf), arrLength * bytesPerElement);
  };
  do {
    f();
  } while (!inIon());
}
testBasic();

function testWrapped() {
  var g = newGlobal();
g.eval(`
var arr = [1, 2, 3];
var tarr = new Int32Array(arr);
var abuf = tarr.buffer;
`);

  var abuf = g.abuf;
  var arrLength = g.arr.length;
  var bytesPerElement = g.Int32Array.BYTES_PER_ELEMENT;

  var f = function() {
    assertEq(PossiblyWrappedArrayBufferByteLength(abuf), arrLength * bytesPerElement);
  };
  do {
    f();
  } while (!inIon());
}
testWrapped();