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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 }; | 112 }; |
113 | 113 |
114 clearStepping() { %ClearStepping(); }; | 114 clearStepping() { %ClearStepping(); }; |
115 | 115 |
116 // Returns the resulting breakpoint id. | 116 // Returns the resulting breakpoint id. |
117 setBreakPoint(func, opt_line, opt_column, opt_condition) { | 117 setBreakPoint(func, opt_line, opt_column, opt_condition) { |
118 assertTrue(%IsFunction(func)); | 118 assertTrue(%IsFunction(func)); |
119 assertFalse(%FunctionIsAPIFunction(func)); | 119 assertFalse(%FunctionIsAPIFunction(func)); |
120 | 120 |
121 // TODO(jgruber): We handle only script breakpoints for now. | 121 // TODO(jgruber): We handle only script breakpoints for now. |
122 // TODO(jgruber): Handle conditions. | |
123 | 122 |
124 const scriptid = %FunctionGetScriptId(func); | 123 const scriptid = %FunctionGetScriptId(func); |
125 assertTrue(scriptid != -1); | 124 assertTrue(scriptid != -1); |
126 | 125 |
127 const offset = %FunctionGetScriptSourcePosition(func); | 126 const offset = %FunctionGetScriptSourcePosition(func); |
128 const loc = | 127 const loc = |
129 %ScriptLocationFromLine2(scriptid, opt_line, opt_column, offset); | 128 %ScriptLocationFromLine2(scriptid, opt_line, opt_column, offset); |
130 | 129 |
| 130 const params = { location : |
| 131 { scriptId : scriptid.toString(), |
| 132 lineNumber : loc.line, |
| 133 columnNumber : loc.column, |
| 134 }}; |
| 135 if (!!opt_condition) { |
| 136 params.condition = opt_condition; |
| 137 } |
| 138 |
131 const {msgid, msg} = this.createMessage( | 139 const {msgid, msg} = this.createMessage( |
132 "Debugger.setBreakpoint", | 140 "Debugger.setBreakpoint", params); |
133 { location : { scriptId : scriptid.toString(), | |
134 lineNumber : loc.line, | |
135 columnNumber : loc.column | |
136 } | |
137 }); | |
138 this.sendMessage(msg); | 141 this.sendMessage(msg); |
139 | 142 |
140 const reply = this.takeReplyChecked(msgid); | 143 const reply = this.takeReplyChecked(msgid); |
141 assertTrue(reply.result !== undefined); | 144 assertTrue(reply.result !== undefined); |
142 const breakid = reply.result.breakpointId; | 145 const breakid = reply.result.breakpointId; |
143 assertTrue(breakid !== undefined); | 146 assertTrue(breakid !== undefined); |
144 | 147 |
145 return breakid; | 148 return breakid; |
146 } | 149 } |
147 | 150 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 case "block": return this.ScopeType.Block; | 233 case "block": return this.ScopeType.Block; |
231 case "script": return this.ScopeType.Script; | 234 case "script": return this.ScopeType.Script; |
232 default: %AbortJS("Unexpected scope type"); | 235 default: %AbortJS("Unexpected scope type"); |
233 } | 236 } |
234 } | 237 } |
235 | 238 |
236 // Returns an array of property descriptors of the scope object. | 239 // Returns an array of property descriptors of the scope object. |
237 // This is in contrast to the original API, which simply passed object | 240 // This is in contrast to the original API, which simply passed object |
238 // mirrors. | 241 // mirrors. |
239 execStateScopeObject(obj) { | 242 execStateScopeObject(obj) { |
240 const {msgid, msg} = this.createMessage( | 243 const serialized_scope = this.getProperties(obj.objectId); |
241 "Runtime.getProperties", { objectId : obj.objectId }); | 244 const scope = {} |
242 this.sendMessage(msg); | 245 const scope_tuples = serialized_scope.forEach((elem) => { |
243 const reply = this.takeReplyChecked(msgid); | 246 const key = elem.name; |
244 return { value : () => reply.result.result }; | 247 |
| 248 let value; |
| 249 if (elem.value) { |
| 250 // Some properties (e.g. with getters/setters) don't have a value. |
| 251 switch (elem.value.type) { |
| 252 case "undefined": value = undefined; break; |
| 253 default: value = elem.value.value; break; |
| 254 } |
| 255 } |
| 256 |
| 257 scope[key] = value; |
| 258 }) |
| 259 |
| 260 return { value : () => scope }; |
245 } | 261 } |
246 | 262 |
247 execStateScope(scope) { | 263 execStateScope(scope) { |
248 return { scopeType : () => this.execStateScopeType(scope.type), | 264 return { scopeType : () => this.execStateScopeType(scope.type), |
249 scopeObject : () => this.execStateScopeObject(scope.object) | 265 scopeObject : () => this.execStateScopeObject(scope.object) |
250 }; | 266 }; |
251 } | 267 } |
252 | 268 |
| 269 getProperties(objectId) { |
| 270 const {msgid, msg} = this.createMessage( |
| 271 "Runtime.getProperties", { objectId : objectId }); |
| 272 this.sendMessage(msg); |
| 273 const reply = this.takeReplyChecked(msgid); |
| 274 return reply.result.result; |
| 275 } |
| 276 |
| 277 getLocalScopeDetails(frame) { |
| 278 const scopes = frame.scopeChain; |
| 279 for (let i = 0; i < scopes.length; i++) { |
| 280 const scope = scopes[i] |
| 281 if (scope.type == "local") { |
| 282 return this.getProperties(scope.object.objectId); |
| 283 } |
| 284 } |
| 285 |
| 286 return undefined; |
| 287 } |
| 288 |
| 289 execStateFrameLocalCount(frame) { |
| 290 const scope_details = this.getLocalScopeDetails(frame); |
| 291 return scope_details ? scope_details.length : 0; |
| 292 } |
| 293 |
| 294 execStateFrameLocalName(frame, index) { |
| 295 const scope_details = this.getLocalScopeDetails(frame); |
| 296 if (index < 0 || index >= scope_details.length) return undefined; |
| 297 return scope_details[index].name; |
| 298 } |
| 299 |
| 300 execStateFrameLocalValue(frame, index) { |
| 301 const scope_details = this.getLocalScopeDetails(frame); |
| 302 if (index < 0 || index >= scope_details.length) return undefined; |
| 303 |
| 304 const local = scope_details[index]; |
| 305 |
| 306 let localValue; |
| 307 switch (local.value.type) { |
| 308 case "undefined": localValue = undefined; break; |
| 309 default: localValue = local.value.value; break; |
| 310 } |
| 311 |
| 312 return { value : () => localValue }; |
| 313 } |
| 314 |
| 315 execStateFrameEvaluate(frame, expr) { |
| 316 const frameid = frame.callFrameId; |
| 317 const {msgid, msg} = this.createMessage( |
| 318 "Debugger.evaluateOnCallFrame", |
| 319 { callFrameId : frameid, |
| 320 expression : expr |
| 321 }); |
| 322 this.sendMessage(msg); |
| 323 const reply = this.takeReplyChecked(msgid); |
| 324 |
| 325 const result = reply.result.result; |
| 326 if (result.subtype == "error") { |
| 327 throw new Error(result.description); |
| 328 } |
| 329 |
| 330 return { value : () => result.value }; |
| 331 } |
| 332 |
253 execStateFrame(frame) { | 333 execStateFrame(frame) { |
254 const scriptid = parseInt(frame.location.scriptId); | 334 const scriptid = parseInt(frame.location.scriptId); |
255 const line = frame.location.lineNumber; | 335 const line = frame.location.lineNumber; |
256 const column = frame.location.columnNumber; | 336 const column = frame.location.columnNumber; |
257 const loc = %ScriptLocationFromLine2(scriptid, line, column, 0); | 337 const loc = %ScriptLocationFromLine2(scriptid, line, column, 0); |
258 const func = { name : () => frame.functionName }; | 338 const func = { name : () => frame.functionName }; |
259 return { sourceLineText : () => loc.sourceText, | 339 return { sourceLineText : () => loc.sourceText, |
| 340 evaluate : (expr) => this.execStateFrameEvaluate(frame, expr), |
260 functionName : () => frame.functionName, | 341 functionName : () => frame.functionName, |
261 func : () => func, | 342 func : () => func, |
| 343 localCount : () => this.execStateFrameLocalCount(frame), |
| 344 localName : (ix) => this.execStateFrameLocalName(frame, ix), |
| 345 localValue: (ix) => this.execStateFrameLocalValue(frame, ix), |
262 scopeCount : () => frame.scopeChain.length, | 346 scopeCount : () => frame.scopeChain.length, |
263 scope : (index) => this.execStateScope(frame.scopeChain[index]), | 347 scope : (index) => this.execStateScope(frame.scopeChain[index]), |
264 allScopes : () => frame.scopeChain.map( | 348 allScopes : () => frame.scopeChain.map( |
265 this.execStateScope.bind(this)) | 349 this.execStateScope.bind(this)) |
266 }; | 350 }; |
267 } | 351 } |
268 | 352 |
269 // --- Message handlers. ----------------------------------------------------- | 353 // --- Message handlers. ----------------------------------------------------- |
270 | 354 |
271 dispatchMessage(message) { | 355 dispatchMessage(message) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 debug.instance = new DebugWrapper(); | 423 debug.instance = new DebugWrapper(); |
340 debug.instance.enable(); | 424 debug.instance.enable(); |
341 } | 425 } |
342 return debug.instance; | 426 return debug.instance; |
343 }}); | 427 }}); |
344 | 428 |
345 Object.defineProperty(debug, 'ScopeType', { get: function() { | 429 Object.defineProperty(debug, 'ScopeType', { get: function() { |
346 const instance = debug.Debug; | 430 const instance = debug.Debug; |
347 return instance.ScopeType; | 431 return instance.ScopeType; |
348 }}); | 432 }}); |
OLD | NEW |