wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v2/testdata/table_grow.wast (about) 1 (module 2 (table $t 0 externref) 3 4 (func (export "get") (param $i i32) (result externref) (table.get $t (local.get $i))) 5 (func (export "set") (param $i i32) (param $r externref) (table.set $t (local.get $i) (local.get $r))) 6 7 (func (export "grow") (param $sz i32) (param $init externref) (result i32) 8 (table.grow $t (local.get $init) (local.get $sz)) 9 ) 10 (func (export "size") (result i32) (table.size $t)) 11 ) 12 13 (assert_return (invoke "size") (i32.const 0)) 14 (assert_trap (invoke "set" (i32.const 0) (ref.extern 2)) "out of bounds table access") 15 (assert_trap (invoke "get" (i32.const 0)) "out of bounds table access") 16 17 (assert_return (invoke "grow" (i32.const 1) (ref.null extern)) (i32.const 0)) 18 (assert_return (invoke "size") (i32.const 1)) 19 (assert_return (invoke "get" (i32.const 0)) (ref.null extern)) 20 (assert_return (invoke "set" (i32.const 0) (ref.extern 2))) 21 (assert_return (invoke "get" (i32.const 0)) (ref.extern 2)) 22 (assert_trap (invoke "set" (i32.const 1) (ref.extern 2)) "out of bounds table access") 23 (assert_trap (invoke "get" (i32.const 1)) "out of bounds table access") 24 25 (assert_return (invoke "grow" (i32.const 4) (ref.extern 3)) (i32.const 1)) 26 (assert_return (invoke "size") (i32.const 5)) 27 (assert_return (invoke "get" (i32.const 0)) (ref.extern 2)) 28 (assert_return (invoke "set" (i32.const 0) (ref.extern 2))) 29 (assert_return (invoke "get" (i32.const 0)) (ref.extern 2)) 30 (assert_return (invoke "get" (i32.const 1)) (ref.extern 3)) 31 (assert_return (invoke "get" (i32.const 4)) (ref.extern 3)) 32 (assert_return (invoke "set" (i32.const 4) (ref.extern 4))) 33 (assert_return (invoke "get" (i32.const 4)) (ref.extern 4)) 34 (assert_trap (invoke "set" (i32.const 5) (ref.extern 2)) "out of bounds table access") 35 (assert_trap (invoke "get" (i32.const 5)) "out of bounds table access") 36 37 38 ;; Reject growing to size outside i32 value range 39 (module 40 (table $t 0x10 funcref) 41 (elem declare func $f) 42 (func $f (export "grow") (result i32) 43 (table.grow $t (ref.func $f) (i32.const 0xffff_fff0)) 44 ) 45 ) 46 47 (assert_return (invoke "grow") (i32.const -1)) 48 49 50 (module 51 (table $t 0 externref) 52 (func (export "grow") (param i32) (result i32) 53 (table.grow $t (ref.null extern) (local.get 0)) 54 ) 55 ) 56 57 (assert_return (invoke "grow" (i32.const 0)) (i32.const 0)) 58 (assert_return (invoke "grow" (i32.const 1)) (i32.const 0)) 59 (assert_return (invoke "grow" (i32.const 0)) (i32.const 1)) 60 (assert_return (invoke "grow" (i32.const 2)) (i32.const 1)) 61 (assert_return (invoke "grow" (i32.const 800)) (i32.const 3)) 62 63 64 (module 65 (table $t 0 10 externref) 66 (func (export "grow") (param i32) (result i32) 67 (table.grow $t (ref.null extern) (local.get 0)) 68 ) 69 ) 70 71 (assert_return (invoke "grow" (i32.const 0)) (i32.const 0)) 72 (assert_return (invoke "grow" (i32.const 1)) (i32.const 0)) 73 (assert_return (invoke "grow" (i32.const 1)) (i32.const 1)) 74 (assert_return (invoke "grow" (i32.const 2)) (i32.const 2)) 75 (assert_return (invoke "grow" (i32.const 6)) (i32.const 4)) 76 (assert_return (invoke "grow" (i32.const 0)) (i32.const 10)) 77 (assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) 78 (assert_return (invoke "grow" (i32.const 0x10000)) (i32.const -1)) 79 80 81 (module 82 (table $t 10 funcref) 83 (func (export "grow") (param i32) (result i32) 84 (table.grow $t (ref.null func) (local.get 0)) 85 ) 86 (elem declare func 1) 87 (func (export "check-table-null") (param i32 i32) (result funcref) 88 (local funcref) 89 (local.set 2 (ref.func 1)) 90 (block 91 (loop 92 (local.set 2 (table.get $t (local.get 0))) 93 (br_if 1 (i32.eqz (ref.is_null (local.get 2)))) 94 (br_if 1 (i32.ge_u (local.get 0) (local.get 1))) 95 (local.set 0 (i32.add (local.get 0) (i32.const 1))) 96 (br_if 0 (i32.le_u (local.get 0) (local.get 1))) 97 ) 98 ) 99 (local.get 2) 100 ) 101 ) 102 103 (assert_return (invoke "check-table-null" (i32.const 0) (i32.const 9)) (ref.null func)) 104 (assert_return (invoke "grow" (i32.const 10)) (i32.const 10)) 105 (assert_return (invoke "check-table-null" (i32.const 0) (i32.const 19)) (ref.null func)) 106 107 108 ;; Type errors 109 110 (assert_invalid 111 (module 112 (table $t 0 externref) 113 (func $type-init-size-empty-vs-i32-externref (result i32) 114 (table.grow $t) 115 ) 116 ) 117 "type mismatch" 118 ) 119 (assert_invalid 120 (module 121 (table $t 0 externref) 122 (func $type-size-empty-vs-i32 (result i32) 123 (table.grow $t (ref.null extern)) 124 ) 125 ) 126 "type mismatch" 127 ) 128 (assert_invalid 129 (module 130 (table $t 0 externref) 131 (func $type-init-empty-vs-externref (result i32) 132 (table.grow $t (i32.const 1)) 133 ) 134 ) 135 "type mismatch" 136 ) 137 (assert_invalid 138 (module 139 (table $t 0 externref) 140 (func $type-size-f32-vs-i32 (result i32) 141 (table.grow $t (ref.null extern) (f32.const 1)) 142 ) 143 ) 144 "type mismatch" 145 ) 146 (assert_invalid 147 (module 148 (table $t 0 funcref) 149 (func $type-init-externref-vs-funcref (param $r externref) (result i32) 150 (table.grow $t (local.get $r) (i32.const 1)) 151 ) 152 ) 153 "type mismatch" 154 ) 155 156 (assert_invalid 157 (module 158 (table $t 1 externref) 159 (func $type-result-i32-vs-empty 160 (table.grow $t (ref.null extern) (i32.const 0)) 161 ) 162 ) 163 "type mismatch" 164 ) 165 (assert_invalid 166 (module 167 (table $t 1 externref) 168 (func $type-result-i32-vs-f32 (result f32) 169 (table.grow $t (ref.null extern) (i32.const 0)) 170 ) 171 ) 172 "type mismatch" 173 )