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 InspectorTest = {}; | 5 InspectorTest = {}; |
6 InspectorTest._dispatchTable = new Map(); | 6 InspectorTest._dispatchTable = new Map(); |
7 InspectorTest._requestId = 0; | 7 InspectorTest._requestId = 0; |
8 InspectorTest._dumpInspectorProtocolMessages = false; | 8 InspectorTest._dumpInspectorProtocolMessages = false; |
9 InspectorTest._eventHandler = {}; | 9 InspectorTest._eventHandler = {}; |
10 InspectorTest._commandToLog = new Set(); | 10 InspectorTest._commandsForLogging = new Set(); |
11 | 11 |
12 Protocol = new Proxy({}, { | 12 Protocol = new Proxy({}, { |
13 get: function(target, agentName, receiver) { | 13 get: function(target, agentName, receiver) { |
14 return new Proxy({}, { | 14 return new Proxy({}, { |
15 get: function(target, methodName, receiver) { | 15 get: function(target, methodName, receiver) { |
16 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; | 16 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; |
17 var match = eventPattern.exec(methodName); | 17 var match = eventPattern.exec(methodName); |
18 if (!match) { | 18 if (!match) { |
19 return (args, contextGroupId) => InspectorTest._sendCommandPromise(`${
agentName}.${methodName}`, args || {}, contextGroupId); | 19 return (args, contextGroupId) => InspectorTest._sendCommandPromise(`${
agentName}.${methodName}`, args || {}, contextGroupId); |
20 } else { | 20 } else { |
21 var eventName = match[2]; | 21 var eventName = match[2]; |
22 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); | 22 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); |
23 if (match[1]) | 23 if (match[1]) |
24 return () => InspectorTest._waitForEventPromise( | 24 return () => InspectorTest._waitForEventPromise( |
25 `${agentName}.${eventName}`); | 25 `${agentName}.${eventName}`); |
26 else | 26 else |
27 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; | 27 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; |
28 } | 28 } |
29 } | 29 } |
30 }); | 30 }); |
31 } | 31 } |
32 }); | 32 }); |
33 | 33 |
34 InspectorTest.dumpProtocolCommand = (command) => InspectorTest._commandToLog.add
(command); | 34 InspectorTest.logProtocolCommandCalls = (command) => InspectorTest._commandsForL
ogging.add(command); |
35 | 35 |
36 var utils = {}; | 36 var utils = {}; |
37 (function setupUtils() { | 37 (function setupUtils() { |
38 utils.load = load; | 38 utils.load = load; |
39 this.load = null; | 39 this.load = null; |
40 utils.read = read; | 40 utils.read = read; |
41 this.read = null; | 41 this.read = null; |
42 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; | 42 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; |
43 this.compileAndRunWithOrigin = null; | 43 this.compileAndRunWithOrigin = null; |
44 utils.quit = quit; | 44 utils.quit = quit; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 261 } |
262 InspectorTest.completeTest(); | 262 InspectorTest.completeTest(); |
263 } | 263 } |
264 | 264 |
265 InspectorTest._sendCommandPromise = function(method, params, contextGroupId) | 265 InspectorTest._sendCommandPromise = function(method, params, contextGroupId) |
266 { | 266 { |
267 var requestId = ++InspectorTest._requestId; | 267 var requestId = ++InspectorTest._requestId; |
268 var messageObject = { "id": requestId, "method": method, "params": params }; | 268 var messageObject = { "id": requestId, "method": method, "params": params }; |
269 var fulfillCallback; | 269 var fulfillCallback; |
270 var promise = new Promise(fulfill => fulfillCallback = fulfill); | 270 var promise = new Promise(fulfill => fulfillCallback = fulfill); |
271 if (InspectorTest._commandToLog.has(method)) { | 271 if (InspectorTest._commandsForLogging.has(method)) { |
272 utils.print(method + ' called'); | 272 utils.print(method + ' called'); |
273 } | 273 } |
274 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill
Callback, contextGroupId); | 274 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill
Callback, contextGroupId); |
275 return promise; | 275 return promise; |
276 } | 276 } |
277 | 277 |
278 InspectorTest._waitForEventPromise = function(eventName) | 278 InspectorTest._waitForEventPromise = function(eventName) |
279 { | 279 { |
280 return new Promise(fulfill => InspectorTest._eventHandler[eventName] = fullfil
lAndClearListener.bind(null, fulfill)); | 280 return new Promise(fulfill => InspectorTest._eventHandler[eventName] = fullfil
lAndClearListener.bind(null, fulfill)); |
281 | 281 |
(...skipping 28 matching lines...) Expand all Loading... |
310 } | 310 } |
311 } catch (e) { | 311 } catch (e) { |
312 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 312 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
313 InspectorTest.completeTest(); | 313 InspectorTest.completeTest(); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 InspectorTest.loadScript = function(fileName) { | 317 InspectorTest.loadScript = function(fileName) { |
318 InspectorTest.addScript(utils.read(fileName)); | 318 InspectorTest.addScript(utils.read(fileName)); |
319 } | 319 } |
OLD | NEW |