letTDZSwitchClosure.js (890B)
1 function assertThrowsReferenceError(f) { 2 var err; 3 try { 4 f(); 5 } catch (e) { 6 err = e; 7 } 8 assertEq(err instanceof ReferenceError, true); 9 } 10 11 function f() { 12 switch (0) { 13 case 1: 14 let x 15 case function() { 16 print(x) 17 }(): 18 } 19 } 20 assertThrowsReferenceError(f); 21 22 function g() { 23 switch (0) { 24 case 1: 25 let x; 26 case 0: 27 var inner = function () { 28 print(x); 29 } 30 inner(); 31 break; 32 } 33 } 34 assertThrowsReferenceError(g); 35 36 function h() { 37 switch (0) { 38 case 0: 39 var inner = function () { 40 print(x); 41 } 42 inner(); 43 case 1: 44 let x; 45 } 46 } 47 assertThrowsReferenceError(h); 48 49 // Tests that a dominating lexical doesn't throw. 50 function F() { 51 switch (0) { 52 case 0: 53 let x = 42; 54 var inner = function () { 55 assertEq(x, 42); 56 } 57 inner(); 58 } 59 } 60 F();