1// Copyright 2016 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 7var Debug = debug.Debug; 8var break_count = 0; 9var exception_count = 0; 10 11function assertCount(expected_breaks, expected_exceptions) { 12 assertEquals(expected_breaks, break_count); 13 assertEquals(expected_exceptions, exception_count); 14} 15 16function listener(event, exec_state, event_data, data) { 17 if (event == Debug.DebugEvent.Break) { 18 break_count++; 19 } else if (event == Debug.DebugEvent.Exception) { 20 exception_count++; 21 } 22} 23 24function f(x) { 25 debugger; 26 return x + 1; 27} 28 29function g(x) { 30 try { 31 throw x; 32 } catch (e) { 33 } 34} 35 36function h(x) { 37 var a = undefined; 38 try { 39 var x = a(); 40 } catch (e) { 41 } 42} 43 44Debug.setListener(listener); 45 46assertCount(0, 0); 47f(0); 48assertCount(1, 0); 49g(0); 50assertCount(1, 0); 51 52Debug.setBreakOnException(); 53f(0); 54assertCount(2, 0); 55g(0); 56assertCount(2, 1); 57 58Debug.setBreakPoint(f, 1, 0, "x == 1"); 59f(1); 60assertCount(3, 1); 61f(2); 62assertCount(3, 1); 63f(1); 64assertCount(4, 1); 65 66Debug.setBreakPoint(f, 1, 0, "x > 0"); 67f(1); 68assertCount(5, 1); 69f(0); 70assertCount(5, 1); 71 72Debug.setBreakPoint(g, 2, 0, "1 == 2"); 73g(1); 74assertCount(5, 1); 75 76Debug.setBreakPoint(g, 2, 0, "x == 1"); 77g(1); 78assertCount(6, 2); 79g(2); 80assertCount(6, 2); 81g(1); 82assertCount(7, 3); 83 84Debug.setBreakPoint(g, 2, 0, "x > 0"); 85g(1); 86assertCount(8, 4); 87g(0); 88assertCount(8, 4); 89 90h(0); 91assertCount(8, 5); 92Debug.setBreakPoint(h, 3, 0, "x > 0"); 93h(1); 94assertCount(9, 6); 95h(0); 96assertCount(9, 6); 97 98Debug.clearBreakOnException(); 99Debug.setListener(null); 100