| 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_get.wast |
| 17 |
|
| 18 |
// ./test/core/table_get.wast:1 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
(table $$t2 2 externref) |
| 21 |
(table $$t3 3 funcref) |
| 22 |
(table $$t64 i64 3 funcref) |
| 23 |
(elem (table $$t3) (i32.const 1) func $$dummy) |
| 24 |
(func $$dummy) |
| 25 |
|
| 26 |
(func (export "init") (param $$r externref) |
| 27 |
(table.set $$t2 (i32.const 1) (local.get $$r)) |
| 28 |
(table.set $$t3 (i32.const 2) (table.get $$t3 (i32.const 1))) |
| 29 |
) |
| 30 |
|
| 31 |
(func (export "get-externref") (param $$i i32) (result externref) |
| 32 |
(table.get (local.get $$i)) |
| 33 |
) |
| 34 |
(func $$f3 (export "get-funcref") (param $$i i32) (result funcref) |
| 35 |
(table.get $$t3 (local.get $$i)) |
| 36 |
) |
| 37 |
(func $$f4 (export "get-funcref-t64") (param $$i i64) (result funcref) |
| 38 |
(table.get $$t64 (local.get $$i)) |
| 39 |
) |
| 40 |
|
| 41 |
(func (export "is_null-funcref") (param $$i i32) (result i32) |
| 42 |
(ref.is_null (call $$f3 (local.get $$i))) |
| 43 |
) |
| 44 |
)`); |
| 45 |
|
| 46 |
// ./test/core/table_get.wast:28 |
| 47 |
invoke($0, `init`, [externref(1)]); |
| 48 |
|
| 49 |
// ./test/core/table_get.wast:30 |
| 50 |
assert_return(() => invoke($0, `get-externref`, [0]), [value('externref', null)]); |
| 51 |
|
| 52 |
// ./test/core/table_get.wast:31 |
| 53 |
assert_return(() => invoke($0, `get-externref`, [1]), [new ExternRefResult(1)]); |
| 54 |
|
| 55 |
// ./test/core/table_get.wast:33 |
| 56 |
assert_return(() => invoke($0, `get-funcref`, [0]), [value('anyfunc', null)]); |
| 57 |
|
| 58 |
// ./test/core/table_get.wast:34 |
| 59 |
assert_return(() => invoke($0, `get-funcref-t64`, [0n]), [value('anyfunc', null)]); |
| 60 |
|
| 61 |
// ./test/core/table_get.wast:35 |
| 62 |
assert_return(() => invoke($0, `is_null-funcref`, [1]), [value("i32", 0)]); |
| 63 |
|
| 64 |
// ./test/core/table_get.wast:36 |
| 65 |
assert_return(() => invoke($0, `is_null-funcref`, [2]), [value("i32", 0)]); |
| 66 |
|
| 67 |
// ./test/core/table_get.wast:38 |
| 68 |
assert_trap(() => invoke($0, `get-externref`, [2]), `out of bounds table access`); |
| 69 |
|
| 70 |
// ./test/core/table_get.wast:39 |
| 71 |
assert_trap(() => invoke($0, `get-funcref`, [3]), `out of bounds table access`); |
| 72 |
|
| 73 |
// ./test/core/table_get.wast:40 |
| 74 |
assert_trap(() => invoke($0, `get-externref`, [-1]), `out of bounds table access`); |
| 75 |
|
| 76 |
// ./test/core/table_get.wast:41 |
| 77 |
assert_trap(() => invoke($0, `get-funcref`, [-1]), `out of bounds table access`); |
| 78 |
|
| 79 |
// ./test/core/table_get.wast:46 |
| 80 |
assert_invalid( |
| 81 |
() => instantiate(`(module |
| 82 |
(table $$t 10 externref) |
| 83 |
(func $$type-index-empty-vs-i32 (result externref) |
| 84 |
(table.get $$t) |
| 85 |
) |
| 86 |
)`), |
| 87 |
`type mismatch`, |
| 88 |
); |
| 89 |
|
| 90 |
// ./test/core/table_get.wast:55 |
| 91 |
assert_invalid( |
| 92 |
() => instantiate(`(module |
| 93 |
(table $$t 10 externref) |
| 94 |
(func $$type-index-f32-vs-i32 (result externref) |
| 95 |
(table.get $$t (f32.const 1)) |
| 96 |
) |
| 97 |
)`), |
| 98 |
`type mismatch`, |
| 99 |
); |
| 100 |
|
| 101 |
// ./test/core/table_get.wast:65 |
| 102 |
assert_invalid( |
| 103 |
() => instantiate(`(module |
| 104 |
(table $$t 10 externref) |
| 105 |
(func $$type-result-externref-vs-empty |
| 106 |
(table.get $$t (i32.const 0)) |
| 107 |
) |
| 108 |
)`), |
| 109 |
`type mismatch`, |
| 110 |
); |
| 111 |
|
| 112 |
// ./test/core/table_get.wast:74 |
| 113 |
assert_invalid( |
| 114 |
() => instantiate(`(module |
| 115 |
(table $$t 10 externref) |
| 116 |
(func $$type-result-externref-vs-funcref (result funcref) |
| 117 |
(table.get $$t (i32.const 1)) |
| 118 |
) |
| 119 |
)`), |
| 120 |
`type mismatch`, |
| 121 |
); |
| 122 |
|
| 123 |
// ./test/core/table_get.wast:84 |
| 124 |
assert_invalid( |
| 125 |
() => instantiate(`(module |
| 126 |
(table $$t1 1 funcref) |
| 127 |
(table $$t2 1 externref) |
| 128 |
(func $$type-result-externref-vs-funcref-multi (result funcref) |
| 129 |
(table.get $$t2 (i32.const 0)) |
| 130 |
) |
| 131 |
)`), |
| 132 |
`type mismatch`, |
| 133 |
); |