misc-control-flow.js (4786B)
1 wasmFailValidateText(`(module 2 (func (param i32) (result i32) 3 (loop (if (i32.const 0) (then (br 0))) (local.get 0))) 4 (export "" (func 0)) 5 )`, /(unused values not explicitly dropped by end of block)|(values remaining on stack at end of block)/); 6 7 wasmFailValidateText(`(module 8 (func (param i32) 9 (loop (if (i32.const 0) (then (br 0))) (local.get 0))) 10 (export "" (func 0)) 11 )`, /(unused values not explicitly dropped by end of block)|(values remaining on stack at end of block)/); 12 13 wasmFailValidateText(`(module 14 (func (param i32) (result i32) 15 (loop (if (i32.const 0) (then (br 0))) (drop (local.get 0)))) 16 (export "" (func 0)) 17 )`, emptyStackError); 18 19 assertEq(wasmEvalText(`(module 20 (func (param i32) (result i32) 21 (loop (if (i32.const 0) (then (br 0)))) (local.get 0)) 22 (export "" (func 0)) 23 )`).exports[""](42), 42); 24 25 wasmEvalText(`(module (func $func$0 26 (block (if (i32.const 1) (then (loop (br_table 0 (br 0)))))) 27 ) 28 )`); 29 30 wasmEvalText(`(module (func 31 (block $out (loop $in (br_table $out $out $in (i32.const 0)))) 32 ) 33 )`); 34 35 wasmEvalText(`(module (func (result i32) 36 (select 37 (block (result i32) 38 (drop (block (result i32) 39 (br_table 40 1 41 0 42 (i32.const 1) 43 (i32.const 0) 44 ) 45 )) 46 (i32.const 2) 47 ) 48 (i32.const 3) 49 (i32.const 4) 50 ) 51 )) 52 `); 53 54 wasmEvalText(`(module 55 (func (param i32) (param i32) (result i32) (i32.const 0)) 56 (func (result i32) 57 (call 0 (i32.const 1) (call 0 (i32.const 2) (i32.const 3))) 58 (call 0 (unreachable) (i32.const 4)) 59 ) 60 )`); 61 62 wasmEvalText(` 63 (module 64 65 (func 66 (param i32) (param i32) (param i32) (param i32) 67 (result i32) 68 (i32.const 0) 69 ) 70 71 (func (result i32) 72 (call 0 73 (i32.const 42) 74 (i32.const 53) 75 (call 0 (i32.const 100) (i32.const 13) (i32.const 37) (i32.const 128)) 76 (return (i32.const 42)) 77 ) 78 ) 79 80 (export "" (func 1)) 81 ) 82 `).exports[""](); 83 84 wasmEvalText(` 85 (module 86 (import "check" "one" (func (param i32))) 87 (import "check" "two" (func (param i32) (param i32))) 88 (func (param i32) (call 0 (local.get 0))) 89 (func (param i32) (param i32) (call 1 (local.get 0) (local.get 1))) 90 (func 91 (call 1 92 (i32.const 43) 93 (block $b (result i32) 94 (if (i32.const 1) 95 (then (call 0 96 (block (result i32) 97 (call 0 (i32.const 42)) 98 (br $b (i32.const 10)))))) 99 (i32.const 44)))) 100 (export "foo" (func 4))) 101 `, { 102 check: { 103 one(x) { 104 assertEq(x, 42); 105 }, 106 two(x, y) { 107 assertEq(x, 43); 108 assertEq(y, 10); 109 } 110 } 111 }).exports.foo(); 112 113 assertEq(wasmEvalText(`(module (func 114 return 115 (select 116 (loop (result i32) (i32.const 1)) 117 (loop (result i32) (i32.const 2)) 118 (i32.const 3) 119 ) 120 drop 121 ) (export "" (func 0)))`).exports[""](), undefined); 122 123 wasmEvalText(`(module (func (result i32) 124 (return (i32.const 0)) 125 (select 126 (loop (result i32) (i32.const 1)) 127 (loop (result i32) (i32.const 2)) 128 (i32.const 3) 129 ) 130 ))`); 131 132 wasmEvalText(`(module (func 133 (block $return 134 (block $beforeReturn 135 (block $out 136 (loop $in 137 (block $otherTable 138 (br_table 139 $return 140 $return 141 $otherTable 142 $beforeReturn 143 (i32.const 0) 144 ) 145 ) 146 (block $backTop 147 (br_table 148 $backTop 149 $backTop 150 $beforeReturn 151 (i32.const 0) 152 ) 153 ) 154 (br $in) 155 ) 156 ) 157 ) 158 ) 159 ))`); 160 161 wasmFailValidateText( 162 `(module 163 (func $func$0 164 (select 165 (if (result f32) 166 (i32.const 0) 167 (then (f32.const 0)) 168 (else (i32.const 0)) 169 ) 170 (if (result f32) 171 (i32.const 0) 172 (then (f32.const 0)) 173 (else (i32.const 0)) 174 ) 175 (i32.const 0) 176 ) 177 ) 178 )`, mismatchError("i32", "f32")); 179 180 wasmEvalText(` 181 (module 182 (func (result i32) 183 (i32.add 184 (block $outer (result i32) 185 (drop (block $middle (result i32) 186 (block $inner (result i32) 187 (br_table $middle $outer $inner (i32.const 42) (i32.const 1)) 188 ) 189 (nop) 190 )) 191 (i32.const 0) 192 ) 193 (i32.const 13) 194 ) 195 ) 196 ) 197 `); 198 199 wasmFailValidateText(` 200 (module 201 (func (result i32) 202 (loop 203 (i32.const 0) 204 (br_table 1 0 (i32.const 15)) 205 ) 206 ) 207 )`, /(br_table targets must all have the same arity)|(br_table target labels have different types)/); 208 209 wasmFailValidateText(` 210 (module 211 (func (result i32) 212 (loop (result i32) 213 (i32.const 0) 214 (br_table 1 0 (i32.const 15)) 215 ) 216 ) 217 )`, /(br_table targets must all have the same arity)|(br_table target labels have different types)/); 218 219 wasmValidateText(` 220 (module 221 (func 222 (loop 223 (i32.const 0) 224 (br_table 1 0 (i32.const 15)) 225 ) 226 ) 227 )`);