OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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: --validate-asm --allow-natives-syntax | 5 // Flags: --validate-asm --allow-natives-syntax |
6 | 6 |
7 // Note that this test file contains tests that explicitly check modules are | 7 // Note that this test file contains tests that explicitly check modules are |
8 // valid asm.js and then break them with invalid instantiation arguments. If | 8 // valid asm.js and then break them with invalid instantiation arguments. If |
9 // this script is run more than once (e.g. --stress-opt) then modules remain | 9 // this script is run more than once (e.g. --stress-opt) then modules remain |
10 // broken in the second run and assertions would fail. We prevent re-runs. | 10 // broken in the second run and assertions would fail. We prevent re-runs. |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 function Module() { | 406 function Module() { |
407 "use asm"; | 407 "use asm"; |
408 function foo() { | 408 function foo() { |
409 return bar() | 0; | 409 return bar() | 0; |
410 } | 410 } |
411 return foo; | 411 return foo; |
412 } | 412 } |
413 Module(); | 413 Module(); |
414 assertFalse(%IsAsmWasmCode(Module)); | 414 assertFalse(%IsAsmWasmCode(Module)); |
415 })(); | 415 })(); |
| 416 |
| 417 (function TestConditionalReturn() { |
| 418 function Module() { |
| 419 'use asm'; |
| 420 function foo(a, b) { |
| 421 a = +a; |
| 422 b = +b; |
| 423 // Allowed, despite not matching the spec, as emscripten emits this in |
| 424 // practice. |
| 425 return a == b ? +a : +b; |
| 426 } |
| 427 return foo; |
| 428 } |
| 429 var m = Module(); |
| 430 assertEquals(4, m(4, 4)); |
| 431 assertEquals(5, m(4, 5)); |
| 432 assertEquals(4, m(5, 4)); |
| 433 assertValidAsm(Module); |
| 434 })(); |
| 435 |
| 436 (function TestMismatchedConditionalReturn() { |
| 437 function Module() { |
| 438 'use asm'; |
| 439 function foo(a, b) { |
| 440 a = +a; |
| 441 return a == 0.0 ? 0 : +a; |
| 442 } |
| 443 return foo; |
| 444 } |
| 445 Module(); |
| 446 assertFalse(% IsAsmWasmCode(Module)); |
| 447 })(); |
| 448 |
| 449 (function TestBadIntConditionalReturn() { |
| 450 function Module() { |
| 451 'use asm'; |
| 452 function foo(a, b) { |
| 453 a = a | 0; |
| 454 b = b | 0; |
| 455 // Disallowed because signature must be signed, but these will be int. |
| 456 return 1 ? a : b; |
| 457 } |
| 458 return foo; |
| 459 } |
| 460 Module(); |
| 461 assertFalse(% IsAsmWasmCode(Module)); |
| 462 })(); |
| 463 |
| 464 (function TestBadSignedConditionalReturn() { |
| 465 function Module() { |
| 466 'use asm'; |
| 467 function foo(a, b) { |
| 468 a = a | 0; |
| 469 b = b | 0; |
| 470 // Disallowed because conditional yields int, even when both sides |
| 471 // are signed. |
| 472 return 1 ? a | 0 : b | 0; |
| 473 } |
| 474 return foo; |
| 475 } |
| 476 Module(); |
| 477 assertFalse(% IsAsmWasmCode(Module)); |
| 478 })(); |
OLD | NEW |