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 13 matching lines...) Expand all Loading... |
24 else | 24 else |
25 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; | 25 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; |
26 } | 26 } |
27 } | 27 } |
28 }); | 28 }); |
29 } | 29 } |
30 }); | 30 }); |
31 | 31 |
32 InspectorTest.log = print.bind(null); | 32 InspectorTest.log = print.bind(null); |
33 | 33 |
34 InspectorTest.logMessage = function(message) | 34 InspectorTest.logMessage = function(originalMessage) |
35 { | 35 { |
| 36 var message = JSON.parse(JSON.stringify(originalMessage)); |
36 if (message.id) | 37 if (message.id) |
37 message.id = "<messageId>"; | 38 message.id = "<messageId>"; |
38 | 39 |
39 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", "executionContextId", "callFrameId"]); | 40 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", "executionContextId", "callFrameId", "breakpointId"]); |
40 var objects = [ message ]; | 41 var objects = [ message ]; |
41 while (objects.length) { | 42 while (objects.length) { |
42 var object = objects.shift(); | 43 var object = objects.shift(); |
43 for (var key in object) { | 44 for (var key in object) { |
44 if (nonStableFields.has(key)) | 45 if (nonStableFields.has(key)) |
45 object[key] = `<${key}>`; | 46 object[key] = `<${key}>`; |
46 else if (typeof object[key] === "object") | 47 else if (typeof object[key] === "object") |
47 objects.push(object[key]); | 48 objects.push(object[key]); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 InspectorTest.logObject(message); | 52 InspectorTest.logObject(message); |
52 return message; | 53 return originalMessage; |
53 } | 54 } |
54 | 55 |
55 InspectorTest.logObject = function(object, title) | 56 InspectorTest.logObject = function(object, title) |
56 { | 57 { |
57 var lines = []; | 58 var lines = []; |
58 | 59 |
59 function dumpValue(value, prefix, prefixWithName) | 60 function dumpValue(value, prefix, prefixWithName) |
60 { | 61 { |
61 if (typeof value === "object" && value !== null) { | 62 if (typeof value === "object" && value !== null) { |
62 if (value instanceof Array) | 63 if (value instanceof Array) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 Protocol.Debugger.disable().then(() => quit()); | 106 Protocol.Debugger.disable().then(() => quit()); |
106 } | 107 } |
107 | 108 |
108 InspectorTest.completeTestAfterPendingTimeouts = function() | 109 InspectorTest.completeTestAfterPendingTimeouts = function() |
109 { | 110 { |
110 Protocol.Runtime.evaluate({ | 111 Protocol.Runtime.evaluate({ |
111 expression: "new Promise(resolve => setTimeout(resolve, 0))", | 112 expression: "new Promise(resolve => setTimeout(resolve, 0))", |
112 awaitPromise: true }).then(InspectorTest.completeTest); | 113 awaitPromise: true }).then(InspectorTest.completeTest); |
113 } | 114 } |
114 | 115 |
115 InspectorTest.addScript = function(string) | 116 InspectorTest.addScript = (string) => compileAndRunWithOrigin(string, "", 0, 0); |
116 { | |
117 return InspectorTest._sendCommandPromise("Runtime.evaluate", { "expression": s
tring }).then(dumpErrorIfNeeded); | |
118 | |
119 function dumpErrorIfNeeded(message) | |
120 { | |
121 if (message.error) { | |
122 InspectorTest.log("Error while executing '" + string + "': " + message.err
or.message); | |
123 InspectorTest.completeTest(); | |
124 } | |
125 } | |
126 }; | |
127 | 117 |
128 InspectorTest.startDumpingProtocolMessages = function() | 118 InspectorTest.startDumpingProtocolMessages = function() |
129 { | 119 { |
130 InspectorTest._dumpInspectorProtocolMessages = true; | 120 InspectorTest._dumpInspectorProtocolMessages = true; |
131 } | 121 } |
132 | 122 |
133 InspectorTest.sendRawCommand = function(requestId, command, handler) | 123 InspectorTest.sendRawCommand = function(requestId, command, handler) |
134 { | 124 { |
135 if (InspectorTest._dumpInspectorProtocolMessages) | 125 if (InspectorTest._dumpInspectorProtocolMessages) |
136 print("frontend: " + command); | 126 print("frontend: " + command); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 var eventName = messageObject["method"]; | 194 var eventName = messageObject["method"]; |
205 var eventHandler = InspectorTest._eventHandler[eventName]; | 195 var eventHandler = InspectorTest._eventHandler[eventName]; |
206 if (eventHandler) | 196 if (eventHandler) |
207 eventHandler(messageObject); | 197 eventHandler(messageObject); |
208 } | 198 } |
209 } catch (e) { | 199 } catch (e) { |
210 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 200 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
211 InspectorTest.completeTest(); | 201 InspectorTest.completeTest(); |
212 } | 202 } |
213 } | 203 } |
OLD | NEW |