summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/TypedObject/neutertypedobjsizedarray.js
blob: 6f8522906b9f36ac70707e99803d9b87a9407494 (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
// Test the case where we detach the buffer underlying a fixed-sized array.
// This is a bit of a tricky case because we cannot (necessarily) fold
// the detached check into the bounds check, as we obtain the bounds
// directly from the type.

if (!this.hasOwnProperty("TypedObject"))
  quit();

var {StructType, uint32, storage} = TypedObject;
var S = new StructType({f: uint32, g: uint32});
var A = S.array(10);

function readFrom(a) {
  return a[2].f + a[2].g;
}

function main() {
  var a = new A();
  a[2].f = 22;
  a[2].g = 44;

  for (var i = 0; i < 10; i++)
    assertEq(readFrom(a), 66);

  detachArrayBuffer(storage(a).buffer);

  for (var i = 0; i < 10; i++) {
    var ok = false;

    try {
      readFrom(a);
    } catch (e) {
      ok = e instanceof TypeError;
    }

    assertEq(ok, true);
  }
}

main();