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