| 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/table_set.wast |
| 17 |
|
| 18 |
// ./test/core/table_set.wast:1 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
(table $$t2 1 externref) |
| 21 |
(table $$t3 2 funcref) |
| 22 |
(table $$t64 i64 2 funcref) |
| 23 |
(elem (table $$t3) (i32.const 1) func $$dummy) |
| 24 |
(func $$dummy) |
| 25 |
|
| 26 |
(func (export "get-externref") (param $$i i32) (result externref) |
| 27 |
(table.get $$t2 (local.get $$i)) |
| 28 |
) |
| 29 |
(func $$f3 (export "get-funcref") (param $$i i32) (result funcref) |
| 30 |
(table.get $$t3 (local.get $$i)) |
| 31 |
) |
| 32 |
(func $$f4 (export "get-funcref-t64") (param $$i i64) (result funcref) |
| 33 |
(table.get $$t64 (local.get $$i)) |
| 34 |
) |
| 35 |
|
| 36 |
(func (export "set-externref") (param $$i i32) (param $$r externref) |
| 37 |
(table.set (local.get $$i) (local.get $$r)) |
| 38 |
) |
| 39 |
(func (export "set-funcref") (param $$i i32) (param $$r funcref) |
| 40 |
(table.set $$t3 (local.get $$i) (local.get $$r)) |
| 41 |
) |
| 42 |
(func (export "set-funcref-from") (param $$i i32) (param $$j i32) |
| 43 |
(table.set $$t3 (local.get $$i) (table.get $$t3 (local.get $$j))) |
| 44 |
) |
| 45 |
(func (export "set-funcref-t64") (param $$i i64) (param $$r funcref) |
| 46 |
(table.set $$t64 (local.get $$i) (local.get $$r)) |
| 47 |
) |
| 48 |
|
| 49 |
(func (export "is_null-funcref") (param $$i i32) (result i32) |
| 50 |
(ref.is_null (call $$f3 (local.get $$i))) |
| 51 |
) |
| 52 |
)`); |
| 53 |
|
| 54 |
// ./test/core/table_set.wast:36 |
| 55 |
assert_return(() => invoke($0, `get-externref`, [0]), [value('externref', null)]); |
| 56 |
|
| 57 |
// ./test/core/table_set.wast:37 |
| 58 |
assert_return(() => invoke($0, `set-externref`, [0, externref(1)]), []); |
| 59 |
|
| 60 |
// ./test/core/table_set.wast:38 |
| 61 |
assert_return(() => invoke($0, `get-externref`, [0]), [new ExternRefResult(1)]); |
| 62 |
|
| 63 |
// ./test/core/table_set.wast:39 |
| 64 |
assert_return(() => invoke($0, `set-externref`, [0, null]), []); |
| 65 |
|
| 66 |
// ./test/core/table_set.wast:40 |
| 67 |
assert_return(() => invoke($0, `get-externref`, [0]), [value('externref', null)]); |
| 68 |
|
| 69 |
// ./test/core/table_set.wast:42 |
| 70 |
assert_return(() => invoke($0, `set-funcref-t64`, [0n, null]), []); |
| 71 |
|
| 72 |
// ./test/core/table_set.wast:43 |
| 73 |
assert_return(() => invoke($0, `get-funcref-t64`, [0n]), [value('anyfunc', null)]); |
| 74 |
|
| 75 |
// ./test/core/table_set.wast:45 |
| 76 |
assert_return(() => invoke($0, `get-funcref`, [0]), [value('anyfunc', null)]); |
| 77 |
|
| 78 |
// ./test/core/table_set.wast:46 |
| 79 |
assert_return(() => invoke($0, `set-funcref-from`, [0, 1]), []); |
| 80 |
|
| 81 |
// ./test/core/table_set.wast:47 |
| 82 |
assert_return(() => invoke($0, `is_null-funcref`, [0]), [value("i32", 0)]); |
| 83 |
|
| 84 |
// ./test/core/table_set.wast:48 |
| 85 |
assert_return(() => invoke($0, `set-funcref`, [0, null]), []); |
| 86 |
|
| 87 |
// ./test/core/table_set.wast:49 |
| 88 |
assert_return(() => invoke($0, `get-funcref`, [0]), [value('anyfunc', null)]); |
| 89 |
|
| 90 |
// ./test/core/table_set.wast:51 |
| 91 |
assert_trap(() => invoke($0, `set-externref`, [2, null]), `out of bounds table access`); |
| 92 |
|
| 93 |
// ./test/core/table_set.wast:52 |
| 94 |
assert_trap(() => invoke($0, `set-funcref`, [3, null]), `out of bounds table access`); |
| 95 |
|
| 96 |
// ./test/core/table_set.wast:53 |
| 97 |
assert_trap(() => invoke($0, `set-externref`, [-1, null]), `out of bounds table access`); |
| 98 |
|
| 99 |
// ./test/core/table_set.wast:54 |
| 100 |
assert_trap(() => invoke($0, `set-funcref`, [-1, null]), `out of bounds table access`); |
| 101 |
|
| 102 |
// ./test/core/table_set.wast:56 |
| 103 |
assert_trap(() => invoke($0, `set-externref`, [2, externref(0)]), `out of bounds table access`); |
| 104 |
|
| 105 |
// ./test/core/table_set.wast:57 |
| 106 |
assert_trap(() => invoke($0, `set-funcref-from`, [3, 1]), `out of bounds table access`); |
| 107 |
|
| 108 |
// ./test/core/table_set.wast:58 |
| 109 |
assert_trap(() => invoke($0, `set-externref`, [-1, externref(0)]), `out of bounds table access`); |
| 110 |
|
| 111 |
// ./test/core/table_set.wast:59 |
| 112 |
assert_trap(() => invoke($0, `set-funcref-from`, [-1, 1]), `out of bounds table access`); |
| 113 |
|
| 114 |
// ./test/core/table_set.wast:64 |
| 115 |
assert_invalid( |
| 116 |
() => instantiate(`(module |
| 117 |
(table $$t 10 externref) |
| 118 |
(func $$type-index-value-empty-vs-i32-externref |
| 119 |
(table.set $$t) |
| 120 |
) |
| 121 |
)`), |
| 122 |
`type mismatch`, |
| 123 |
); |
| 124 |
|
| 125 |
// ./test/core/table_set.wast:73 |
| 126 |
assert_invalid( |
| 127 |
() => instantiate(`(module |
| 128 |
(table $$t 10 externref) |
| 129 |
(func $$type-index-empty-vs-i32 |
| 130 |
(table.set $$t (ref.null extern)) |
| 131 |
) |
| 132 |
)`), |
| 133 |
`type mismatch`, |
| 134 |
); |
| 135 |
|
| 136 |
// ./test/core/table_set.wast:82 |
| 137 |
assert_invalid( |
| 138 |
() => instantiate(`(module |
| 139 |
(table $$t 10 externref) |
| 140 |
(func $$type-value-empty-vs-externref |
| 141 |
(table.set $$t (i32.const 1)) |
| 142 |
) |
| 143 |
)`), |
| 144 |
`type mismatch`, |
| 145 |
); |
| 146 |
|
| 147 |
// ./test/core/table_set.wast:91 |
| 148 |
assert_invalid( |
| 149 |
() => instantiate(`(module |
| 150 |
(table $$t 10 externref) |
| 151 |
(func $$type-size-f32-vs-i32 |
| 152 |
(table.set $$t (f32.const 1) (ref.null extern)) |
| 153 |
) |
| 154 |
)`), |
| 155 |
`type mismatch`, |
| 156 |
); |
| 157 |
|
| 158 |
// ./test/core/table_set.wast:100 |
| 159 |
assert_invalid( |
| 160 |
() => instantiate(`(module |
| 161 |
(table $$t 10 funcref) |
| 162 |
(func $$type-value-externref-vs-funcref (param $$r externref) |
| 163 |
(table.set $$t (i32.const 1) (local.get $$r)) |
| 164 |
) |
| 165 |
)`), |
| 166 |
`type mismatch`, |
| 167 |
); |
| 168 |
|
| 169 |
// ./test/core/table_set.wast:110 |
| 170 |
assert_invalid( |
| 171 |
() => instantiate(`(module |
| 172 |
(table $$t1 1 externref) |
| 173 |
(table $$t2 1 funcref) |
| 174 |
(func $$type-value-externref-vs-funcref-multi (param $$r externref) |
| 175 |
(table.set $$t2 (i32.const 0) (local.get $$r)) |
| 176 |
) |
| 177 |
)`), |
| 178 |
`type mismatch`, |
| 179 |
); |
| 180 |
|
| 181 |
// ./test/core/table_set.wast:121 |
| 182 |
assert_invalid( |
| 183 |
() => instantiate(`(module |
| 184 |
(table $$t 10 externref) |
| 185 |
(func $$type-result-empty-vs-num (result i32) |
| 186 |
(table.set $$t (i32.const 0) (ref.null extern)) |
| 187 |
) |
| 188 |
)`), |
| 189 |
`type mismatch`, |
| 190 |
); |