| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 this.ExceptionBreak = { Caught : 0, | 63 this.ExceptionBreak = { Caught : 0, |
| 64 Uncaught: 1 }; | 64 Uncaught: 1 }; |
| 65 | 65 |
| 66 // The different types of breakpoint position alignments. | 66 // The different types of breakpoint position alignments. |
| 67 // Must match BreakPositionAlignment in debug.h. | 67 // Must match BreakPositionAlignment in debug.h. |
| 68 this.BreakPositionAlignment = { | 68 this.BreakPositionAlignment = { |
| 69 Statement: 0, | 69 Statement: 0, |
| 70 BreakPosition: 1 | 70 BreakPosition: 1 |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // The different script break point types. |
| 74 this.ScriptBreakPointType = { ScriptId: 0, |
| 75 ScriptName: 1, |
| 76 ScriptRegExp: 2 }; |
| 77 |
| 73 // Store the current script id so we can skip corresponding break events. | 78 // Store the current script id so we can skip corresponding break events. |
| 74 this.thisScriptId = %FunctionGetScriptId(receive); | 79 this.thisScriptId = %FunctionGetScriptId(receive); |
| 75 | 80 |
| 76 // Register as the active wrapper. | 81 // Register as the active wrapper. |
| 77 assertTrue(activeWrapper === undefined); | 82 assertTrue(activeWrapper === undefined); |
| 78 activeWrapper = this; | 83 activeWrapper = this; |
| 79 } | 84 } |
| 80 | 85 |
| 81 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } | 86 enable() { this.sendMessageForMethodChecked("Debugger.enable"); } |
| 82 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } | 87 disable() { this.sendMessageForMethodChecked("Debugger.disable"); } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 139 |
| 135 const params = { location : | 140 const params = { location : |
| 136 { scriptId : scriptid.toString(), | 141 { scriptId : scriptid.toString(), |
| 137 lineNumber : loc.line, | 142 lineNumber : loc.line, |
| 138 columnNumber : loc.column, | 143 columnNumber : loc.column, |
| 139 }}; | 144 }}; |
| 140 if (!!opt_condition) { | 145 if (!!opt_condition) { |
| 141 params.condition = opt_condition; | 146 params.condition = opt_condition; |
| 142 } | 147 } |
| 143 | 148 |
| 144 const {msgid, msg} = this.createMessage( | 149 const {msgid, msg} = this.createMessage("Debugger.setBreakpoint", params); |
| 145 "Debugger.setBreakpoint", params); | |
| 146 this.sendMessage(msg); | 150 this.sendMessage(msg); |
| 147 | 151 |
| 148 const reply = this.takeReplyChecked(msgid); | 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 } |
| 159 |
| 160 setScriptBreakPoint(type, scriptid, opt_line, opt_column, opt_condition) { |
| 161 // Only sets by script id are supported for now. |
| 162 assertEquals(this.ScriptBreakPointType.ScriptId, type); |
| 163 return this.setScriptBreakPointById(scriptid, opt_line, opt_column, |
| 164 opt_condition); |
| 165 } |
| 166 |
| 167 setScriptBreakPointById(scriptid, opt_line, opt_column, opt_condition) { |
| 168 const loc = %ScriptLocationFromLine2(scriptid, opt_line, opt_column, 0); |
| 169 |
| 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); |
| 149 assertTrue(reply.result !== undefined); | 183 assertTrue(reply.result !== undefined); |
| 150 const breakid = reply.result.breakpointId; | 184 const breakid = reply.result.breakpointId; |
| 151 assertTrue(breakid !== undefined); | 185 assertTrue(breakid !== undefined); |
| 152 | 186 |
| 153 return breakid; | 187 return breakid; |
| 154 } | 188 } |
| 155 | 189 |
| 156 clearBreakPoint(breakid) { | 190 clearBreakPoint(breakid) { |
| 157 const {msgid, msg} = this.createMessage( | 191 const {msgid, msg} = this.createMessage( |
| 158 "Debugger.removeBreakpoint", { breakpointId : breakid }); | 192 "Debugger.removeBreakpoint", { breakpointId : breakid }); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return %FunctionGetScriptSourcePosition(f); | 274 return %FunctionGetScriptSourcePosition(f); |
| 241 }; | 275 }; |
| 242 | 276 |
| 243 setBreakPointsActive(enabled) { | 277 setBreakPointsActive(enabled) { |
| 244 const {msgid, msg} = this.createMessage( | 278 const {msgid, msg} = this.createMessage( |
| 245 "Debugger.setBreakpointsActive", { active : enabled }); | 279 "Debugger.setBreakpointsActive", { active : enabled }); |
| 246 this.sendMessage(msg); | 280 this.sendMessage(msg); |
| 247 this.takeReplyChecked(msgid); | 281 this.takeReplyChecked(msgid); |
| 248 } | 282 } |
| 249 | 283 |
| 284 get LiveEdit() { |
| 285 const debugContext = %GetDebugContext(); |
| 286 return debugContext.Debug.LiveEdit; |
| 287 } |
| 288 |
| 250 // --- Internal methods. ----------------------------------------------------- | 289 // --- Internal methods. ----------------------------------------------------- |
| 251 | 290 |
| 252 getNextMessageId() { | 291 getNextMessageId() { |
| 253 return this.nextMessageId++; | 292 return this.nextMessageId++; |
| 254 } | 293 } |
| 255 | 294 |
| 256 createMessage(method, params) { | 295 createMessage(method, params) { |
| 257 const id = this.getNextMessageId(); | 296 const id = this.getNextMessageId(); |
| 258 const msg = JSON.stringify({ | 297 const msg = JSON.stringify({ |
| 259 id: id, | 298 id: id, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 for (let i = 0; i < props.length; i++) { | 495 for (let i = 0; i < props.length; i++) { |
| 457 array[i] = props[i]; | 496 array[i] = props[i]; |
| 458 } | 497 } |
| 459 value = array; | 498 value = array; |
| 460 } | 499 } |
| 461 } | 500 } |
| 462 | 501 |
| 463 return { value : () => value, | 502 return { value : () => value, |
| 464 isUndefined : () => obj.type == "undefined" | 503 isUndefined : () => obj.type == "undefined" |
| 465 }; | 504 }; |
| 466 | |
| 467 } | 505 } |
| 468 | 506 |
| 469 evaluateOnCallFrame(frame, expr) { | 507 evaluateOnCallFrame(frame, expr) { |
| 470 const frameid = frame.callFrameId; | 508 const frameid = frame.callFrameId; |
| 471 const {msgid, msg} = this.createMessage( | 509 const {msgid, msg} = this.createMessage( |
| 472 "Debugger.evaluateOnCallFrame", | 510 "Debugger.evaluateOnCallFrame", |
| 473 { callFrameId : frameid, | 511 { callFrameId : frameid, |
| 474 expression : expr | 512 expression : expr |
| 475 }); | 513 }); |
| 476 this.sendMessage(msg); | 514 this.sendMessage(msg); |
| 477 const reply = this.takeReplyChecked(msgid); | 515 const reply = this.takeReplyChecked(msgid); |
| 478 | 516 |
| 479 const result = reply.result.result; | 517 const result = reply.result.result; |
| 480 return this.reconstructRemoteObject(result); | 518 return this.reconstructRemoteObject(result); |
| 481 } | 519 } |
| 482 | 520 |
| 521 execStateFrameRestart(frame) { |
| 522 const frameid = frame.callFrameId; |
| 523 const {msgid, msg} = this.createMessage( |
| 524 "Debugger.restartFrame", { callFrameId : frameid }); |
| 525 this.sendMessage(msg); |
| 526 this.takeReplyChecked(msgid); |
| 527 } |
| 528 |
| 483 execStateFrame(frame) { | 529 execStateFrame(frame) { |
| 484 const scriptid = parseInt(frame.location.scriptId); | 530 const scriptid = parseInt(frame.location.scriptId); |
| 485 const line = frame.location.lineNumber; | 531 const line = frame.location.lineNumber; |
| 486 const column = frame.location.columnNumber; | 532 const column = frame.location.columnNumber; |
| 487 const loc = %ScriptLocationFromLine2(scriptid, line, column, 0); | 533 const loc = %ScriptLocationFromLine2(scriptid, line, column, 0); |
| 488 const func = { name : () => frame.functionName }; | 534 const func = { name : () => frame.functionName }; |
| 489 | 535 |
| 490 function allScopes() { | 536 function allScopes() { |
| 491 const scopes = []; | 537 const scopes = []; |
| 492 for (let i = 0; i < frame.scopeChain.length; i++) { | 538 for (let i = 0; i < frame.scopeChain.length; i++) { |
| 493 scopes.push(this.execStateScope(frame, i)); | 539 scopes.push(this.execStateScope(frame, i)); |
| 494 } | 540 } |
| 495 return scopes; | 541 return scopes; |
| 496 }; | 542 }; |
| 497 | 543 |
| 498 return { sourceColumn : () => loc.column, | 544 return { sourceColumn : () => loc.column, |
| 499 sourceLine : () => loc.line + 1, | 545 sourceLine : () => loc.line + 1, |
| 500 sourceLineText : () => loc.sourceText, | 546 sourceLineText : () => loc.sourceText, |
| 501 evaluate : (expr) => this.evaluateOnCallFrame(frame, expr), | 547 evaluate : (expr) => this.evaluateOnCallFrame(frame, expr), |
| 502 functionName : () => frame.functionName, | 548 functionName : () => frame.functionName, |
| 503 func : () => func, | 549 func : () => func, |
| 504 localCount : () => this.execStateFrameLocalCount(frame), | 550 localCount : () => this.execStateFrameLocalCount(frame), |
| 505 localName : (ix) => this.execStateFrameLocalName(frame, ix), | 551 localName : (ix) => this.execStateFrameLocalName(frame, ix), |
| 506 localValue: (ix) => this.execStateFrameLocalValue(frame, ix), | 552 localValue: (ix) => this.execStateFrameLocalValue(frame, ix), |
| 553 restart : () => this.execStateFrameRestart(frame), |
| 507 scopeCount : () => frame.scopeChain.length, | 554 scopeCount : () => frame.scopeChain.length, |
| 508 scope : (index) => this.execStateScope(frame, index), | 555 scope : (index) => this.execStateScope(frame, index), |
| 509 allScopes : allScopes.bind(this) | 556 allScopes : allScopes.bind(this) |
| 510 }; | 557 }; |
| 511 } | 558 } |
| 512 | 559 |
| 513 eventDataException(params) { | 560 eventDataException(params) { |
| 514 switch (params.data.type) { | 561 switch (params.data.type) { |
| 515 case "string": { | 562 case "string": { |
| 516 return params.data.value; | 563 return params.data.value; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 debug.instance = new DebugWrapper(); | 688 debug.instance = new DebugWrapper(); |
| 642 debug.instance.enable(); | 689 debug.instance.enable(); |
| 643 } | 690 } |
| 644 return debug.instance; | 691 return debug.instance; |
| 645 }}); | 692 }}); |
| 646 | 693 |
| 647 Object.defineProperty(debug, 'ScopeType', { get: function() { | 694 Object.defineProperty(debug, 'ScopeType', { get: function() { |
| 648 const instance = debug.Debug; | 695 const instance = debug.Debug; |
| 649 return instance.ScopeType; | 696 return instance.ScopeType; |
| 650 }}); | 697 }}); |
| OLD | NEW |