Chromium Code Reviews| Index: test/debugger/test-api.js |
| diff --git a/test/debugger/test-api.js b/test/debugger/test-api.js |
| index ad14a306c6cb2c23796e95ab09cc36ddc888ab46..ba232ea890a602156a14b9dd1e6194b6809e2a5e 100644 |
| --- a/test/debugger/test-api.js |
| +++ b/test/debugger/test-api.js |
| @@ -33,27 +33,71 @@ class DebugWrapper { |
| this.nextMessageId = 0; |
| // The listener method called on certain events. |
| - this.listener = () => undefined; |
| + this.listener = undefined; |
| // Register as the active wrapper. |
| assertTrue(activeWrapper === undefined); |
| activeWrapper = this; |
| } |
| - enable() { |
| - const {msgid, msg} = this.createMessage("Debugger.enable"); |
| + enable() { this.sendMessageForMethodChecked("Debugger.enable"); } |
| + disable() { this.sendMessageForMethodChecked("Debugger.disable"); } |
| + |
| + setListener(listener) { this.listener = listener; } |
| + |
| + stepOver() { this.sendMessageForMethodChecked("Debugger.stepOver"); } |
| + stepInto() { this.sendMessageForMethodChecked("Debugger.stepInto"); } |
| + stepOut() { this.sendMessageForMethodChecked("Debugger.stepOut"); } |
| + |
| + // Returns the resulting breakpoint id. |
| + setBreakPoint(func, opt_line, opt_column, opt_condition) { |
| + assertTrue(%IsFunction(func)); |
| + assertFalse(%FunctionIsAPIFunction(func)); |
| + |
| + // TODO(jgruber): We handle only script breakpoints for now. |
| + // TODO(jgruber): Handle conditions. |
| + |
| + const script = %FunctionGetScript(func); |
| + assertTrue(!!script.id); |
|
Yang
2016/10/28 05:51:06
This still relies on the script wrapper object, wh
jgruber
2016/10/28 07:36:27
Done.
|
| + |
| + const offset = %FunctionGetScriptSourcePosition(func); |
| + const loc = %ScriptLocationFromLine(script, opt_line, opt_column, offset); |
| + |
| + const {msgid, msg} = this.createMessage( |
| + "Debugger.setBreakpoint", |
| + { location : { scriptId : script.id.toString() |
| + , lineNumber : loc.line |
| + , columnNumber : loc.column |
| + } |
| + }); |
| this.sendMessage(msg); |
| - assertTrue(this.receivedMessages[msgid] !== undefined); |
| + |
| + const reply = this.receivedMessages[msgid]; |
| + const breakid = reply.result.breakpointId; |
| + assertTrue(breakid !== undefined); |
| + |
| + return breakid; |
| } |
| - disable() { |
| - const {msgid, msg} = this.createMessage("Debugger.disable"); |
| + clearBreakPoint(breakid) { |
| + const {msgid, msg} = this.createMessage( |
| + "Debugger.removeBreakpoint", { breakpointId : breakid }); |
| this.sendMessage(msg); |
| assertTrue(this.receivedMessages[msgid] !== undefined); |
| } |
| - setListener(listener) { |
| - this.listener = listener; |
| + // Returns the serialized result of the given expression. For example: |
| + // {"type":"number", "value":33, "description":"33"}. |
| + evaluate(frameid, expression) { |
| + const {msgid, msg} = this.createMessage( |
| + "Debugger.evaluateOnCallFrame", |
| + { callFrameId : frameid |
| + , expression : expression |
| + }); |
| + this.sendMessage(msg); |
| + |
| + const reply = this.receivedMessages[msgid]; |
| + return reply.result.result; |
| } |
| // --- Internal methods. ----------------------------------------------------- |
| @@ -88,15 +132,31 @@ class DebugWrapper { |
| send(message); |
| } |
| + sendMessageForMethodChecked(method) { |
| + const {msgid, msg} = this.createMessage(method); |
| + this.sendMessage(msg); |
| + assertTrue(this.receivedMessages[msgid] !== undefined); |
| + } |
| + |
| // --- Message handlers. ----------------------------------------------------- |
| dispatchMessage(message) { |
| const method = message.method; |
| - if (method == "Debugger.scriptParsed") { |
| + if (method == "Debugger.paused") { |
| + this.handleDebuggerPaused(message); |
| + } else if (method == "Debugger.scriptParsed") { |
| this.handleDebuggerScriptParsed(message); |
| } |
| } |
| + handleDebuggerPaused(message) { |
| + const params = message.params; |
| + |
| + // TODO(jgruber): Arguments as needed. |
| + let execState = { frames: params.callFrames }; |
| + this.invokeListener(DebugEvent.Break, execState); |
| + } |
| + |
| handleDebuggerScriptParsed(message) { |
| const params = message.params; |
| let eventData = { scriptId : params.scriptId |
| @@ -105,6 +165,13 @@ class DebugWrapper { |
| // TODO(jgruber): Arguments as needed. Still completely missing exec_state, |
| // and eventData used to contain the script mirror instead of its id. |
| - this.listener(DebugEvent.AfterCompile, undefined, eventData, undefined); |
| + this.invokeListener(DebugEvent.AfterCompile, undefined, eventData, |
| + undefined); |
| + } |
| + |
| + invokeListener(event, exec_state, event_data, data) { |
| + if (this.listener) { |
| + this.listener(event, exec_state, event_data, data); |
| + } |
| } |
| } |