blob: 6f31ef11d848fa599b49cec484f29619b8c4c5d7 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// 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
Ben Murdoch014dc512016-03-22 12:00:34 +000031Debug.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
Steve Blocka7e24c12009-10-30 11:49:00 +000060
61// Set and remove a script break point for a named script.
Ben Murdoch014dc512016-03-22 12:00:34 +000062var sbp = Debug.setScriptBreakPointByName(script_name, 35, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +000063assertEquals(1, Debug.scriptBreakPoints().length);
Ben Murdoch014dc512016-03-22 12:00:34 +000064checkBreakPoint(0, 35, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +000065Debug.clearBreakPoint(sbp);
66assertEquals(0, Debug.scriptBreakPoints().length);
67
68// Set three script break points for named scripts.
Ben Murdoch014dc512016-03-22 12:00:34 +000069var sbp1 = Debug.setScriptBreakPointByName(script_name, 36, 3);
70var sbp2 = Debug.setScriptBreakPointByName(script_name, 37, 4);
71var sbp3 = Debug.setScriptBreakPointByName(script_name, 38, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +000072
73// Check the content of the script break points.
74assertEquals(3, Debug.scriptBreakPoints().length);
Ben Murdoch014dc512016-03-22 12:00:34 +000075checkBreakPoint(0, 36, 3);
76checkBreakPoint(1, 37, 4);
77checkBreakPoint(2, 38, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +000078
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
Ben Murdoch014dc512016-03-22 12:00:34 +000088
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
Steve Blocka7e24c12009-10-30 11:49:00 +000098// Set and remove a script break point for a script id.
Ben Murdoch014dc512016-03-22 12:00:34 +000099var sbp = Debug.setScriptBreakPointById(script_id, 40, 6);
Steve Blocka7e24c12009-10-30 11:49:00 +0000100assertEquals(1, Debug.scriptBreakPoints().length);
Ben Murdoch014dc512016-03-22 12:00:34 +0000101checkBreakPoint(0, 40, 6);
Steve Blocka7e24c12009-10-30 11:49:00 +0000102Debug.clearBreakPoint(sbp);
103assertEquals(0, Debug.scriptBreakPoints().length);
104
105// Set three script break points for script ids.
Ben Murdoch014dc512016-03-22 12:00:34 +0000106var sbp1 = Debug.setScriptBreakPointById(script_id, 42, 3);
107var sbp2 = Debug.setScriptBreakPointById(script_id, 43, 4);
108var sbp3 = Debug.setScriptBreakPointById(script_id, 44, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +0000109
110// Check the content of the script break points.
111assertEquals(3, Debug.scriptBreakPoints().length);
Ben Murdoch014dc512016-03-22 12:00:34 +0000112checkBreakPoint(0, 42, 3);
113checkBreakPoint(1, 43, 4);
114checkBreakPoint(2, 44, 5);
Steve Blocka7e24c12009-10-30 11:49:00 +0000115
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);
Ben Murdoch014dc512016-03-22 12:00:34 +0000124
125Debug.setListener(null);