Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: test/debugger/test-api.js

Issue 2451153003: [debugger] Add initial skeleton for debug test wrapper (Closed)
Patch Set: Put test-api.js in strict mode Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/debugger/wrapper/enable-disable.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/debugger/test-api.js
diff --git a/test/debugger/test-api.js b/test/debugger/test-api.js
index 881e69209aa1602eea6f3aa09b0edacb2eca3830..62057d85f6c521fd23c78382afc5dc6c0f9051fd 100644
--- a/test/debugger/test-api.js
+++ b/test/debugger/test-api.js
@@ -2,4 +2,111 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TODO: add test API implementation.
+"use strict";
+
+// If true, prints all messages sent and received by inspector.
+const printProtocolMessages = false;
+
+// The active wrapper instance.
+let activeWrapper = undefined;
+
+// Receiver function called by inspector, delegating to active wrapper.
+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.
+ this.receivedMessages = {};
+
+ // Each message dispatched by the Debug wrapper is assigned a unique number
+ // using nextMessageId.
+ this.nextMessageId = 0;
+
+ // The listener method called on certain events.
+ this.listener = () => undefined;
+
+ // Register as the active wrapper.
+ assertTrue(activeWrapper === undefined);
+ activeWrapper = this;
+ }
+
+ enable() {
+ const {msgid, msg} = this.createMessage("Debugger.enable");
+ this.sendMessage(msg);
+ assertTrue(this.receivedMessages[msgid] !== undefined);
+ }
+
+ disable() {
+ const {msgid, msg} = this.createMessage("Debugger.disable");
+ this.sendMessage(msg);
+ assertTrue(this.receivedMessages[msgid] !== undefined);
+ }
+
+ setListener(listener) {
+ this.listener = listener;
+ }
+
+ // --- Internal methods. -----------------------------------------------------
+
+ getNextMessageId() {
+ return this.nextMessageId++;
+ }
+
+ createMessage(method, params) {
+ const id = this.getNextMessageId();
+ const msg = JSON.stringify({
+ id: id,
+ method: method,
+ params: params,
+ });
+ return {msgid: id, msg: msg};
+ }
+
+ receiveMessage(message) {
+ if (printProtocolMessages) print(message);
+
+ const parsedMessage = JSON.parse(message);
+ if (parsedMessage.id !== undefined) {
+ this.receivedMessages[parsedMessage.id] = parsedMessage;
+ }
+
+ this.dispatchMessage(parsedMessage);
+ }
+
+ sendMessage(message) {
+ if (printProtocolMessages) print(message);
+ send(message);
+ }
+
+ // --- Message handlers. -----------------------------------------------------
+
+ dispatchMessage(message) {
+ const method = message.method;
+ if (method == "Debugger.scriptParsed") {
+ this.handleDebuggerScriptParsed(message);
+ }
+ }
+
+ handleDebuggerScriptParsed(message) {
+ const params = message.params;
+ let eventData = { scriptId : params.scriptId
+ , eventType : 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);
+ }
+}
« no previous file with comments | « no previous file | test/debugger/wrapper/enable-disable.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698