| 1 |
/* Copyright 2021 Mozilla Foundation |
| 2 |
* |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software |
| 10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
* See the License for the specific language governing permissions and |
| 13 |
* limitations under the License. |
| 14 |
*/ |
| 15 |
|
| 16 |
// ./test/core/gc/array_new_elem.wast |
| 17 |
|
| 18 |
// ./test/core/gc/array_new_elem.wast:3 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
(type $$arr (array i31ref)) |
| 21 |
|
| 22 |
(elem $$e i31ref |
| 23 |
(ref.i31 (i32.const 0xaa)) |
| 24 |
(ref.i31 (i32.const 0xbb)) |
| 25 |
(ref.i31 (i32.const 0xcc)) |
| 26 |
(ref.i31 (i32.const 0xdd))) |
| 27 |
|
| 28 |
(func (export "array-new-elem") (param i32 i32) (result (ref $$arr)) |
| 29 |
(array.new_elem $$arr $$e (local.get 0) (local.get 1)) |
| 30 |
) |
| 31 |
)`); |
| 32 |
|
| 33 |
// ./test/core/gc/array_new_elem.wast:18 |
| 34 |
assert_return(() => invoke($0, `array-new-elem`, [0, 0]), [new RefWithType('arrayref')]); |
| 35 |
|
| 36 |
// ./test/core/gc/array_new_elem.wast:19 |
| 37 |
assert_return(() => invoke($0, `array-new-elem`, [0, 4]), [new RefWithType('arrayref')]); |
| 38 |
|
| 39 |
// ./test/core/gc/array_new_elem.wast:20 |
| 40 |
assert_return(() => invoke($0, `array-new-elem`, [1, 2]), [new RefWithType('arrayref')]); |
| 41 |
|
| 42 |
// ./test/core/gc/array_new_elem.wast:21 |
| 43 |
assert_return(() => invoke($0, `array-new-elem`, [4, 0]), [new RefWithType('arrayref')]); |
| 44 |
|
| 45 |
// ./test/core/gc/array_new_elem.wast:24 |
| 46 |
assert_trap(() => invoke($0, `array-new-elem`, [0, 5]), `out of bounds table access`); |
| 47 |
|
| 48 |
// ./test/core/gc/array_new_elem.wast:25 |
| 49 |
assert_trap(() => invoke($0, `array-new-elem`, [5, 0]), `out of bounds table access`); |
| 50 |
|
| 51 |
// ./test/core/gc/array_new_elem.wast:26 |
| 52 |
assert_trap(() => invoke($0, `array-new-elem`, [1, 4]), `out of bounds table access`); |
| 53 |
|
| 54 |
// ./test/core/gc/array_new_elem.wast:27 |
| 55 |
assert_trap(() => invoke($0, `array-new-elem`, [4, 1]), `out of bounds table access`); |
| 56 |
|
| 57 |
// ./test/core/gc/array_new_elem.wast:29 |
| 58 |
let $1 = instantiate(`(module |
| 59 |
(type $$arr (array i31ref)) |
| 60 |
|
| 61 |
(elem $$e i31ref |
| 62 |
(ref.i31 (i32.const 0xaa)) |
| 63 |
(ref.i31 (i32.const 0xbb)) |
| 64 |
(ref.i31 (i32.const 0xcc)) |
| 65 |
(ref.i31 (i32.const 0xdd))) |
| 66 |
|
| 67 |
(func (export "array-new-elem-contents") (result i32 i32) |
| 68 |
(local (ref $$arr)) |
| 69 |
(local.set 0 (array.new_elem $$arr $$e (i32.const 1) (i32.const 2))) |
| 70 |
(i31.get_u (array.get $$arr (local.get 0) (i32.const 0))) |
| 71 |
(i31.get_u (array.get $$arr (local.get 0) (i32.const 1))) |
| 72 |
) |
| 73 |
)`); |
| 74 |
|
| 75 |
// ./test/core/gc/array_new_elem.wast:47 |
| 76 |
assert_return(() => invoke($1, `array-new-elem-contents`, []), [value("i32", 187), value("i32", 204)]); |
| 77 |
|
| 78 |
// ./test/core/gc/array_new_elem.wast:51 |
| 79 |
let $2 = instantiate(`(module |
| 80 |
(type $$arr (array funcref)) |
| 81 |
|
| 82 |
(elem $$e func $$aa $$bb $$cc $$dd) |
| 83 |
(func $$aa (result i32) (i32.const 0xaa)) |
| 84 |
(func $$bb (result i32) (i32.const 0xbb)) |
| 85 |
(func $$cc (result i32) (i32.const 0xcc)) |
| 86 |
(func $$dd (result i32) (i32.const 0xdd)) |
| 87 |
|
| 88 |
(func (export "array-new-elem") (param i32 i32) (result (ref $$arr)) |
| 89 |
(array.new_elem $$arr $$e (local.get 0) (local.get 1)) |
| 90 |
) |
| 91 |
)`); |
| 92 |
|
| 93 |
// ./test/core/gc/array_new_elem.wast:66 |
| 94 |
assert_return(() => invoke($2, `array-new-elem`, [0, 0]), [new RefWithType('arrayref')]); |
| 95 |
|
| 96 |
// ./test/core/gc/array_new_elem.wast:67 |
| 97 |
assert_return(() => invoke($2, `array-new-elem`, [0, 4]), [new RefWithType('arrayref')]); |
| 98 |
|
| 99 |
// ./test/core/gc/array_new_elem.wast:68 |
| 100 |
assert_return(() => invoke($2, `array-new-elem`, [1, 2]), [new RefWithType('arrayref')]); |
| 101 |
|
| 102 |
// ./test/core/gc/array_new_elem.wast:69 |
| 103 |
assert_return(() => invoke($2, `array-new-elem`, [4, 0]), [new RefWithType('arrayref')]); |
| 104 |
|
| 105 |
// ./test/core/gc/array_new_elem.wast:72 |
| 106 |
assert_trap(() => invoke($2, `array-new-elem`, [0, 5]), `out of bounds table access`); |
| 107 |
|
| 108 |
// ./test/core/gc/array_new_elem.wast:73 |
| 109 |
assert_trap(() => invoke($2, `array-new-elem`, [5, 0]), `out of bounds table access`); |
| 110 |
|
| 111 |
// ./test/core/gc/array_new_elem.wast:74 |
| 112 |
assert_trap(() => invoke($2, `array-new-elem`, [1, 4]), `out of bounds table access`); |
| 113 |
|
| 114 |
// ./test/core/gc/array_new_elem.wast:75 |
| 115 |
assert_trap(() => invoke($2, `array-new-elem`, [4, 1]), `out of bounds table access`); |
| 116 |
|
| 117 |
// ./test/core/gc/array_new_elem.wast:77 |
| 118 |
let $3 = instantiate(`(module |
| 119 |
(type $$f (func (result i32))) |
| 120 |
(type $$arr (array funcref)) |
| 121 |
|
| 122 |
(elem $$e func $$aa $$bb $$cc $$dd) |
| 123 |
(func $$aa (result i32) (i32.const 0xaa)) |
| 124 |
(func $$bb (result i32) (i32.const 0xbb)) |
| 125 |
(func $$cc (result i32) (i32.const 0xcc)) |
| 126 |
(func $$dd (result i32) (i32.const 0xdd)) |
| 127 |
|
| 128 |
(table $$t 2 2 funcref) |
| 129 |
|
| 130 |
(func (export "array-new-elem-contents") (result i32 i32) |
| 131 |
(local (ref $$arr)) |
| 132 |
(local.set 0 (array.new_elem $$arr $$e (i32.const 1) (i32.const 2))) |
| 133 |
|
| 134 |
(table.set $$t (i32.const 0) (array.get $$arr (local.get 0) (i32.const 0))) |
| 135 |
(table.set $$t (i32.const 1) (array.get $$arr (local.get 0) (i32.const 1))) |
| 136 |
|
| 137 |
(call_indirect (type $$f) (i32.const 0)) |
| 138 |
(call_indirect (type $$f) (i32.const 1)) |
| 139 |
|
| 140 |
) |
| 141 |
)`); |
| 142 |
|
| 143 |
// ./test/core/gc/array_new_elem.wast:103 |
| 144 |
assert_return(() => invoke($3, `array-new-elem-contents`, []), [value("i32", 187), value("i32", 204)]); |