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 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. | 5 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode. |
6 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl
arations-web-legacy-compatibility-semantics | 6 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl
arations-web-legacy-compatibility-semantics |
7 | 7 |
8 (function overridingLocalFunction() { | 8 (function overridingLocalFunction() { |
9 var x = []; | 9 var x = []; |
10 assertEquals('function', typeof f); | 10 assertEquals('function', typeof f); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 448 } |
449 assertEquals(5, f()); | 449 assertEquals(5, f()); |
450 } | 450 } |
451 | 451 |
452 assertEquals(4, f()); | 452 assertEquals(4, f()); |
453 } | 453 } |
454 | 454 |
455 assertEquals(4, f()); | 455 assertEquals(4, f()); |
456 })(); | 456 })(); |
457 | 457 |
| 458 // B.3.5 interacts with B.3.3 to allow this. |
| 459 (function hoistingThroughSimpleCatch() { |
| 460 assertEquals(undefined, f); |
| 461 |
| 462 try { |
| 463 throw 0; |
| 464 } catch(f) { |
| 465 { |
| 466 assertEquals(4, f()); |
| 467 |
| 468 function f() { |
| 469 return 4; |
| 470 } |
| 471 |
| 472 assertEquals(4, f()); |
| 473 } |
| 474 } |
| 475 |
| 476 assertEquals(4, f()); |
| 477 })(); |
| 478 |
| 479 (function noHoistingThroughComplexCatch() { |
| 480 try { |
| 481 throw 0; |
| 482 } catch({f}) { |
| 483 { |
| 484 assertEquals(4, f()); |
| 485 |
| 486 function f() { |
| 487 return 4; |
| 488 } |
| 489 |
| 490 assertEquals(4, f()); |
| 491 } |
| 492 } |
| 493 |
| 494 assertThrows(()=>f, ReferenceError); |
| 495 })(); |
| 496 |
458 // Test that hoisting from blocks does happen in global scope | 497 // Test that hoisting from blocks does happen in global scope |
459 function globalHoisted() { return 0; } | 498 function globalHoisted() { return 0; } |
460 { | 499 { |
461 function globalHoisted() { return 1; } | 500 function globalHoisted() { return 1; } |
462 } | 501 } |
463 assertEquals(1, globalHoisted()); | 502 assertEquals(1, globalHoisted()); |
464 | 503 |
465 // Also happens when not previously defined | 504 // Also happens when not previously defined |
466 assertEquals(undefined, globalUndefinedHoisted); | 505 assertEquals(undefined, globalUndefinedHoisted); |
467 { | 506 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 throws = false; | 592 throws = false; |
554 try { | 593 try { |
555 eval('{ function hoistWhenFrozen() {} }'); | 594 eval('{ function hoistWhenFrozen() {} }'); |
556 } catch (e) { | 595 } catch (e) { |
557 throws = true; | 596 throws = true; |
558 } | 597 } |
559 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); | 598 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); |
560 assertThrows(() => hoistWhenFrozen, ReferenceError); | 599 assertThrows(() => hoistWhenFrozen, ReferenceError); |
561 // Should be assertFalse BUG(v8:4452) | 600 // Should be assertFalse BUG(v8:4452) |
562 assertTrue(throws); | 601 assertTrue(throws); |
OLD | NEW |