OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 function assertWasm(expected, func, ffi) { | 7 function assertWasm(expected, func, ffi) { |
8 print("Testing " + func.name + "..."); | 8 print("Testing " + func.name + "..."); |
9 assertEquals(expected, Wasm.instantiateModuleFromAsm( | 9 assertEquals(expected, Wasm.instantiateModuleFromAsm( |
10 func.toString(), ffi).caller()); | 10 func.toString(), ffi).caller()); |
11 } | 11 } |
12 | 12 |
13 function EmptyTest() { | 13 function EmptyTest() { |
14 "use asm"; | 14 "use asm"; |
15 function caller() { | 15 function caller() { |
16 empty(); | 16 empty(); |
17 return 11; | 17 return 11; |
18 } | 18 } |
19 function empty() { | 19 function empty() { |
20 } | 20 } |
21 return {caller: caller}; | 21 return {caller: caller}; |
22 } | 22 } |
23 | 23 |
24 assertWasm(11, EmptyTest); | 24 assertWasm(11, EmptyTest); |
25 | 25 |
| 26 function VoidReturnTest() { |
| 27 "use asm"; |
| 28 function caller() { |
| 29 empty(); |
| 30 return 19; |
| 31 } |
| 32 function empty() { |
| 33 var x = 0; |
| 34 if (x) return; |
| 35 } |
| 36 return {caller: caller}; |
| 37 } |
| 38 |
| 39 assertWasm(19, VoidReturnTest); |
26 | 40 |
27 function IntTest() { | 41 function IntTest() { |
28 "use asm"; | 42 "use asm"; |
29 function sum(a, b) { | 43 function sum(a, b) { |
30 a = a|0; | 44 a = a|0; |
31 b = b|0; | 45 b = b|0; |
32 var c = (b + 1)|0 | 46 var c = (b + 1)|0 |
33 var d = 3.0; | 47 var d = 3.0; |
34 var e = ~~d; // double conversion | 48 var e = ~~d; // double conversion |
35 return (a + c + 1)|0; | 49 return (a + c + 1)|0; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 return 7; | 200 return 7; |
187 return x|0; | 201 return x|0; |
188 } | 202 } |
189 | 203 |
190 return {caller: caller}; | 204 return {caller: caller}; |
191 } | 205 } |
192 | 206 |
193 assertWasm(7, TestReturnInWhileWithoutBraces); | 207 assertWasm(7, TestReturnInWhileWithoutBraces); |
194 | 208 |
195 | 209 |
| 210 function TestBreakInIf() { |
| 211 "use asm"; |
| 212 |
| 213 function caller() { |
| 214 label: { |
| 215 if(1) break label; |
| 216 return 11; |
| 217 } |
| 218 return 12; |
| 219 } |
| 220 |
| 221 return {caller: caller}; |
| 222 } |
| 223 |
| 224 assertWasm(12, TestBreakInIf); |
| 225 |
| 226 function TestBreakInIfInDoWhileFalse() { |
| 227 "use asm"; |
| 228 |
| 229 function caller() { |
| 230 do { |
| 231 if(1) break; |
| 232 return 11; |
| 233 } while(0); |
| 234 return 12; |
| 235 } |
| 236 |
| 237 return {caller: caller}; |
| 238 } |
| 239 |
| 240 assertWasm(12, TestBreakInIfInDoWhileFalse); |
| 241 |
| 242 function TestBreakInElse() { |
| 243 "use asm"; |
| 244 |
| 245 function caller() { |
| 246 do { |
| 247 if(0) ; |
| 248 else break; |
| 249 return 14; |
| 250 } while(0); |
| 251 return 15; |
| 252 } |
| 253 |
| 254 return {caller: caller}; |
| 255 } |
| 256 |
| 257 assertWasm(15, TestBreakInElse); |
| 258 |
196 function TestBreakInWhile() { | 259 function TestBreakInWhile() { |
197 "use asm"; | 260 "use asm"; |
198 | 261 |
199 function caller() { | 262 function caller() { |
200 while(1) { | 263 while(1) { |
201 break; | 264 break; |
202 } | 265 } |
203 return 8; | 266 return 8; |
204 } | 267 } |
205 | 268 |
206 return {caller: caller}; | 269 return {caller: caller}; |
207 } | 270 } |
208 | 271 |
209 assertWasm(8, TestBreakInWhile); | 272 assertWasm(8, TestBreakInWhile); |
210 | 273 |
211 | 274 |
| 275 function TestBreakInIfInWhile() { |
| 276 "use asm"; |
| 277 |
| 278 function caller() { |
| 279 while(1) { |
| 280 if (1) break; |
| 281 else break; |
| 282 } |
| 283 return 8; |
| 284 } |
| 285 |
| 286 return {caller: caller}; |
| 287 } |
| 288 |
| 289 assertWasm(8, TestBreakInIfInWhile); |
| 290 |
212 function TestBreakInNestedWhile() { | 291 function TestBreakInNestedWhile() { |
213 "use asm"; | 292 "use asm"; |
214 | 293 |
215 function caller() { | 294 function caller() { |
216 var x = 1.0; | 295 var x = 1.0; |
217 while(x < 1.5) { | 296 while(x < 1.5) { |
218 while(1) | 297 while(1) |
219 break; | 298 break; |
220 x = +(x + 0.25); | 299 x = +(x + 0.25); |
221 } | 300 } |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 u0xffffffff: u0xffffffff, | 1489 u0xffffffff: u0xffffffff, |
1411 u0x80000000: u0x80000000, | 1490 u0x80000000: u0x80000000, |
1412 u0x87654321: u0x87654321, | 1491 u0x87654321: u0x87654321, |
1413 }; | 1492 }; |
1414 } | 1493 } |
1415 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 1494 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
1416 assertEquals(0xffffffff, wasm.u0xffffffff()); | 1495 assertEquals(0xffffffff, wasm.u0xffffffff()); |
1417 assertEquals(0x80000000, wasm.u0x80000000()); | 1496 assertEquals(0x80000000, wasm.u0x80000000()); |
1418 assertEquals(0x87654321, wasm.u0x87654321()); | 1497 assertEquals(0x87654321, wasm.u0x87654321()); |
1419 })(); | 1498 })(); |
OLD | NEW |