summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/atomics/nursery-non-shared-moved-gc.js
blob: 472076ce638ac1ffc429f9a1e9f6f4a64fc95985 (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
95
96
97
98
99
// Small (non-shared) TypedArrays can use inline storage and can also be nursery
// allocated. Ensure Atomics functions use correct rooting and don't store the
// TypedArray's data pointer on the stack across a GC.
const INLINE_MEMORY_LENGTH = 1;

function gcValue(value) {
  return {
    valueOf() {
      minorgc();
      return value;
    }
  };
};

// Atomics.store
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);

  Atomics.store(ta, 0, gcValue(1));

  assertEq(ta[0], 1);
}

// Atomics.compareExchange
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 1;

  let val = Atomics.compareExchange(ta, 0, 1, gcValue(2));

  assertEq(val, 1);
  assertEq(ta[0], 2);
}

// Atomics.exchange
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 1;

  let val = Atomics.exchange(ta, 0, gcValue(2));

  assertEq(val, 1);
  assertEq(ta[0], 2);
}

// Atomics.add
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 1;

  let val = Atomics.add(ta, 0, gcValue(2));

  assertEq(val, 1);
  assertEq(ta[0], 3);
}

// Atomics.sub
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 3;

  let val = Atomics.sub(ta, 0, gcValue(2));

  assertEq(val, 3);
  assertEq(ta[0], 1);
}

// Atomics.and
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 3;

  let val = Atomics.and(ta, 0, gcValue(1));

  assertEq(val, 3);
  assertEq(ta[0], 1);
}

// Atomics.or
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 2;

  let val = Atomics.or(ta, 0, gcValue(1));

  assertEq(val, 2);
  assertEq(ta[0], 3);
}

// Atomics.xor
{
  let ta = new Int32Array(INLINE_MEMORY_LENGTH);
  ta[0] = 3;

  let val = Atomics.xor(ta, 0, gcValue(1));

  assertEq(val, 3);
  assertEq(ta[0], 2);
}