Environment-getVariable-12.js (1475B)
1 var g = newGlobal({newCompartment: true}); 2 var dbg = new Debugger; 3 var gw = dbg.addDebuggee(g); 4 5 var hits = 0; 6 dbg.onDebuggerStatement = function (frame) { 7 hits++; 8 assertEq(frame.environment.parent.getVariable('y'), true); 9 }; 10 11 g.eval("var g;" + 12 "function f(x) {" + 13 " { let y = x; " + 14 " if (x)" + 15 " g = function() { eval('debugger') };" + 16 " else" + 17 " g();" + 18 " }" + 19 "}" + 20 "f(true);" + 21 "f(false);"); 22 assertEq(hits, 1); 23 24 var hits = 0; 25 dbg.onDebuggerStatement = function (frame) { 26 hits++; 27 assertEq(frame.environment.parent.getVariable('y'), 1); 28 assertEq(frame.environment.parent.names().indexOf('z'), -1); 29 }; 30 31 g.eval("var g;" + 32 "{ let y = 1; " + 33 " g = function () { eval(''); debugger; };" + 34 " { let z = 2; " + 35 " g();" + 36 " }"+ 37 "}"); 38 assertEq(hits, 1); 39 40 var hits = 0; 41 dbg.onDebuggerStatement = function (frame) { 42 hits++; 43 var e = frame.older.environment.parent; 44 assertEq(e.getVariable('z'), true); 45 e = e.parent; 46 assertEq(e.getVariable('y'), true); 47 }; 48 49 g.eval("var g;" + 50 "function h() { eval(''); debugger; };" + 51 "for (var x of [true, false]) {" + 52 " { let y = x; " + 53 " { let z = x; " + 54 " if (x)" + 55 " g = function () { print(z); h() };" + 56 " else" + 57 " g();" + 58 " }" + 59 " }" + 60 "}"); 61 assertEq(hits, 1);