blob: ec9656c28c47c70f50c27884121d69099d6c0bcd [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
31
32// Set and remove a script break point for a named script.
33var sbp = Debug.setScriptBreakPointByName("1", 2, 3);
34assertEquals(1, Debug.scriptBreakPoints().length);
35assertEquals("1", Debug.scriptBreakPoints()[0].script_name());
36assertEquals(2, Debug.scriptBreakPoints()[0].line());
37assertEquals(3, Debug.scriptBreakPoints()[0].column());
38Debug.clearBreakPoint(sbp);
39assertEquals(0, Debug.scriptBreakPoints().length);
40
41// Set three script break points for named scripts.
42var sbp1 = Debug.setScriptBreakPointByName("1", 2, 3);
43var sbp2 = Debug.setScriptBreakPointByName("2", 3, 4);
44var sbp3 = Debug.setScriptBreakPointByName("3", 4, 5);
45
46// Check the content of the script break points.
47assertEquals(3, Debug.scriptBreakPoints().length);
48for (var i = 0; i < Debug.scriptBreakPoints().length; i++) {
49 var x = Debug.scriptBreakPoints()[i];
50 if ("1" == x.script_name()) {
51 assertEquals(2, x.line());
52 assertEquals(3, x.column());
53 } else if ("2" == x.script_name()) {
54 assertEquals(3, x.line());
55 assertEquals(4, x.column());
56 } else if ("3" == x.script_name()) {
57 assertEquals(4, x.line());
58 assertEquals(5, x.column());
59 } else {
60 assertUnreachable("unecpected script_name " + x.script_name());
61 }
62}
63
64// Remove script break points (in another order than they where added).
65assertEquals(3, Debug.scriptBreakPoints().length);
66Debug.clearBreakPoint(sbp1);
67assertEquals(2, Debug.scriptBreakPoints().length);
68Debug.clearBreakPoint(sbp3);
69assertEquals(1, Debug.scriptBreakPoints().length);
70Debug.clearBreakPoint(sbp2);
71assertEquals(0, Debug.scriptBreakPoints().length);
72
73// Set and remove a script break point for a script id.
74var sbp = Debug.setScriptBreakPointById(1, 2, 3);
75assertEquals(1, Debug.scriptBreakPoints().length);
76assertEquals(1, Debug.scriptBreakPoints()[0].script_id());
77assertEquals(2, Debug.scriptBreakPoints()[0].line());
78assertEquals(3, Debug.scriptBreakPoints()[0].column());
79Debug.clearBreakPoint(sbp);
80assertEquals(0, Debug.scriptBreakPoints().length);
81
82// Set three script break points for script ids.
83var sbp1 = Debug.setScriptBreakPointById(1, 2, 3);
84var sbp2 = Debug.setScriptBreakPointById(2, 3, 4);
85var sbp3 = Debug.setScriptBreakPointById(3, 4, 5);
86
87// Check the content of the script break points.
88assertEquals(3, Debug.scriptBreakPoints().length);
89for (var i = 0; i < Debug.scriptBreakPoints().length; i++) {
90 var x = Debug.scriptBreakPoints()[i];
91 if (1 == x.script_id()) {
92 assertEquals(2, x.line());
93 assertEquals(3, x.column());
94 } else if (2 == x.script_id()) {
95 assertEquals(3, x.line());
96 assertEquals(4, x.column());
97 } else if (3 == x.script_id()) {
98 assertEquals(4, x.line());
99 assertEquals(5, x.column());
100 } else {
101 assertUnreachable("unecpected script_id " + x.script_id());
102 }
103}
104
105// Remove script break points (in another order than they where added).
106assertEquals(3, Debug.scriptBreakPoints().length);
107Debug.clearBreakPoint(sbp1);
108assertEquals(2, Debug.scriptBreakPoints().length);
109Debug.clearBreakPoint(sbp3);
110assertEquals(1, Debug.scriptBreakPoints().length);
111Debug.clearBreakPoint(sbp2);
112assertEquals(0, Debug.scriptBreakPoints().length);