| 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 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 return () => InspectorTest._waitForEventPromise( | 23 return () => InspectorTest._waitForEventPromise( |
| 24 `${agentName}.${eventName}`); | 24 `${agentName}.${eventName}`); |
| 25 else | 25 else |
| 26 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; | 26 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 }); | 29 }); |
| 30 } | 30 } |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 InspectorTest.log = print.bind(null); | 33 var utils = {}; |
| 34 (function setupUtils() { |
| 35 utils.load = load; |
| 36 this.load = null; |
| 37 utils.read = read; |
| 38 this.read = null; |
| 39 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; |
| 40 this.compileAndRunWithOrigin = null; |
| 41 utils.quit = quit; |
| 42 this.quit = null; |
| 43 utils.print = print; |
| 44 this.print = null; |
| 45 utils.setlocale = setlocale; |
| 46 this.setlocale = null; |
| 47 utils.setCurrentTimeMSForTest = setCurrentTimeMSForTest; |
| 48 this.setCurrentTimeMSForTest = null; |
| 49 utils.schedulePauseOnNextStatement = schedulePauseOnNextStatement; |
| 50 this.schedulePauseOnNextStatement = null; |
| 51 utils.cancelPauseOnNextStatement = cancelPauseOnNextStatement; |
| 52 this.cancelPauseOnNextStatement = null; |
| 53 utils.reconnect = reconnect; |
| 54 this.reconnect = null; |
| 55 })(); |
| 56 |
| 57 InspectorTest.log = utils.print.bind(null); |
| 34 | 58 |
| 35 InspectorTest.logMessage = function(originalMessage) | 59 InspectorTest.logMessage = function(originalMessage) |
| 36 { | 60 { |
| 37 var message = JSON.parse(JSON.stringify(originalMessage)); | 61 var message = JSON.parse(JSON.stringify(originalMessage)); |
| 38 if (message.id) | 62 if (message.id) |
| 39 message.id = "<messageId>"; | 63 message.id = "<messageId>"; |
| 40 | 64 |
| 41 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", "executionContextId", "callFrameId", "breakpointId"]); | 65 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", |
| 66 "executionContextId", "callFrameId", "breakpointId", "bindRemoteObjectFuncti
onId", "formatterObjectId" ]); |
| 42 var objects = [ message ]; | 67 var objects = [ message ]; |
| 43 while (objects.length) { | 68 while (objects.length) { |
| 44 var object = objects.shift(); | 69 var object = objects.shift(); |
| 45 for (var key in object) { | 70 for (var key in object) { |
| 46 if (nonStableFields.has(key)) | 71 if (nonStableFields.has(key)) |
| 47 object[key] = `<${key}>`; | 72 object[key] = `<${key}>`; |
| 48 else if (typeof object[key] === "object") | 73 else if (typeof object[key] === "object") |
| 49 objects.push(object[key]); | 74 objects.push(object[key]); |
| 50 } | 75 } |
| 51 } | 76 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 InspectorTest.log(`-- ${asyncStackTrace.description} (${frame.url | 172 InspectorTest.log(`-- ${asyncStackTrace.description} (${frame.url |
| 148 }:${frame.lineNumber}:${frame.columnNumber})--`); | 173 }:${frame.lineNumber}:${frame.columnNumber})--`); |
| 149 } else { | 174 } else { |
| 150 InspectorTest.log(`-- ${asyncStackTrace.description} --`); | 175 InspectorTest.log(`-- ${asyncStackTrace.description} --`); |
| 151 } | 176 } |
| 152 InspectorTest.logCallFrames(asyncStackTrace.callFrames); | 177 InspectorTest.logCallFrames(asyncStackTrace.callFrames); |
| 153 asyncStackTrace = asyncStackTrace.parent; | 178 asyncStackTrace = asyncStackTrace.parent; |
| 154 } | 179 } |
| 155 } | 180 } |
| 156 | 181 |
| 157 InspectorTest.completeTest = function() | 182 InspectorTest.completeTest = () => Protocol.Debugger.disable().then(() => utils.
quit()); |
| 158 { | |
| 159 Protocol.Debugger.disable().then(() => quit()); | |
| 160 } | |
| 161 | 183 |
| 162 InspectorTest.completeTestAfterPendingTimeouts = function() | 184 InspectorTest.completeTestAfterPendingTimeouts = function() |
| 163 { | 185 { |
| 164 InspectorTest.waitPendingTasks().then(InspectorTest.completeTest); | 186 InspectorTest.waitPendingTasks().then(InspectorTest.completeTest); |
| 165 } | 187 } |
| 166 | 188 |
| 167 InspectorTest.waitPendingTasks = function() | 189 InspectorTest.waitPendingTasks = function() |
| 168 { | 190 { |
| 169 return Protocol.Runtime.evaluate({ expression: "new Promise(r => setTimeout(r,
0))//# sourceURL=wait-pending-tasks.js", awaitPromise: true }); | 191 return Protocol.Runtime.evaluate({ expression: "new Promise(r => setTimeout(r,
0))//# sourceURL=wait-pending-tasks.js", awaitPromise: true }); |
| 170 } | 192 } |
| 171 | 193 |
| 172 InspectorTest.addScript = (string, lineOffset, columnOffset) => compileAndRunWit
hOrigin(string, "", lineOffset || 0, columnOffset || 0, false); | 194 InspectorTest.addScript = (string, lineOffset, columnOffset) => utils.compileAnd
RunWithOrigin(string, "", lineOffset || 0, columnOffset || 0, false); |
| 173 InspectorTest.addScriptWithUrl = (string, url) => compileAndRunWithOrigin(string
, url, 0, 0, false); | 195 InspectorTest.addScriptWithUrl = (string, url) => utils.compileAndRunWithOrigin(
string, url, 0, 0, false); |
| 174 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => compileAndR
unWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); | 196 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => utils.compi
leAndRunWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); |
| 175 | 197 |
| 176 InspectorTest.startDumpingProtocolMessages = function() | 198 InspectorTest.startDumpingProtocolMessages = function() |
| 177 { | 199 { |
| 178 InspectorTest._dumpInspectorProtocolMessages = true; | 200 InspectorTest._dumpInspectorProtocolMessages = true; |
| 179 } | 201 } |
| 180 | 202 |
| 181 InspectorTest.sendRawCommand = function(requestId, command, handler) | 203 InspectorTest.sendRawCommand = function(requestId, command, handler) |
| 182 { | 204 { |
| 183 if (InspectorTest._dumpInspectorProtocolMessages) | 205 if (InspectorTest._dumpInspectorProtocolMessages) |
| 184 print("frontend: " + command); | 206 utils.print("frontend: " + command); |
| 185 InspectorTest._dispatchTable.set(requestId, handler); | 207 InspectorTest._dispatchTable.set(requestId, handler); |
| 186 sendMessageToBackend(command); | 208 sendMessageToBackend(command); |
| 187 } | 209 } |
| 188 | 210 |
| 189 InspectorTest.checkExpectation = function(fail, name, messageObject) | 211 InspectorTest.checkExpectation = function(fail, name, messageObject) |
| 190 { | 212 { |
| 191 if (fail === !!messageObject.error) { | 213 if (fail === !!messageObject.error) { |
| 192 InspectorTest.log("PASS: " + name); | 214 InspectorTest.log("PASS: " + name); |
| 193 return true; | 215 return true; |
| 194 } | 216 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 function fullfillAndClearListener(fulfill, result) | 260 function fullfillAndClearListener(fulfill, result) |
| 239 { | 261 { |
| 240 delete InspectorTest._eventHandler[eventName]; | 262 delete InspectorTest._eventHandler[eventName]; |
| 241 fulfill(result); | 263 fulfill(result); |
| 242 } | 264 } |
| 243 } | 265 } |
| 244 | 266 |
| 245 InspectorTest._dispatchMessage = function(messageObject) | 267 InspectorTest._dispatchMessage = function(messageObject) |
| 246 { | 268 { |
| 247 if (InspectorTest._dumpInspectorProtocolMessages) | 269 if (InspectorTest._dumpInspectorProtocolMessages) |
| 248 print("backend: " + JSON.stringify(messageObject)); | 270 utils.print("backend: " + JSON.stringify(messageObject)); |
| 249 try { | 271 try { |
| 250 var messageId = messageObject["id"]; | 272 var messageId = messageObject["id"]; |
| 251 if (typeof messageId === "number") { | 273 if (typeof messageId === "number") { |
| 252 var handler = InspectorTest._dispatchTable.get(messageId); | 274 var handler = InspectorTest._dispatchTable.get(messageId); |
| 253 if (handler) { | 275 if (handler) { |
| 254 handler(messageObject); | 276 handler(messageObject); |
| 255 InspectorTest._dispatchTable.delete(messageId); | 277 InspectorTest._dispatchTable.delete(messageId); |
| 256 } | 278 } |
| 257 } else { | 279 } else { |
| 258 var eventName = messageObject["method"]; | 280 var eventName = messageObject["method"]; |
| 259 var eventHandler = InspectorTest._eventHandler[eventName]; | 281 var eventHandler = InspectorTest._eventHandler[eventName]; |
| 260 if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed") | 282 if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed") |
| 261 InspectorTest._scriptMap.set(messageObject.params.scriptId, JSON.parse(J
SON.stringify(messageObject.params))); | 283 InspectorTest._scriptMap.set(messageObject.params.scriptId, JSON.parse(J
SON.stringify(messageObject.params))); |
| 262 if (eventName === "Debugger.scriptParsed" && messageObject.params.url ===
"wait-pending-tasks.js") | 284 if (eventName === "Debugger.scriptParsed" && messageObject.params.url ===
"wait-pending-tasks.js") |
| 263 return; | 285 return; |
| 264 if (eventHandler) | 286 if (eventHandler) |
| 265 eventHandler(messageObject); | 287 eventHandler(messageObject); |
| 266 } | 288 } |
| 267 } catch (e) { | 289 } catch (e) { |
| 268 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 290 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
| 269 InspectorTest.completeTest(); | 291 InspectorTest.completeTest(); |
| 270 } | 292 } |
| 271 } | 293 } |
| 272 | 294 |
| 273 InspectorTest.loadScript = function(fileName) { | 295 InspectorTest.loadScript = function(fileName) { |
| 274 InspectorTest.addScript(read(fileName)); | 296 InspectorTest.addScript(utils.read(fileName)); |
| 275 } | 297 } |
| OLD | NEW |