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

Side by Side Diff: test/debugger/test-api.js

Issue 2508853003: [debug-wrapper] clearAllBreakPoints and several scripts functions (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // If true, prints all messages sent and received by inspector. 7 // If true, prints all messages sent and received by inspector.
8 const printProtocolMessages = false; 8 const printProtocolMessages = false;
9 9
10 // The active wrapper instance. 10 // The active wrapper instance.
(...skipping 27 matching lines...) Expand all
38 AsyncTaskEvent: 7 38 AsyncTaskEvent: 7
39 }; 39 };
40 40
41 // The different types of steps. 41 // The different types of steps.
42 this.StepAction = { StepOut: 0, 42 this.StepAction = { StepOut: 0,
43 StepNext: 1, 43 StepNext: 1,
44 StepIn: 2, 44 StepIn: 2,
45 StepFrame: 3, 45 StepFrame: 3,
46 }; 46 };
47 47
48 // The different types of scripts matching enum ScriptType in objects.h.
49 this.ScriptType = { Native: 0,
50 Extension: 1,
51 Normal: 2,
52 Wasm: 3};
53
48 // A copy of the scope types from runtime-debug.cc. 54 // A copy of the scope types from runtime-debug.cc.
49 // NOTE: these constants should be backward-compatible, so 55 // NOTE: these constants should be backward-compatible, so
50 // add new ones to the end of this list. 56 // add new ones to the end of this list.
51 this.ScopeType = { Global: 0, 57 this.ScopeType = { Global: 0,
52 Local: 1, 58 Local: 1,
53 With: 2, 59 With: 2,
54 Closure: 3, 60 Closure: 3,
55 Catch: 4, 61 Catch: 4,
56 Block: 5, 62 Block: 5,
57 Script: 6, 63 Script: 6,
(...skipping 13 matching lines...) Expand all
71 }; 77 };
72 78
73 // The different script break point types. 79 // The different script break point types.
74 this.ScriptBreakPointType = { ScriptId: 0, 80 this.ScriptBreakPointType = { ScriptId: 0,
75 ScriptName: 1, 81 ScriptName: 1,
76 ScriptRegExp: 2 }; 82 ScriptRegExp: 2 };
77 83
78 // Store the current script id so we can skip corresponding break events. 84 // Store the current script id so we can skip corresponding break events.
79 this.thisScriptId = %FunctionGetScriptId(receive); 85 this.thisScriptId = %FunctionGetScriptId(receive);
80 86
87 // Stores all set breakpoints.
88 this.breakpoints = new Set();
89
81 // Register as the active wrapper. 90 // Register as the active wrapper.
82 assertTrue(activeWrapper === undefined); 91 assertTrue(activeWrapper === undefined);
83 activeWrapper = this; 92 activeWrapper = this;
84 } 93 }
85 94
86 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } 95 enable() { this.sendMessageForMethodChecked("Debugger.enable"); }
87 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } 96 disable() { this.sendMessageForMethodChecked("Debugger.disable"); }
88 97
89 setListener(listener) { this.listener = listener; } 98 setListener(listener) { this.listener = listener; }
90 99
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 setBreakPoint(func, opt_line, opt_column, opt_condition) { 138 setBreakPoint(func, opt_line, opt_column, opt_condition) {
130 assertTrue(%IsFunction(func)); 139 assertTrue(%IsFunction(func));
131 assertFalse(%FunctionIsAPIFunction(func)); 140 assertFalse(%FunctionIsAPIFunction(func));
132 141
133 const scriptid = %FunctionGetScriptId(func); 142 const scriptid = %FunctionGetScriptId(func);
134 assertTrue(scriptid != -1); 143 assertTrue(scriptid != -1);
135 144
136 const offset = %FunctionGetScriptSourcePosition(func); 145 const offset = %FunctionGetScriptSourcePosition(func);
137 const loc = 146 const loc =
138 %ScriptLocationFromLine2(scriptid, opt_line, opt_column, offset); 147 %ScriptLocationFromLine2(scriptid, opt_line, opt_column, offset);
139 148 return this.setBreakPointAtLocation(scriptid, loc, opt_condition);
140 const params = { location :
141 { scriptId : scriptid.toString(),
142 lineNumber : loc.line,
143 columnNumber : loc.column,
144 }};
145 if (!!opt_condition) {
146 params.condition = opt_condition;
147 }
148
149 const {msgid, msg} = this.createMessage("Debugger.setBreakpoint", params);
150 this.sendMessage(msg);
151
152 const reply = this.takeReplyChecked(msgid);
153 assertTrue(reply.result !== undefined);
154 const breakid = reply.result.breakpointId;
155 assertTrue(breakid !== undefined);
156
157 return breakid;
158 } 149 }
159 150
160 setScriptBreakPoint(type, scriptid, opt_line, opt_column, opt_condition) { 151 setScriptBreakPoint(type, scriptid, opt_line, opt_column, opt_condition) {
161 // Only sets by script id are supported for now. 152 // Only sets by script id are supported for now.
162 assertEquals(this.ScriptBreakPointType.ScriptId, type); 153 assertEquals(this.ScriptBreakPointType.ScriptId, type);
163 return this.setScriptBreakPointById(scriptid, opt_line, opt_column, 154 return this.setScriptBreakPointById(scriptid, opt_line, opt_column,
164 opt_condition); 155 opt_condition);
165 } 156 }
166 157
167 setScriptBreakPointById(scriptid, opt_line, opt_column, opt_condition) { 158 setScriptBreakPointById(scriptid, opt_line, opt_column, opt_condition) {
168 const loc = %ScriptLocationFromLine2(scriptid, opt_line, opt_column, 0); 159 const loc = %ScriptLocationFromLine2(scriptid, opt_line, opt_column, 0);
169 160 return this.setBreakPointAtLocation(scriptid, loc, opt_condition);
170 const params = { location :
171 { scriptId : scriptid.toString(),
172 lineNumber : loc.line,
173 columnNumber : loc.column,
174 }};
175 if (!!opt_condition) {
176 params.condition = opt_condition;
177 }
178
179 const {msgid, msg} = this.createMessage("Debugger.setBreakpoint", params);
180 this.sendMessage(msg);
181
182 const reply = this.takeReplyChecked(msgid);
183 assertTrue(reply.result !== undefined);
184 const breakid = reply.result.breakpointId;
185 assertTrue(breakid !== undefined);
186
187 return breakid;
188 } 161 }
189 162
190 clearBreakPoint(breakid) { 163 clearBreakPoint(breakid) {
164 assertTrue(this.breakpoints.has(breakid));
191 const {msgid, msg} = this.createMessage( 165 const {msgid, msg} = this.createMessage(
192 "Debugger.removeBreakpoint", { breakpointId : breakid }); 166 "Debugger.removeBreakpoint", { breakpointId : breakid });
193 this.sendMessage(msg); 167 this.sendMessage(msg);
194 this.takeReplyChecked(msgid); 168 this.takeReplyChecked(msgid);
169 this.breakpoints.delete(breakid);
170 }
171
172 clearAllBreakPoints() {
173 for (let breakid of this.breakpoints) {
174 this.clearBreakPoint(breakid);
175 }
Yang 2016/11/16 14:31:59 do we want to clear the set afterwards?
jgruber 2016/11/16 15:18:21 Sounds like a good idea. Good catch :)
195 } 176 }
196 177
197 showBreakPoints(f, opt_position_alignment) { 178 showBreakPoints(f, opt_position_alignment) {
198 if (!%IsFunction(f)) throw new Error("Not passed a Function"); 179 if (!%IsFunction(f)) throw new Error("Not passed a Function");
199 180
200 const source = %FunctionGetSourceCode(f); 181 const source = %FunctionGetSourceCode(f);
201 const offset = %FunctionGetScriptSourcePosition(f); 182 const offset = %FunctionGetScriptSourcePosition(f);
202 const position_alignment = opt_position_alignment === undefined 183 const position_alignment = opt_position_alignment === undefined
203 ? this.BreakPositionAlignment.Statement : opt_position_alignment; 184 ? this.BreakPositionAlignment.Statement : opt_position_alignment;
204 const locations = %GetBreakLocations(f, position_alignment); 185 const locations = %GetBreakLocations(f, position_alignment);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (result_count == 1) { 243 if (result_count == 1) {
263 return last_result; 244 return last_result;
264 } else { 245 } else {
265 return undefined; 246 return undefined;
266 } 247 }
267 } else { 248 } else {
268 return %GetScript(func_or_script_name); 249 return %GetScript(func_or_script_name);
269 } 250 }
270 } 251 }
271 252
253 // Returns the script source. If the parameter is a function the return value
254 // is the script source for the script in which the function is defined. If th e
Yang 2016/11/16 14:31:59 80-char limit
jgruber 2016/11/16 15:18:21 Done.
255 // parameter is a string the return value is the script for which the script
256 // name has that string value.
257 scriptSource(func_or_script_name) {
258 return this.findScript(func_or_script_name).source;
259 };
260
272 sourcePosition(f) { 261 sourcePosition(f) {
273 if (!%IsFunction(f)) throw new Error("Not passed a Function"); 262 if (!%IsFunction(f)) throw new Error("Not passed a Function");
274 return %FunctionGetScriptSourcePosition(f); 263 return %FunctionGetScriptSourcePosition(f);
275 }; 264 };
276 265
266 // Returns the character position in a script based on a line number and an
267 // optional position within that line.
268 findScriptSourcePosition(script, opt_line, opt_column) {
269 var location = %ScriptLocationFromLine(script, opt_line, opt_column, 0);
270 return location ? location.position : null;
271 };
272
273 findFunctionSourceLocation(func, opt_line, opt_column) {
274 var script = %FunctionGetScript(func);
275 var script_offset = %FunctionGetScriptSourcePosition(func);
276 return %ScriptLocationFromLine(script, opt_line, opt_column, script_offset);
277 }
278
277 setBreakPointsActive(enabled) { 279 setBreakPointsActive(enabled) {
278 const {msgid, msg} = this.createMessage( 280 const {msgid, msg} = this.createMessage(
279 "Debugger.setBreakpointsActive", { active : enabled }); 281 "Debugger.setBreakpointsActive", { active : enabled });
280 this.sendMessage(msg); 282 this.sendMessage(msg);
281 this.takeReplyChecked(msgid); 283 this.takeReplyChecked(msgid);
282 } 284 }
283 285
284 get LiveEdit() { 286 get LiveEdit() {
285 return %GetLiveEditAPIObject(); 287 return %GetLiveEditAPIObject();
286 } 288 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 this.takeReplyChecked(msgid); 325 this.takeReplyChecked(msgid);
324 } 326 }
325 327
326 takeReplyChecked(msgid) { 328 takeReplyChecked(msgid) {
327 const reply = this.receivedMessages.get(msgid); 329 const reply = this.receivedMessages.get(msgid);
328 assertTrue(reply !== undefined); 330 assertTrue(reply !== undefined);
329 this.receivedMessages.delete(msgid); 331 this.receivedMessages.delete(msgid);
330 return reply; 332 return reply;
331 } 333 }
332 334
335 setBreakPointAtLocation(scriptid, loc, opt_condition) {
336 const params = { location :
337 { scriptId : scriptid.toString(),
338 lineNumber : loc.line,
339 columnNumber : loc.column,
340 },
341 condition : opt_condition,
342 };
343
344 const {msgid, msg} = this.createMessage("Debugger.setBreakpoint", params);
345 this.sendMessage(msg);
346
347 const reply = this.takeReplyChecked(msgid);
348 assertTrue(reply.result !== undefined);
349 const breakid = reply.result.breakpointId;
350 assertTrue(breakid !== undefined);
351
352 this.breakpoints.add(breakid);
353
354 return breakid;
355 }
356
333 execStatePrepareStep(action) { 357 execStatePrepareStep(action) {
334 switch(action) { 358 switch(action) {
335 case this.StepAction.StepOut: this.stepOut(); break; 359 case this.StepAction.StepOut: this.stepOut(); break;
336 case this.StepAction.StepNext: this.stepOver(); break; 360 case this.StepAction.StepNext: this.stepOver(); break;
337 case this.StepAction.StepIn: this.stepInto(); break; 361 case this.StepAction.StepIn: this.stepInto(); break;
338 default: %AbortJS("Unsupported StepAction"); break; 362 default: %AbortJS("Unsupported StepAction"); break;
339 } 363 }
340 } 364 }
341 365
342 execStateScopeType(type) { 366 execStateScopeType(type) {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 debug.instance = new DebugWrapper(); 711 debug.instance = new DebugWrapper();
688 debug.instance.enable(); 712 debug.instance.enable();
689 } 713 }
690 return debug.instance; 714 return debug.instance;
691 }}); 715 }});
692 716
693 Object.defineProperty(debug, 'ScopeType', { get: function() { 717 Object.defineProperty(debug, 'ScopeType', { get: function() {
694 const instance = debug.Debug; 718 const instance = debug.Debug;
695 return instance.ScopeType; 719 return instance.ScopeType;
696 }}); 720 }});
OLDNEW
« no previous file with comments | « test/debugger/debug/regress/regress-prepare-break-while-recompile.js ('k') | test/mjsunit/debug-sourceinfo.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698