| 1 |
(module |
| 2 |
(table $t2 2 externref) |
| 3 |
(table $t3 3 funcref) |
| 4 |
(elem (table $t3) (i32.const 1) func $dummy) |
| 5 |
(func $dummy) |
| 6 |
|
| 7 |
(func (export "init") (param $r externref) |
| 8 |
(table.set $t2 (i32.const 1) (local.get $r)) |
| 9 |
(table.set $t3 (i32.const 2) (table.get $t3 (i32.const 1))) |
| 10 |
) |
| 11 |
|
| 12 |
(func (export "get-externref") (param $i i32) (result externref) |
| 13 |
(table.get (local.get $i)) |
| 14 |
) |
| 15 |
(func $f3 (export "get-funcref") (param $i i32) (result funcref) |
| 16 |
(table.get $t3 (local.get $i)) |
| 17 |
) |
| 18 |
|
| 19 |
(func (export "is_null-funcref") (param $i i32) (result i32) |
| 20 |
(ref.is_null (call $f3 (local.get $i))) |
| 21 |
) |
| 22 |
) |
| 23 |
|
| 24 |
(invoke "init" (ref.extern 1)) |
| 25 |
|
| 26 |
(assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern)) |
| 27 |
(assert_return (invoke "get-externref" (i32.const 1)) (ref.extern 1)) |
| 28 |
|
| 29 |
(assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) |
| 30 |
(assert_return (invoke "is_null-funcref" (i32.const 1)) (i32.const 0)) |
| 31 |
(assert_return (invoke "is_null-funcref" (i32.const 2)) (i32.const 0)) |
| 32 |
|
| 33 |
(assert_trap (invoke "get-externref" (i32.const 2)) "out of bounds table access") |
| 34 |
(assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds table access") |
| 35 |
(assert_trap (invoke "get-externref" (i32.const -1)) "out of bounds table access") |
| 36 |
(assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds table access") |
| 37 |
|
| 38 |
|
| 39 |
;; Type errors |
| 40 |
|
| 41 |
(assert_invalid |
| 42 |
(module |
| 43 |
(table $t 10 externref) |
| 44 |
(func $type-index-empty-vs-i32 (result externref) |
| 45 |
(table.get $t) |
| 46 |
) |
| 47 |
) |
| 48 |
"type mismatch" |
| 49 |
) |
| 50 |
(assert_invalid |
| 51 |
(module |
| 52 |
(table $t 10 externref) |
| 53 |
(func $type-index-f32-vs-i32 (result externref) |
| 54 |
(table.get $t (f32.const 1)) |
| 55 |
) |
| 56 |
) |
| 57 |
"type mismatch" |
| 58 |
) |
| 59 |
|
| 60 |
(assert_invalid |
| 61 |
(module |
| 62 |
(table $t 10 externref) |
| 63 |
(func $type-result-externref-vs-empty |
| 64 |
(table.get $t (i32.const 0)) |
| 65 |
) |
| 66 |
) |
| 67 |
"type mismatch" |
| 68 |
) |
| 69 |
(assert_invalid |
| 70 |
(module |
| 71 |
(table $t 10 externref) |
| 72 |
(func $type-result-externref-vs-funcref (result funcref) |
| 73 |
(table.get $t (i32.const 1)) |
| 74 |
) |
| 75 |
) |
| 76 |
"type mismatch" |
| 77 |
) |
| 78 |
|
| 79 |
(assert_invalid |
| 80 |
(module |
| 81 |
(table $t1 1 funcref) |
| 82 |
(table $t2 1 externref) |
| 83 |
(func $type-result-externref-vs-funcref-multi (result funcref) |
| 84 |
(table.get $t2 (i32.const 0)) |
| 85 |
) |
| 86 |
) |
| 87 |
"type mismatch" |
| 88 |
) |