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

Side by Side 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, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/debugger/wrapper/enable-disable.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO: add test API implementation. 5 "use strict";
6
7 // If true, prints all messages sent and received by inspector.
8 const printProtocolMessages = false;
9
10 // The active wrapper instance.
11 let activeWrapper = undefined;
12
13 // Receiver function called by inspector, delegating to active wrapper.
14 function receive(message) {
15 activeWrapper.receiveMessage(message);
16 }
17
18 // TODO(jgruber): Determine which of these are still required and possible.
19 // Debug events which can occur in the V8 JavaScript engine.
20 const DebugEvent = { Break: 1,
21 Exception: 2,
22 NewFunction: 3,
23 BeforeCompile: 4,
24 AfterCompile: 5,
25 CompileError: 6,
26 AsyncTaskEvent: 7 };
27
28 class DebugWrapper {
29 constructor() {
30 // Message dictionary storing {id, message} pairs.
31 this.receivedMessages = {};
32
33 // Each message dispatched by the Debug wrapper is assigned a unique number
34 // using nextMessageId.
35 this.nextMessageId = 0;
36
37 // The listener method called on certain events.
38 this.listener = () => undefined;
39
40 // Register as the active wrapper.
41 assertTrue(activeWrapper === undefined);
42 activeWrapper = this;
43 }
44
45 enable() {
46 const {msgid, msg} = this.createMessage("Debugger.enable");
47 this.sendMessage(msg);
48 assertTrue(this.receivedMessages[msgid] !== undefined);
49 }
50
51 disable() {
52 const {msgid, msg} = this.createMessage("Debugger.disable");
53 this.sendMessage(msg);
54 assertTrue(this.receivedMessages[msgid] !== undefined);
55 }
56
57 setListener(listener) {
58 this.listener = listener;
59 }
60
61 // --- Internal methods. -----------------------------------------------------
62
63 getNextMessageId() {
64 return this.nextMessageId++;
65 }
66
67 createMessage(method, params) {
68 const id = this.getNextMessageId();
69 const msg = JSON.stringify({
70 id: id,
71 method: method,
72 params: params,
73 });
74 return {msgid: id, msg: msg};
75 }
76
77 receiveMessage(message) {
78 if (printProtocolMessages) print(message);
79
80 const parsedMessage = JSON.parse(message);
81 if (parsedMessage.id !== undefined) {
82 this.receivedMessages[parsedMessage.id] = parsedMessage;
83 }
84
85 this.dispatchMessage(parsedMessage);
86 }
87
88 sendMessage(message) {
89 if (printProtocolMessages) print(message);
90 send(message);
91 }
92
93 // --- Message handlers. -----------------------------------------------------
94
95 dispatchMessage(message) {
96 const method = message.method;
97 if (method == "Debugger.scriptParsed") {
98 this.handleDebuggerScriptParsed(message);
99 }
100 }
101
102 handleDebuggerScriptParsed(message) {
103 const params = message.params;
104 let eventData = { scriptId : params.scriptId
105 , eventType : DebugEvent.AfterCompile
106 }
107
108 // TODO(jgruber): Arguments as needed. Still completely missing exec_state,
109 // and eventData used to contain the script mirror instead of its id.
110 this.listener(DebugEvent.AfterCompile, undefined, eventData, undefined);
111 }
112 }
OLDNEW
« 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