Index: test/debugger/test-api.js |
diff --git a/test/debugger/test-api.js b/test/debugger/test-api.js |
index 62057d85f6c521fd23c78382afc5dc6c0f9051fd..f9d22afd87cce1e1a60322743a0cac5a1fe9be35 100644 |
--- a/test/debugger/test-api.js |
+++ b/test/debugger/test-api.js |
@@ -15,16 +15,6 @@ function receive(message) { |
activeWrapper.receiveMessage(message); |
} |
-// TODO(jgruber): Determine which of these are still required and possible. |
-// Debug events which can occur in the V8 JavaScript engine. |
-const DebugEvent = { Break: 1, |
- Exception: 2, |
- NewFunction: 3, |
- BeforeCompile: 4, |
- AfterCompile: 5, |
- CompileError: 6, |
- AsyncTaskEvent: 7 }; |
- |
class DebugWrapper { |
constructor() { |
// Message dictionary storing {id, message} pairs. |
@@ -35,27 +25,83 @@ class DebugWrapper { |
this.nextMessageId = 0; |
// The listener method called on certain events. |
- this.listener = () => undefined; |
+ this.listener = undefined; |
+ |
+ // TODO(jgruber): Determine which of these are still required and possible. |
+ // Debug events which can occur in the V8 JavaScript engine. |
+ this.DebugEvent = { Break: 1 |
+ , Exception: 2 |
+ , NewFunction: 3 |
+ , BeforeCompile: 4 |
+ , AfterCompile: 5 |
+ , CompileError: 6 |
+ , AsyncTaskEvent: 7 |
+ }; |
// 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 scriptid = %FunctionGetScriptId(func); |
+ assertTrue(scriptid != -1); |
+ |
+ const offset = %FunctionGetScriptSourcePosition(func); |
+ const loc = |
+ %ScriptLocationFromLine2(scriptid, opt_line, opt_column, offset); |
+ |
+ const {msgid, msg} = this.createMessage( |
+ "Debugger.setBreakpoint", |
+ { location : { scriptId : scriptid.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. ----------------------------------------------------- |
@@ -90,23 +136,46 @@ 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(this.DebugEvent.Break, execState); |
+ } |
+ |
handleDebuggerScriptParsed(message) { |
const params = message.params; |
let eventData = { scriptId : params.scriptId |
- , eventType : DebugEvent.AfterCompile |
+ , eventType : this.DebugEvent.AfterCompile |
} |
// 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(this.DebugEvent.AfterCompile, undefined, eventData, |
+ undefined); |
+ } |
+ |
+ invokeListener(event, exec_state, event_data, data) { |
+ if (this.listener) { |
+ this.listener(event, exec_state, event_data, data); |
+ } |
} |
} |