summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/dataview/throws-on-detached.js
blob: fb06a3c34c2b47b4173ac104390f3ce52ed73e34 (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
// TypeError is thrown when the underlying ArrayBuffer is detached.

function testByteOffset() {
  var ab = new ArrayBuffer(10);
  var dv = new DataView(ab, 4, 0);

  var q = 0;
  var error;
  try {
    for (var i = 0; i <= 200; ++i) {
      if (i === 200) {
        detachArrayBuffer(ab);
      }
      q += dv.byteOffset;
    }
  } catch (e) {
    error = e;
  }
  assertEq(q, 4 * 200);
  assertEq(error instanceof TypeError, true);
}
testByteOffset();

function testByteLength() {
  var ab = new ArrayBuffer(10);
  var dv = new DataView(ab, 4, 6);

  var q = 0;
  var error;
  try {
    for (var i = 0; i <= 200; ++i) {
      if (i === 200) {
        detachArrayBuffer(ab);
      }
      q += dv.byteLength;
    }
  } catch (e) {
    error = e;
  }
  assertEq(q, 6 * 200);
  assertEq(error instanceof TypeError, true);
}
testByteLength();