1// Copyright 2008 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28// Flags: --expose-debug-as debug 29// Get the Debug object exposed from the debug context global object. 30Debug = debug.Debug 31Debug.setListener(function(){}); 32 33var script_id; 34var script_name; 35 36// Get current script id and name. 37var scripts = Debug.scripts(); 38for (var i = 0; i < scripts.length; i++) { 39 var name = scripts[i].name; 40 var id = scripts[i].id; 41 if (name !== undefined && name.includes("debug-script-breakpoints.js")) { 42 script_id = id; 43 script_name = name; 44 break; 45 } 46} 47assertTrue(script_id !== undefined); 48assertTrue(script_name !== undefined); 49print("#" + script_id + ": " + script_name); 50 51 52// Checks script name, line and column. 53var checkBreakPoint = function(id, line, column) { 54 var breakpoint = Debug.scriptBreakPoints()[id]; 55 assertEquals(script_name, breakpoint.script_name()); 56 assertEquals(line, breakpoint.line()); 57 assertEquals(column, breakpoint.column()); 58} 59 60 61// Set and remove a script break point for a named script. 62var sbp = Debug.setScriptBreakPointByName(script_name, 35, 5); 63assertEquals(1, Debug.scriptBreakPoints().length); 64checkBreakPoint(0, 35, 5); 65Debug.clearBreakPoint(sbp); 66assertEquals(0, Debug.scriptBreakPoints().length); 67 68// Set three script break points for named scripts. 69var sbp1 = Debug.setScriptBreakPointByName(script_name, 36, 3); 70var sbp2 = Debug.setScriptBreakPointByName(script_name, 37, 4); 71var sbp3 = Debug.setScriptBreakPointByName(script_name, 38, 5); 72 73// Check the content of the script break points. 74assertEquals(3, Debug.scriptBreakPoints().length); 75checkBreakPoint(0, 36, 3); 76checkBreakPoint(1, 37, 4); 77checkBreakPoint(2, 38, 5); 78 79// Remove script break points (in another order than they where added). 80assertEquals(3, Debug.scriptBreakPoints().length); 81Debug.clearBreakPoint(sbp1); 82assertEquals(2, Debug.scriptBreakPoints().length); 83Debug.clearBreakPoint(sbp3); 84assertEquals(1, Debug.scriptBreakPoints().length); 85Debug.clearBreakPoint(sbp2); 86assertEquals(0, Debug.scriptBreakPoints().length); 87 88 89// Checks script id, line and column. 90var checkBreakPoint = function(id, line, column) { 91 var breakpoint = Debug.scriptBreakPoints()[id]; 92 assertEquals(script_id, breakpoint.script_id()); 93 assertEquals(line, breakpoint.line()); 94 assertEquals(column, breakpoint.column()); 95} 96 97 98// Set and remove a script break point for a script id. 99var sbp = Debug.setScriptBreakPointById(script_id, 40, 6); 100assertEquals(1, Debug.scriptBreakPoints().length); 101checkBreakPoint(0, 40, 6); 102Debug.clearBreakPoint(sbp); 103assertEquals(0, Debug.scriptBreakPoints().length); 104 105// Set three script break points for script ids. 106var sbp1 = Debug.setScriptBreakPointById(script_id, 42, 3); 107var sbp2 = Debug.setScriptBreakPointById(script_id, 43, 4); 108var sbp3 = Debug.setScriptBreakPointById(script_id, 44, 5); 109 110// Check the content of the script break points. 111assertEquals(3, Debug.scriptBreakPoints().length); 112checkBreakPoint(0, 42, 3); 113checkBreakPoint(1, 43, 4); 114checkBreakPoint(2, 44, 5); 115 116// Remove script break points (in another order than they where added). 117assertEquals(3, Debug.scriptBreakPoints().length); 118Debug.clearBreakPoint(sbp1); 119assertEquals(2, Debug.scriptBreakPoints().length); 120Debug.clearBreakPoint(sbp3); 121assertEquals(1, Debug.scriptBreakPoints().length); 122Debug.clearBreakPoint(sbp2); 123assertEquals(0, Debug.scriptBreakPoints().length); 124 125Debug.setListener(null); 126