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 3 // found in the LICENSE file. 4 5 // Flags: --expose-debug-as debug 6 7 Debug = debug.Debug 8 var exception = null; 9 var break_count = 0; 10 11 function listener(event, exec_state, event_data, data) { 12 try { 13 if (event == Debug.DebugEvent.Break) { 14 assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace"); 15 // Count number of expected breakpoints in this source file. 16 if (!break_count) { 17 var source_text = exec_state.frame(0).func().script().source(); 18 expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length; 19 print("Expected breaks: " + expected_breaks); 20 } 21 var frameMirror = exec_state.frame(0); 22 23 frameMirror.allScopes(); 24 var source = frameMirror.sourceLineText(); 25 print("paused at: " + source); 26 assertTrue(source.indexOf("// Break " + break_count + ".") > 0, 27 "Unexpected pause at: " + source + "\n" + 28 "Expected: // Break " + break_count + "."); 29 ++break_count; 30 31 if (break_count !== expected_breaks) { 32 exec_state.prepareStep(Debug.StepAction.StepIn); 33 print("Next step prepared"); 34 } 35 } 36 } catch(e) { 37 exception = e; 38 print(e, e.stack); 39 } 40 }; 41 42 Debug.setListener(listener); 43 44 var sum = 0; 45 (function (){ 46 'use strict'; 47 48 debugger; // Break 0. 49 var i = 0; // Break 1. 50 i++; // Break 2. 51 i++; // Break 3. 52 debugger; // Break 4. 53 return i; // Break 5. 54 }()); // Break 6. 55 56 assertNull(exception); // Break 7. 57 assertEquals(expected_breaks, break_count); 58 59 Debug.setListener(null); 60