The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / deps / v8 / test / mjsunit / debug-evaluate-recursive.js @ 40c0f755
History | View | Annotate | Download (5.76 KB)
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.
|
30 |
Debug = debug.Debug |
31 |
|
32 |
listenerComplete = false;
|
33 |
exception = false;
|
34 |
|
35 |
// The base part of all evaluate requests.
|
36 |
var base_request = '"seq":0,"type":"request","command":"evaluate"' |
37 |
|
38 |
function safeEval(code) { |
39 |
try {
|
40 |
return eval('(' + code + ')'); |
41 |
} catch (e) {
|
42 |
assertEquals(void 0, e); |
43 |
return undefined; |
44 |
} |
45 |
} |
46 |
|
47 |
function testRequest(dcp, arguments, success, result) { |
48 |
// Generate request with the supplied arguments.
|
49 |
var request;
|
50 |
if (arguments) { |
51 |
request = '{' + base_request + ',"arguments":' + arguments + '}'; |
52 |
} else {
|
53 |
request = '{' + base_request + '}' |
54 |
} |
55 |
var response = safeEval(dcp.processDebugJSONRequest(request));
|
56 |
if (success) {
|
57 |
assertTrue(response.success, request + ' -> ' + response.message);
|
58 |
assertEquals(result, response.body.value); |
59 |
} else {
|
60 |
assertFalse(response.success, request + ' -> ' + response.message);
|
61 |
} |
62 |
assertFalse(response.running, request + ' -> expected not running');
|
63 |
} |
64 |
|
65 |
|
66 |
// Event listener which evaluates with break disabled.
|
67 |
function listener(event, exec_state, event_data, data) { |
68 |
try {
|
69 |
if (event == Debug.DebugEvent.Break)
|
70 |
{ |
71 |
// Call functions with break using the FrameMirror directly.
|
72 |
assertEquals(1, exec_state.evaluateGlobal('f()', true).value()); |
73 |
assertEquals(2, exec_state.evaluateGlobal('g()', true).value()); |
74 |
assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); |
75 |
assertEquals(2, exec_state.frame(0).evaluate('g()', true).value()); |
76 |
|
77 |
// Get the debug command processor.
|
78 |
var dcp = exec_state.debugCommandProcessor();
|
79 |
|
80 |
// Call functions with break using the JSON protocol. Tests that argument
|
81 |
// disable_break is default true.
|
82 |
testRequest(dcp, '{"expression":"f()"}', true, 1); |
83 |
testRequest(dcp, '{"expression":"f()","frame":0}', true, 1); |
84 |
testRequest(dcp, '{"expression":"g()"}', true, 2); |
85 |
testRequest(dcp, '{"expression":"g()","frame":0}', true, 2); |
86 |
|
87 |
// Call functions with break using the JSON protocol. Tests passing
|
88 |
// argument disable_break is default true.
|
89 |
testRequest(dcp, '{"expression":"f()","disable_break":true}', true, 1); |
90 |
testRequest(dcp, '{"expression":"f()","frame":0,"disable_break":true}',
|
91 |
true, 1); |
92 |
testRequest(dcp, '{"expression":"g()","disable_break":true}', true, 2); |
93 |
testRequest(dcp, '{"expression":"g()","frame":0,"disable_break":true}',
|
94 |
true, 2); |
95 |
|
96 |
// Indicate that all was processed.
|
97 |
listenerComplete = true;
|
98 |
} |
99 |
} catch (e) {
|
100 |
exception = e |
101 |
}; |
102 |
}; |
103 |
|
104 |
|
105 |
// Event listener which evaluates with break enabled one time and the second
|
106 |
// time evaluates with break disabled.
|
107 |
var break_count = 0; |
108 |
function listener_recurse(event, exec_state, event_data, data) { |
109 |
try {
|
110 |
if (event == Debug.DebugEvent.Break)
|
111 |
{ |
112 |
break_count++; |
113 |
|
114 |
// Call functions with break using the FrameMirror directly.
|
115 |
if (break_count == 1) { |
116 |
// First break event evaluates with break enabled.
|
117 |
assertEquals(1, exec_state.frame(0).evaluate('f()', false).value()); |
118 |
listenerComplete = true;
|
119 |
} else {
|
120 |
// Second break event evaluates with break disabled.
|
121 |
assertEquals(2, break_count);
|
122 |
assertFalse(listenerComplete); |
123 |
assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); |
124 |
} |
125 |
} |
126 |
} catch (e) {
|
127 |
exception = e |
128 |
}; |
129 |
}; |
130 |
|
131 |
// Add the debug event listener.
|
132 |
Debug.setListener(listener); |
133 |
|
134 |
// Test functions - one with break point and one with debugger statement.
|
135 |
function f() { |
136 |
return 1; |
137 |
}; |
138 |
|
139 |
function g() { |
140 |
debugger;
|
141 |
return 2; |
142 |
}; |
143 |
|
144 |
Debug.setBreakPoint(f, 2, 0); |
145 |
|
146 |
// Cause a debug break event.
|
147 |
debugger;
|
148 |
|
149 |
// Make sure that the debug event listener vas invoked.
|
150 |
assertTrue(listenerComplete); |
151 |
assertFalse(exception, "exception in listener")
|
152 |
|
153 |
// Remove the debug event listener.
|
154 |
Debug.setListener(null);
|
155 |
|
156 |
// Set debug event listener wich uses recursive breaks.
|
157 |
Debug.setListener(listener_recurse); |
158 |
listenerComplete = false;
|
159 |
|
160 |
Debug.setBreakPoint(f, 2, 0); |
161 |
|
162 |
debugger;
|
163 |
|
164 |
// Make sure that the debug event listener vas invoked.
|
165 |
assertTrue(listenerComplete); |
166 |
assertFalse(exception, "exception in listener")
|
167 |
assertEquals(2, break_count);
|