| 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 | |
| 497 // Test that hoisting from blocks does happen in global scope | 458 // Test that hoisting from blocks does happen in global scope |
| 498 function globalHoisted() { return 0; } | 459 function globalHoisted() { return 0; } |
| 499 { | 460 { |
| 500 function globalHoisted() { return 1; } | 461 function globalHoisted() { return 1; } |
| 501 } | 462 } |
| 502 assertEquals(1, globalHoisted()); | 463 assertEquals(1, globalHoisted()); |
| 503 | 464 |
| 504 // Also happens when not previously defined | 465 // Also happens when not previously defined |
| 505 assertEquals(undefined, globalUndefinedHoisted); | 466 assertEquals(undefined, globalUndefinedHoisted); |
| 506 { | 467 { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 throws = false; | 553 throws = false; |
| 593 try { | 554 try { |
| 594 eval('{ function hoistWhenFrozen() {} }'); | 555 eval('{ function hoistWhenFrozen() {} }'); |
| 595 } catch (e) { | 556 } catch (e) { |
| 596 throws = true; | 557 throws = true; |
| 597 } | 558 } |
| 598 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); | 559 assertFalse(this.hasOwnProperty("hoistWhenFrozen")); |
| 599 assertThrows(() => hoistWhenFrozen, ReferenceError); | 560 assertThrows(() => hoistWhenFrozen, ReferenceError); |
| 600 // Should be assertFalse BUG(v8:4452) | 561 // Should be assertFalse BUG(v8:4452) |
| 601 assertTrue(throws); | 562 assertTrue(throws); |
| OLD | NEW |