Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: test/mjsunit/debug-setbreakpoint.js

Issue 2557043005: [debugger] remove remaining uses of the debug command processor. (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/debug-scripts-request.js ('k') | test/mjsunit/debug-setexceptionbreak.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 19 matching lines...) Expand all
30 Debug = debug.Debug 30 Debug = debug.Debug
31 31
32 // Simple function which stores the last debug event. 32 // Simple function which stores the last debug event.
33 var listenerComplete = false; 33 var listenerComplete = false;
34 var exception = false; 34 var exception = false;
35 var f_script_id = 0; 35 var f_script_id = 0;
36 var g_script_id = 0; 36 var g_script_id = 0;
37 var h_script_id = 0; 37 var h_script_id = 0;
38 var f_line = 0; 38 var f_line = 0;
39 var g_line = 0; 39 var g_line = 0;
40 40 var h_line = 0;
41 var base_request = '"seq":0,"type":"request","command":"setbreakpoint"'
42
43 function safeEval(code) {
44 try {
45 return eval('(' + code + ')');
46 } catch (e) {
47 assertEquals(void 0, e);
48 return undefined;
49 }
50 }
51
52 function testArguments(dcp, arguments, success, is_script) {
53 var request = '{' + base_request + ',"arguments":' + arguments + '}'
54 var json_response = dcp.processDebugJSONRequest(request);
55 var response = safeEval(json_response);
56 if (success) {
57 assertTrue(response.success, request + ' -> ' + json_response);
58 if (is_script) {
59 assertEquals('scriptName', response.body.type, request + ' -> ' + json_res ponse);
60 } else {
61 assertEquals('scriptId', response.body.type, request + ' -> ' + json_respo nse);
62 }
63 } else {
64 assertFalse(response.success, request + ' -> ' + json_response);
65 }
66 return response;
67 }
68 41
69 function listener(event, exec_state, event_data, data) { 42 function listener(event, exec_state, event_data, data) {
70 try { 43 try {
71 if (event == Debug.DebugEvent.Break) { 44 if (event == Debug.DebugEvent.Break) {
72 // Get the debug command processor. 45 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value());
73 var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); 46 Debug.setBreakPoint(exec_state.evaluateGlobal("h").value());
47 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
48 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
49 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(),
50 undefined, undefined, "i == 1");
74 51
75 // Test some illegal setbreakpoint requests. 52 Debug.setScriptBreakPointByName("test");
76 var request = '{' + base_request + '}' 53 Debug.setScriptBreakPointByName("test", 1);
77 var response = safeEval(dcp.processDebugJSONRequest(request)); 54 Debug.setScriptBreakPointByName("test", 1, 1);
78 assertFalse(response.success);
79 55
80 var mirror; 56 Debug.setScriptBreakPointByName(f_script_id, f_line);
57 Debug.setScriptBreakPointByName(g_script_id, g_line);
58 Debug.setScriptBreakPointByName(h_script_id, h_line);
81 59
82 testArguments(dcp, '{}', false); 60 // Indicate that all was processed.
83 testArguments(dcp, '{"type":"xx"}', false); 61 listenerComplete = true;
84 testArguments(dcp, '{"type":"function"}', false); 62 }
85 testArguments(dcp, '{"type":"script"}', false);
86 testArguments(dcp, '{"target":"f"}', false);
87 testArguments(dcp, '{"type":"xx","target":"xx"}', false);
88 testArguments(dcp, '{"type":"function","target":1}', false);
89 testArguments(dcp, '{"type":"function","target":"f","line":-1}', false);
90 testArguments(dcp, '{"type":"function","target":"f","column":-1}', false);
91 testArguments(dcp, '{"type":"handle","target":"-1"}', false);
92 mirror = debug.MakeMirror(o);
93 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', fal se);
94
95 // Test some legal setbreakpoint requests.
96 testArguments(dcp, '{"type":"function","target":"f"}', true, false);
97 testArguments(dcp, '{"type":"function","target":"h"}', true, false);
98 testArguments(dcp, '{"type":"function","target":"f","line":1}', true, false) ;
99 testArguments(dcp, '{"type":"function","target":"f","position":1}', true, fa lse);
100 testArguments(dcp, '{"type":"function","target":"f","condition":"i == 1"}', true, false);
101 testArguments(dcp, '{"type":"function","target":"f","enabled":true}', true, false);
102 testArguments(dcp, '{"type":"function","target":"f","enabled":false}', true, false);
103
104 testArguments(dcp, '{"type":"script","target":"test"}', true, true);
105 testArguments(dcp, '{"type":"script","target":"test"}', true, true);
106 testArguments(dcp, '{"type":"script","target":"test","line":1}', true, true) ;
107 testArguments(dcp, '{"type":"script","target":"test","column":1}', true, tru e);
108
109 testArguments(dcp, '{"type":"scriptId","target":' + f_script_id + ',"line":' + f_line + '}', true, false);
110 testArguments(dcp, '{"type":"scriptId","target":' + g_script_id + ',"line":' + g_line + '}', true, false);
111 testArguments(dcp, '{"type":"scriptId","target":' + h_script_id + ',"line":' + h_line + '}', true, false);
112
113 mirror = debug.MakeMirror(f);
114 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', tru e, false);
115 mirror = debug.MakeMirror(o.a);
116 testArguments(dcp, '{"type":"handle","target":' + mirror.handle() + '}', tru e, false);
117
118 testArguments(dcp, '{"type":"script","target":"sourceUrlScript","line":0}', true, true);
119
120 // Set a break point on a line with the comment, and check that actual posit ion
121 // is the next line after the comment.
122 request = '{"type":"scriptId","target":' + g_script_id + ',"line":' + (g_lin e + 1) + '}';
123 response = testArguments(dcp, request, true, false);
124 assertEquals(g_line + 2, response.body.actual_locations[0].line);
125
126 // Indicate that all was processed.
127 listenerComplete = true;
128 }
129 } catch (e) { 63 } catch (e) {
130 exception = e 64 exception = e
131 }; 65 };
132 }; 66 };
133 67
134 // Add the debug event listener. 68 // Add the debug event listener.
135 Debug.setListener(listener); 69 Debug.setListener(listener);
136 70
137 function f() { 71 function f() {
138 a=1 72 a=1
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 112
179 // Try setting breakpoint by url specified in sourceURL 113 // Try setting breakpoint by url specified in sourceURL
180 114
181 var breakListenerCalled = false; 115 var breakListenerCalled = false;
182 116
183 function breakListener(event) { 117 function breakListener(event) {
184 if (event == Debug.DebugEvent.Break) 118 if (event == Debug.DebugEvent.Break)
185 breakListenerCalled = true; 119 breakListenerCalled = true;
186 } 120 }
187 121
122 Debug.setBreakPoint(sourceUrlFunc);
123
188 Debug.setListener(breakListener); 124 Debug.setListener(breakListener);
189 125
190 sourceUrlFunc(); 126 sourceUrlFunc();
191 127
192 assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by sourceURL"); 128 assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by sourceURL");
193 129
194 130
195 // Breakpoint in a script with no statements test case. If breakpoint is set 131 // Breakpoint in a script with no statements test case. If breakpoint is set
196 // to the script body, its actual position is taken from the nearest statement 132 // to the script body, its actual position is taken from the nearest statement
197 // below or like in this case is reset to the very end of the script. 133 // below or like in this case is reset to the very end of the script.
198 // Unless some precautions made, this position becomes out-of-range and 134 // Unless some precautions made, this position becomes out-of-range and
199 // we get an exception. 135 // we get an exception.
200 136
201 // Gets a script of 'i1' function and sets the breakpoint at line #4 which 137 // Gets a script of 'i1' function and sets the breakpoint at line #4 which
202 // should be empty. 138 // should be empty.
203 function SetBreakpointInI1Script() { 139 function SetBreakpointInI1Script() {
204 var i_script = Debug.findScript(i1); 140 var i_script = Debug.findScript(i1);
205 assertTrue(!!i_script, "invalid script for i1"); 141 assertTrue(!!i_script, "invalid script for i1");
206 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, 142 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
207 i_script.id, 4); 143 i_script.id, 4);
208 } 144 }
209 145
210 // Creates the eval script and tries to set the breakpoint. 146 // Creates the eval script and tries to set the breakpoint.
211 // The tricky part is that the script function must be strongly reachable at the 147 // The tricky part is that the script function must be strongly reachable at the
212 // moment. Since there's no way of simply getting the pointer to the function, 148 // moment. Since there's no way of simply getting the pointer to the function,
213 // we run this code while the script function is being activated on stack. 149 // we run this code while the script function is being activated on stack.
214 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); 150 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n');
OLDNEW
« no previous file with comments | « test/mjsunit/debug-scripts-request.js ('k') | test/mjsunit/debug-setexceptionbreak.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698