Frame-onStep-14.js (1317B)
1 // Test how stepping interacts with switch statements. 2 3 var g = newGlobal({newCompartment: true}); 4 5 g.eval('function bob() { return "bob"; }'); 6 7 // Stepping into a sparse switch should not stop on literal cases. 8 evaluate(`function lit(x) { // 1 9 debugger; // 2 10 switch(x) { // 3 11 case "nope": // 4 12 break; // 5 13 case "bob": // 6 14 break; // 7 15 } // 8 16 }`, {lineNumber: 1, global: g}); 17 18 // Stepping into a sparse switch should stop on non-literal cases. 19 evaluate(`function nonlit(x) { // 1 20 debugger; // 2 21 switch(x) { // 3 22 case bob(): // 4 23 break; // 5 24 } // 6 25 }`, {lineNumber: 1, global: g}); 26 27 var dbg = Debugger(g); 28 var badStep = false; 29 30 function test(s, okLine) { 31 dbg.onDebuggerStatement = function(frame) { 32 frame.onStep = function() { 33 let thisLine = this.script.getOffsetLocation(this.offset).lineNumber; 34 // The stop at line 3 is the switch. 35 if (thisLine > 3) { 36 assertEq(thisLine, okLine) 37 frame.onStep = undefined; 38 } 39 }; 40 }; 41 g.eval(s); 42 } 43 44 test("lit('bob');", 7); 45 46 test("nonlit('bob');", 4);