OLD | NEW |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 Local: 1, | 52 Local: 1, |
53 With: 2, | 53 With: 2, |
54 Closure: 3, | 54 Closure: 3, |
55 Catch: 4, | 55 Catch: 4, |
56 Block: 5, | 56 Block: 5, |
57 Script: 6, | 57 Script: 6, |
58 Eval: 7, | 58 Eval: 7, |
59 Module: 8 | 59 Module: 8 |
60 }; | 60 }; |
61 | 61 |
| 62 // Types of exceptions that can be broken upon. |
| 63 this.ExceptionBreak = { Caught : 0, |
| 64 Uncaught: 1 }; |
| 65 |
62 // Store the current script id so we can skip corresponding break events. | 66 // Store the current script id so we can skip corresponding break events. |
63 this.thisScriptId = %FunctionGetScriptId(receive); | 67 this.thisScriptId = %FunctionGetScriptId(receive); |
64 | 68 |
65 // Register as the active wrapper. | 69 // Register as the active wrapper. |
66 assertTrue(activeWrapper === undefined); | 70 assertTrue(activeWrapper === undefined); |
67 activeWrapper = this; | 71 activeWrapper = this; |
68 } | 72 } |
69 | 73 |
70 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } | 74 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } |
71 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } | 75 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } |
72 | 76 |
73 setListener(listener) { this.listener = listener; } | 77 setListener(listener) { this.listener = listener; } |
74 | 78 |
75 stepOver() { this.sendMessageForMethodChecked("Debugger.stepOver"); } | 79 stepOver() { this.sendMessageForMethodChecked("Debugger.stepOver"); } |
76 stepInto() { this.sendMessageForMethodChecked("Debugger.stepInto"); } | 80 stepInto() { this.sendMessageForMethodChecked("Debugger.stepInto"); } |
77 stepOut() { this.sendMessageForMethodChecked("Debugger.stepOut"); } | 81 stepOut() { this.sendMessageForMethodChecked("Debugger.stepOut"); } |
78 | 82 |
| 83 setBreakOnException() { |
| 84 this.sendMessageForMethodChecked( |
| 85 "Debugger.setPauseOnExceptions", { state : "all" }); |
| 86 } |
| 87 |
| 88 clearBreakOnException() { |
| 89 const newState = this.isBreakOnUncaughtException() ? "uncaught" : "none"; |
| 90 this.sendMessageForMethodChecked( |
| 91 "Debugger.setPauseOnExceptions", { state : newState }); |
| 92 } |
| 93 |
| 94 isBreakOnException() { |
| 95 return !!%IsBreakOnException(this.ExceptionBreak.Caught); |
| 96 }; |
| 97 |
| 98 setBreakOnUncaughtException() { |
| 99 const newState = this.isBreakOnException() ? "all" : "uncaught"; |
| 100 this.sendMessageForMethodChecked( |
| 101 "Debugger.setPauseOnExceptions", { state : newState }); |
| 102 } |
| 103 |
| 104 clearBreakOnUncaughtException() { |
| 105 const newState = this.isBreakOnException() ? "all" : "none"; |
| 106 this.sendMessageForMethodChecked( |
| 107 "Debugger.setPauseOnExceptions", { state : newState }); |
| 108 } |
| 109 |
| 110 isBreakOnUncaughtException() { |
| 111 return !!%IsBreakOnException(this.ExceptionBreak.Uncaught); |
| 112 }; |
| 113 |
| 114 clearStepping() { %ClearStepping(); }; |
| 115 |
79 // Returns the resulting breakpoint id. | 116 // Returns the resulting breakpoint id. |
80 setBreakPoint(func, opt_line, opt_column, opt_condition) { | 117 setBreakPoint(func, opt_line, opt_column, opt_condition) { |
81 assertTrue(%IsFunction(func)); | 118 assertTrue(%IsFunction(func)); |
82 assertFalse(%FunctionIsAPIFunction(func)); | 119 assertFalse(%FunctionIsAPIFunction(func)); |
83 | 120 |
84 // TODO(jgruber): We handle only script breakpoints for now. | 121 // TODO(jgruber): We handle only script breakpoints for now. |
85 // TODO(jgruber): Handle conditions. | 122 // TODO(jgruber): Handle conditions. |
86 | 123 |
87 const scriptid = %FunctionGetScriptId(func); | 124 const scriptid = %FunctionGetScriptId(func); |
88 assertTrue(scriptid != -1); | 125 assertTrue(scriptid != -1); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 191 } |
155 | 192 |
156 this.dispatchMessage(parsedMessage); | 193 this.dispatchMessage(parsedMessage); |
157 } | 194 } |
158 | 195 |
159 sendMessage(message) { | 196 sendMessage(message) { |
160 if (printProtocolMessages) print(message); | 197 if (printProtocolMessages) print(message); |
161 send(message); | 198 send(message); |
162 } | 199 } |
163 | 200 |
164 sendMessageForMethodChecked(method) { | 201 sendMessageForMethodChecked(method, params) { |
165 const {msgid, msg} = this.createMessage(method); | 202 const {msgid, msg} = this.createMessage(method, params); |
166 this.sendMessage(msg); | 203 this.sendMessage(msg); |
167 this.takeReplyChecked(msgid); | 204 this.takeReplyChecked(msgid); |
168 } | 205 } |
169 | 206 |
170 takeReplyChecked(msgid) { | 207 takeReplyChecked(msgid) { |
171 const reply = this.receivedMessages.get(msgid); | 208 const reply = this.receivedMessages.get(msgid); |
172 assertTrue(reply !== undefined); | 209 assertTrue(reply !== undefined); |
173 this.receivedMessages.delete(msgid); | 210 this.receivedMessages.delete(msgid); |
174 return reply; | 211 return reply; |
175 } | 212 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 291 |
255 // Simulate the debug object generated by --expose-debug-as debug. | 292 // Simulate the debug object generated by --expose-debug-as debug. |
256 var debug = { instance : undefined }; | 293 var debug = { instance : undefined }; |
257 Object.defineProperty(debug, 'Debug', { get: function() { | 294 Object.defineProperty(debug, 'Debug', { get: function() { |
258 if (!debug.instance) { | 295 if (!debug.instance) { |
259 debug.instance = new DebugWrapper(); | 296 debug.instance = new DebugWrapper(); |
260 debug.instance.enable(); | 297 debug.instance.enable(); |
261 } | 298 } |
262 return debug.instance; | 299 return debug.instance; |
263 }}); | 300 }}); |
OLD | NEW |