summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/gc/array_fill.wast.js
blob: 271b1690c4259f26f6a8e2b9b1a9f00a065f5565 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Copyright 2021 Mozilla Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ./test/core/gc/array_fill.wast

// ./test/core/gc/array_fill.wast:5
assert_invalid(
  () => instantiate(`(module
    (type $$a (array i8))

    (func (export "array.fill-immutable") (param $$1 (ref $$a)) (param $$2 i32)
      (array.fill $$a (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
    )
  )`),
  `array is immutable`,
);

// ./test/core/gc/array_fill.wast:16
assert_invalid(
  () => instantiate(`(module
    (type $$a (array (mut i8)))

    (func (export "array.fill-invalid-1") (param $$1 (ref $$a)) (param $$2 funcref)
      (array.fill $$a (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
    )
  )`),
  `type mismatch`,
);

// ./test/core/gc/array_fill.wast:27
assert_invalid(
  () => instantiate(`(module
    (type $$b (array (mut funcref)))

    (func (export "array.fill-invalid-1") (param $$1 (ref $$b)) (param $$2 i32)
      (array.fill $$b (local.get $$1) (i32.const 0) (local.get $$2) (i32.const 0))
    )
  )`),
  `type mismatch`,
);

// ./test/core/gc/array_fill.wast:38
let $0 = instantiate(`(module
  (type $$arr8 (array i8))
  (type $$arr8_mut (array (mut i8)))

  (global $$g_arr8 (ref $$arr8) (array.new $$arr8 (i32.const 10) (i32.const 12)))
  (global $$g_arr8_mut (mut (ref $$arr8_mut)) (array.new_default $$arr8_mut (i32.const 12)))

  (func (export "array_get_nth") (param $$1 i32) (result i32)
    (array.get_u $$arr8_mut (global.get $$g_arr8_mut) (local.get $$1))
  )

  (func (export "array_fill-null")
    (array.fill $$arr8_mut (ref.null $$arr8_mut) (i32.const 0) (i32.const 0) (i32.const 0))
  )

  (func (export "array_fill") (param $$1 i32) (param $$2 i32) (param $$3 i32)
    (array.fill $$arr8_mut (global.get $$g_arr8_mut) (local.get $$1) (local.get $$2) (local.get $$3))
  )
)`);

// ./test/core/gc/array_fill.wast:59
assert_trap(() => invoke($0, `array_fill-null`, []), `null array reference`);

// ./test/core/gc/array_fill.wast:62
assert_trap(() => invoke($0, `array_fill`, [13, 0, 0]), `out of bounds array access`);

// ./test/core/gc/array_fill.wast:65
assert_trap(() => invoke($0, `array_fill`, [0, 0, 13]), `out of bounds array access`);

// ./test/core/gc/array_fill.wast:68
assert_return(() => invoke($0, `array_fill`, [12, 0, 0]), []);

// ./test/core/gc/array_fill.wast:71
assert_return(() => invoke($0, `array_get_nth`, [0]), [value("i32", 0)]);

// ./test/core/gc/array_fill.wast:72
assert_return(() => invoke($0, `array_get_nth`, [5]), [value("i32", 0)]);

// ./test/core/gc/array_fill.wast:73
assert_return(() => invoke($0, `array_get_nth`, [11]), [value("i32", 0)]);

// ./test/core/gc/array_fill.wast:74
assert_trap(() => invoke($0, `array_get_nth`, [12]), `out of bounds array access`);

// ./test/core/gc/array_fill.wast:77
assert_return(() => invoke($0, `array_fill`, [2, 11, 2]), []);

// ./test/core/gc/array_fill.wast:78
assert_return(() => invoke($0, `array_get_nth`, [1]), [value("i32", 0)]);

// ./test/core/gc/array_fill.wast:79
assert_return(() => invoke($0, `array_get_nth`, [2]), [value("i32", 11)]);

// ./test/core/gc/array_fill.wast:80
assert_return(() => invoke($0, `array_get_nth`, [3]), [value("i32", 11)]);

// ./test/core/gc/array_fill.wast:81
assert_return(() => invoke($0, `array_get_nth`, [4]), [value("i32", 0)]);