summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Atomics/detached-buffers.js
blob: e3bc269b40f3ce50bf961ee39b8ef615c4469d88 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// |reftest| skip-if(!this.Atomics)

const intArrayConstructors = [
  Int32Array,
  Int16Array,
  Int8Array,
  Uint32Array,
  Uint16Array,
  Uint8Array,
];

function badValue(ta) {
  return {
    valueOf() {
      detachArrayBuffer(ta.buffer);
      return 0;
    }
  };
}

// Atomics.load
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.load(ta, badValue(ta)), TypeError);
}

// Atomics.store
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.store(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.store(ta, 0, badValue(ta)), TypeError);
}

// Atomics.compareExchange
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.compareExchange(ta, badValue(ta), 0, 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.compareExchange(ta, 0, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.compareExchange(ta, 0, 0, badValue(ta)), TypeError);
}

// Atomics.exchange
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.exchange(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.exchange(ta, 0, badValue(ta)), TypeError);
}

// Atomics.add
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.add(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.add(ta, 0, badValue(ta)), TypeError);
}

// Atomics.sub
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.sub(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.sub(ta, 0, badValue(ta)), TypeError);
}

// Atomics.and
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.and(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.and(ta, 0, badValue(ta)), TypeError);
}

// Atomics.or
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.or(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.or(ta, 0, badValue(ta)), TypeError);
}

// Atomics.xor
for (let TA of intArrayConstructors) {
  let ta = new TA(1);

  assertThrowsInstanceOf(() => Atomics.xor(ta, badValue(ta), 0), TypeError);
  assertThrowsInstanceOf(() => Atomics.xor(ta, 0, badValue(ta)), TypeError);
}

if (typeof reportCompare === "function")
  reportCompare(true, true);