Chromium Code Reviews| 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(); | |
|
dgozman
2017/03/21 23:33:21
_commandsForLogging
kozy
2017/03/22 17:09:45
Done.
| |
| 10 | 11 |
| 11 Protocol = new Proxy({}, { | 12 Protocol = new Proxy({}, { |
| 12 get: function(target, agentName, receiver) { | 13 get: function(target, agentName, receiver) { |
| 13 return new Proxy({}, { | 14 return new Proxy({}, { |
| 14 get: function(target, methodName, receiver) { | 15 get: function(target, methodName, receiver) { |
| 15 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; | 16 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; |
| 16 var match = eventPattern.exec(methodName); | 17 var match = eventPattern.exec(methodName); |
| 17 if (!match) { | 18 if (!match) { |
| 18 return (args, contextGroupId) => InspectorTest._sendCommandPromise(`${ agentName}.${methodName}`, args || {}, contextGroupId); | 19 return (args, contextGroupId) => InspectorTest._sendCommandPromise(`${ agentName}.${methodName}`, args || {}, contextGroupId); |
| 19 } else { | 20 } else { |
| 20 var eventName = match[2]; | 21 var eventName = match[2]; |
| 21 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); | 22 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); |
| 22 if (match[1]) | 23 if (match[1]) |
| 23 return () => InspectorTest._waitForEventPromise( | 24 return () => InspectorTest._waitForEventPromise( |
| 24 `${agentName}.${eventName}`); | 25 `${agentName}.${eventName}`); |
| 25 else | 26 else |
| 26 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e ventName}`] = listener }; | 27 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e ventName}`] = listener }; |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 }); | 30 }); |
| 30 } | 31 } |
| 31 }); | 32 }); |
| 32 | 33 |
| 34 InspectorTest.dumpProtocolCommand = (command) => InspectorTest._commandToLog.add (command); | |
|
dgozman
2017/03/21 23:33:21
logProtocolCommandCalls
kozy
2017/03/22 17:09:46
Done.
| |
| 35 | |
| 33 var utils = {}; | 36 var utils = {}; |
| 34 (function setupUtils() { | 37 (function setupUtils() { |
| 35 utils.load = load; | 38 utils.load = load; |
| 36 this.load = null; | 39 this.load = null; |
| 37 utils.read = read; | 40 utils.read = read; |
| 38 this.read = null; | 41 this.read = null; |
| 39 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; | 42 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; |
| 40 this.compileAndRunWithOrigin = null; | 43 this.compileAndRunWithOrigin = null; |
| 41 utils.quit = quit; | 44 utils.quit = quit; |
| 42 this.quit = null; | 45 this.quit = null; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 } | 261 } |
| 259 InspectorTest.completeTest(); | 262 InspectorTest.completeTest(); |
| 260 } | 263 } |
| 261 | 264 |
| 262 InspectorTest._sendCommandPromise = function(method, params, contextGroupId) | 265 InspectorTest._sendCommandPromise = function(method, params, contextGroupId) |
| 263 { | 266 { |
| 264 var requestId = ++InspectorTest._requestId; | 267 var requestId = ++InspectorTest._requestId; |
| 265 var messageObject = { "id": requestId, "method": method, "params": params }; | 268 var messageObject = { "id": requestId, "method": method, "params": params }; |
| 266 var fulfillCallback; | 269 var fulfillCallback; |
| 267 var promise = new Promise(fulfill => fulfillCallback = fulfill); | 270 var promise = new Promise(fulfill => fulfillCallback = fulfill); |
| 271 if (InspectorTest._commandToLog.has(method)) { | |
| 272 utils.print(method + ' called'); | |
| 273 } | |
| 268 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill Callback, contextGroupId); | 274 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill Callback, contextGroupId); |
| 269 return promise; | 275 return promise; |
| 270 } | 276 } |
| 271 | 277 |
| 272 InspectorTest._waitForEventPromise = function(eventName) | 278 InspectorTest._waitForEventPromise = function(eventName) |
| 273 { | 279 { |
| 274 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)); |
| 275 | 281 |
| 276 function fullfillAndClearListener(fulfill, result) | 282 function fullfillAndClearListener(fulfill, result) |
| 277 { | 283 { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 304 } | 310 } |
| 305 } catch (e) { | 311 } catch (e) { |
| 306 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)); |
| 307 InspectorTest.completeTest(); | 313 InspectorTest.completeTest(); |
| 308 } | 314 } |
| 309 } | 315 } |
| 310 | 316 |
| 311 InspectorTest.loadScript = function(fileName) { | 317 InspectorTest.loadScript = function(fileName) { |
| 312 InspectorTest.addScript(utils.read(fileName)); | 318 InspectorTest.addScript(utils.read(fileName)); |
| 313 } | 319 } |
| OLD | NEW |