OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... | |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.SDKModel} | 33 * @extends {WebInspector.SDKModel} |
34 * @param {!WebInspector.Target} target | 34 * @param {!WebInspector.Target} target |
35 */ | 35 */ |
36 WebInspector.ConsoleModel = function(target) | 36 WebInspector.ConsoleModel = function(target) |
37 { | 37 { |
38 WebInspector.SDKModel.call(this, WebInspector.ConsoleModel, target); | 38 WebInspector.SDKModel.call(this, WebInspector.ConsoleModel, target); |
39 | 39 |
40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ | 40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ |
41 this._messages = []; | 41 this._messages = []; |
42 this.warnings = 0; | 42 /** @type {!Map<number, !WebInspector.ConsoleMessage>} */ |
43 this.errors = 0; | 43 this._messageBySequenceNumber = new Map(); |
44 this._warnings = 0; | |
45 this._errors = 0; | |
46 this._revokedErrors = 0; | |
44 this._consoleAgent = target.consoleAgent(); | 47 this._consoleAgent = target.consoleAgent(); |
45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); | 48 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); |
46 this._enableAgent(); | 49 this._enableAgent(); |
47 } | 50 } |
48 | 51 |
49 WebInspector.ConsoleModel.Events = { | 52 WebInspector.ConsoleModel.Events = { |
50 ConsoleCleared: "ConsoleCleared", | 53 ConsoleCleared: "ConsoleCleared", |
51 MessageAdded: "MessageAdded", | 54 MessageAdded: "MessageAdded", |
52 CommandEvaluated: "CommandEvaluated", | 55 CommandEvaluated: "CommandEvaluated", |
53 } | 56 } |
(...skipping 11 matching lines...) Expand all Loading... | |
65 delete this._enablingConsole; | 68 delete this._enablingConsole; |
66 } | 69 } |
67 this._consoleAgent.enable(callback.bind(this)); | 70 this._consoleAgent.enable(callback.bind(this)); |
68 }, | 71 }, |
69 | 72 |
70 /** | 73 /** |
71 * @param {!WebInspector.ConsoleMessage} msg | 74 * @param {!WebInspector.ConsoleMessage} msg |
72 */ | 75 */ |
73 addMessage: function(msg) | 76 addMessage: function(msg) |
74 { | 77 { |
75 msg.index = this._messages.length; | |
76 this._messages.push(msg); | 78 this._messages.push(msg); |
79 this._messageBySequenceNumber.set(msg.sequenceNumber, msg); | |
80 if (msg._relatedSequenceNumber) { | |
81 var relatedMessage = this._messageBySequenceNumber.get(msg._relatedS equenceNumber); | |
82 if (relatedMessage) | |
83 msg.setRelatedMessage(relatedMessage); | |
84 } | |
85 if (msg.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError && msg.relatedMessage()) | |
dgozman
2015/04/21 09:16:36
Move this to |_incrementErrorWarningCount|.
pfeldman
2015/04/21 12:15:27
Handled it separately.
| |
86 this._errors--; | |
77 this._incrementErrorWarningCount(msg); | 87 this._incrementErrorWarningCount(msg); |
78 | |
79 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg); | 88 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg); |
80 }, | 89 }, |
81 | 90 |
82 /** | 91 /** |
83 * @param {!WebInspector.ConsoleMessage} msg | 92 * @param {!WebInspector.ConsoleMessage} msg |
84 */ | 93 */ |
85 _incrementErrorWarningCount: function(msg) | 94 _incrementErrorWarningCount: function(msg) |
86 { | 95 { |
87 switch (msg.level) { | 96 switch (msg.level) { |
88 case WebInspector.ConsoleMessage.MessageLevel.Warning: | 97 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
89 this.warnings++; | 98 this._warnings++; |
90 break; | 99 break; |
91 case WebInspector.ConsoleMessage.MessageLevel.Error: | 100 case WebInspector.ConsoleMessage.MessageLevel.Error: |
92 this.errors++; | 101 this._errors++; |
102 break; | |
103 case WebInspector.ConsoleMessage.MessageLevel.RevokedError: | |
104 this._revokedErrors++; | |
93 break; | 105 break; |
94 } | 106 } |
95 }, | 107 }, |
96 | 108 |
97 /** | 109 /** |
98 * @return {!Array.<!WebInspector.ConsoleMessage>} | 110 * @return {!Array.<!WebInspector.ConsoleMessage>} |
99 */ | 111 */ |
100 messages: function() | 112 messages: function() |
101 { | 113 { |
102 return this._messages; | 114 return this._messages; |
103 }, | 115 }, |
104 | 116 |
105 requestClearMessages: function() | 117 requestClearMessages: function() |
106 { | 118 { |
107 this._consoleAgent.clearMessages(); | 119 this._consoleAgent.clearMessages(); |
108 this._messagesCleared(); | 120 this._messagesCleared(); |
109 }, | 121 }, |
110 | 122 |
111 _messagesCleared: function() | 123 _messagesCleared: function() |
112 { | 124 { |
113 this._messages = []; | 125 this._messages = []; |
114 this.errors = 0; | 126 this._messageBySequenceNumber.clear(); |
115 this.warnings = 0; | 127 this._errors = 0; |
128 this._revokedErrors = 0; | |
129 this._warnings = 0; | |
116 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared); | 130 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared); |
117 }, | 131 }, |
118 | 132 |
133 /** | |
134 * @return {number} | |
135 */ | |
136 errors: function() | |
137 { | |
138 return this._errors; | |
139 }, | |
140 | |
141 /** | |
142 * @return {number} | |
143 */ | |
144 revokedErrors: function() | |
145 { | |
146 return this._revokedErrors; | |
147 }, | |
148 | |
149 /** | |
150 * @return {number} | |
151 */ | |
152 warnings: function() | |
153 { | |
154 return this._warnings; | |
155 }, | |
156 | |
119 __proto__: WebInspector.SDKModel.prototype | 157 __proto__: WebInspector.SDKModel.prototype |
120 } | 158 } |
121 | 159 |
122 /** | 160 /** |
123 * @param {!WebInspector.ExecutionContext} executionContext | 161 * @param {!WebInspector.ExecutionContext} executionContext |
124 * @param {string} text | 162 * @param {string} text |
125 * @param {boolean=} useCommandLineAPI | 163 * @param {boolean=} useCommandLineAPI |
126 */ | 164 */ |
127 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext, text, useCommandLineAPI) | 165 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext, text, useCommandLineAPI) |
128 { | 166 { |
129 useCommandLineAPI = !!useCommandLineAPI; | 167 useCommandLineAPI = !!useCommandLineAPI; |
130 var target = executionContext.target(); | 168 var target = executionContext.target(); |
131 | 169 |
132 var commandMessage = new WebInspector.ConsoleMessage(target, WebInspector.Co nsoleMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageTy pe.Command); | 170 var commandMessage = new WebInspector.ConsoleMessage(target, 0, WebInspector .ConsoleMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.Messag eType.Command); |
133 commandMessage.setExecutionContextId(executionContext.id); | 171 commandMessage.setExecutionContextId(executionContext.id); |
134 target.consoleModel.addMessage(commandMessage); | 172 target.consoleModel.addMessage(commandMessage); |
135 | 173 |
136 /** | 174 /** |
137 * @param {?WebInspector.RemoteObject} result | 175 * @param {?WebInspector.RemoteObject} result |
138 * @param {boolean} wasThrown | 176 * @param {boolean} wasThrown |
139 * @param {?RuntimeAgent.RemoteObject=} valueResult | 177 * @param {?RuntimeAgent.RemoteObject=} valueResult |
140 * @param {?DebuggerAgent.ExceptionDetails=} exceptionDetails | 178 * @param {?DebuggerAgent.ExceptionDetails=} exceptionDetails |
141 */ | 179 */ |
142 function printResult(result, wasThrown, valueResult, exceptionDetails) | 180 function printResult(result, wasThrown, valueResult, exceptionDetails) |
(...skipping 10 matching lines...) Expand all Loading... | |
153 | 191 |
154 executionContext.evaluate(text, "console", useCommandLineAPI, false, false, true, printResult); | 192 executionContext.evaluate(text, "console", useCommandLineAPI, false, false, true, printResult); |
155 | 193 |
156 WebInspector.userMetrics.ConsoleEvaluated.record(); | 194 WebInspector.userMetrics.ConsoleEvaluated.record(); |
157 } | 195 } |
158 | 196 |
159 | 197 |
160 /** | 198 /** |
161 * @constructor | 199 * @constructor |
162 * @param {?WebInspector.Target} target | 200 * @param {?WebInspector.Target} target |
201 * @param {number} sequenceNumber | |
163 * @param {string} source | 202 * @param {string} source |
164 * @param {?string} level | 203 * @param {?string} level |
165 * @param {string} messageText | 204 * @param {string} messageText |
166 * @param {string=} type | 205 * @param {string=} type |
167 * @param {?string=} url | 206 * @param {?string=} url |
168 * @param {number=} line | 207 * @param {number=} line |
169 * @param {number=} column | 208 * @param {number=} column |
170 * @param {!NetworkAgent.RequestId=} requestId | 209 * @param {!NetworkAgent.RequestId=} requestId |
171 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters | 210 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters |
172 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace | 211 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace |
173 * @param {number=} timestamp | 212 * @param {number=} timestamp |
174 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId | 213 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId |
175 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace | 214 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace |
176 * @param {?string=} scriptId | 215 * @param {?string=} scriptId |
216 * @param {number=} relatedSequenceNumber | |
177 */ | 217 */ |
178 WebInspector.ConsoleMessage = function(target, source, level, messageText, type, url, line, column, requestId, parameters, stackTrace, timestamp, executionConte xtId, asyncStackTrace, scriptId) | 218 WebInspector.ConsoleMessage = function(target, sequenceNumber, source, level, me ssageText, type, url, line, column, requestId, parameters, stackTrace, timestamp , executionContextId, asyncStackTrace, scriptId, relatedSequenceNumber) |
179 { | 219 { |
180 this._target = target; | 220 this._target = target; |
221 this.sequenceNumber = sequenceNumber; | |
181 this.source = source; | 222 this.source = source; |
182 this.level = level; | 223 this.level = level; |
183 this.messageText = messageText; | 224 this.messageText = messageText; |
184 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; | 225 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; |
185 /** @type {string|undefined} */ | 226 /** @type {string|undefined} */ |
186 this.url = url || undefined; | 227 this.url = url || undefined; |
187 /** @type {number} */ | 228 /** @type {number} */ |
188 this.line = line || 0; | 229 this.line = line || 0; |
189 /** @type {number} */ | 230 /** @type {number} */ |
190 this.column = column || 0; | 231 this.column = column || 0; |
191 this.parameters = parameters; | 232 this.parameters = parameters; |
192 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */ | 233 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */ |
193 this.stackTrace = stackTrace; | 234 this.stackTrace = stackTrace; |
194 this.timestamp = timestamp || Date.now(); | 235 this.timestamp = timestamp || Date.now(); |
195 this.executionContextId = executionContextId || 0; | 236 this.executionContextId = executionContextId || 0; |
196 this.asyncStackTrace = asyncStackTrace; | 237 this.asyncStackTrace = asyncStackTrace; |
197 this.scriptId = scriptId || null; | 238 this.scriptId = scriptId || null; |
239 this._relatedSequenceNumber = relatedSequenceNumber || 0; | |
198 | 240 |
199 this.request = requestId ? target.networkLog.requestForId(requestId) : null; | 241 this.request = requestId ? target.networkLog.requestForId(requestId) : null; |
200 | 242 |
201 if (this.request) { | 243 if (this.request) { |
202 var initiator = this.request.initiator(); | 244 var initiator = this.request.initiator(); |
203 if (initiator) { | 245 if (initiator) { |
204 this.stackTrace = initiator.stackTrace || undefined; | 246 this.stackTrace = initiator.stackTrace || undefined; |
205 this.asyncStackTrace = initiator.asyncStackTrace; | 247 this.asyncStackTrace = initiator.asyncStackTrace; |
206 if (initiator.url) { | 248 if (initiator.url) { |
207 this.url = initiator.url; | 249 this.url = initiator.url; |
208 this.line = initiator.lineNumber || 0; | 250 this.line = initiator.lineNumber || 0; |
209 } | 251 } |
210 } | 252 } |
211 } | 253 } |
212 } | 254 } |
213 | 255 |
214 WebInspector.ConsoleMessage.prototype = { | 256 WebInspector.ConsoleMessage.prototype = { |
215 /** | 257 /** |
216 * @return {?WebInspector.Target} | 258 * @return {?WebInspector.Target} |
217 */ | 259 */ |
218 target: function() | 260 target: function() |
219 { | 261 { |
220 return this._target; | 262 return this._target; |
221 }, | 263 }, |
222 | 264 |
223 /** | 265 /** |
224 * @param {!WebInspector.ConsoleMessage} originatingMessage | 266 * @param {!WebInspector.ConsoleMessage} relatedMessage |
225 */ | 267 */ |
226 setOriginatingMessage: function(originatingMessage) | 268 setRelatedMessage: function(relatedMessage) |
227 { | 269 { |
228 this._originatingConsoleMessage = originatingMessage; | 270 this._relatedMessage = relatedMessage; |
229 this.executionContextId = originatingMessage.executionContextId; | |
230 }, | 271 }, |
231 | 272 |
232 /** | 273 /** |
233 * @param {!RuntimeAgent.ExecutionContextId} executionContextId | 274 * @param {!RuntimeAgent.ExecutionContextId} executionContextId |
234 */ | 275 */ |
235 setExecutionContextId: function(executionContextId) | 276 setExecutionContextId: function(executionContextId) |
236 { | 277 { |
237 this.executionContextId = executionContextId; | 278 this.executionContextId = executionContextId; |
238 }, | 279 }, |
239 | 280 |
240 /** | 281 /** |
241 * @return {?WebInspector.ConsoleMessage} | 282 * @return {?WebInspector.ConsoleMessage} |
242 */ | 283 */ |
243 originatingMessage: function() | 284 relatedMessage: function() |
244 { | 285 { |
245 return this._originatingConsoleMessage; | 286 return this._relatedMessage; |
246 }, | 287 }, |
247 | 288 |
248 /** | 289 /** |
249 * @return {boolean} | 290 * @return {boolean} |
250 */ | 291 */ |
251 isGroupMessage: function() | 292 isGroupMessage: function() |
252 { | 293 { |
253 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup || | 294 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup || |
254 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupColl apsed || | 295 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupColl apsed || |
255 this.type === WebInspector.ConsoleMessage.MessageType.EndGroup; | 296 this.type === WebInspector.ConsoleMessage.MessageType.EndGroup; |
(...skipping 10 matching lines...) Expand all Loading... | |
266 | 307 |
267 /** | 308 /** |
268 * @return {boolean} | 309 * @return {boolean} |
269 */ | 310 */ |
270 isErrorOrWarning: function() | 311 isErrorOrWarning: function() |
271 { | 312 { |
272 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error); | 313 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error); |
273 }, | 314 }, |
274 | 315 |
275 /** | 316 /** |
276 * @return {!WebInspector.ConsoleMessage} | |
277 */ | |
278 clone: function() | |
279 { | |
280 return new WebInspector.ConsoleMessage( | |
281 this.target(), | |
282 this.source, | |
283 this.level, | |
284 this.messageText, | |
285 this.type, | |
286 this.url, | |
287 this.line, | |
288 this.column, | |
289 this.request ? this.request.requestId : undefined, | |
290 this.parameters, | |
291 this.stackTrace, | |
292 this.timestamp, | |
293 this.executionContextId, | |
294 this.asyncStackTrace, | |
295 this.scriptId); | |
296 }, | |
297 | |
298 /** | |
299 * @param {?WebInspector.ConsoleMessage} msg | 317 * @param {?WebInspector.ConsoleMessage} msg |
300 * @return {boolean} | 318 * @return {boolean} |
301 */ | 319 */ |
302 isEqual: function(msg) | 320 isEqual: function(msg) |
303 { | 321 { |
304 if (!msg) | 322 if (!msg) |
305 return false; | 323 return false; |
306 | 324 |
325 if (this._relatedSequenceNumber || msg._relatedSequenceNumber) | |
326 return false; | |
327 | |
307 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) | 328 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) |
308 return false; | 329 return false; |
309 | 330 |
310 var asyncTrace1 = this.asyncStackTrace; | 331 var asyncTrace1 = this.asyncStackTrace; |
311 var asyncTrace2 = msg.asyncStackTrace; | 332 var asyncTrace2 = msg.asyncStackTrace; |
312 while (asyncTrace1 || asyncTrace2) { | 333 while (asyncTrace1 || asyncTrace2) { |
313 if (!asyncTrace1 || !asyncTrace2) | 334 if (!asyncTrace1 || !asyncTrace2) |
314 return false; | 335 return false; |
315 if (asyncTrace1.description !== asyncTrace2.description) | 336 if (asyncTrace1.description !== asyncTrace2.description) |
316 return false; | 337 return false; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 425 } |
405 | 426 |
406 /** | 427 /** |
407 * @enum {string} | 428 * @enum {string} |
408 */ | 429 */ |
409 WebInspector.ConsoleMessage.MessageLevel = { | 430 WebInspector.ConsoleMessage.MessageLevel = { |
410 Log: "log", | 431 Log: "log", |
411 Info: "info", | 432 Info: "info", |
412 Warning: "warning", | 433 Warning: "warning", |
413 Error: "error", | 434 Error: "error", |
414 Debug: "debug" | 435 Debug: "debug", |
436 RevokedError: "revokedError" | |
415 }; | 437 }; |
416 | 438 |
417 /** | 439 /** |
418 * @param {!WebInspector.ConsoleMessage} a | 440 * @param {!WebInspector.ConsoleMessage} a |
419 * @param {!WebInspector.ConsoleMessage} b | 441 * @param {!WebInspector.ConsoleMessage} b |
420 * @return {number} | 442 * @return {number} |
421 */ | 443 */ |
422 WebInspector.ConsoleMessage.timestampComparator = function (a, b) | 444 WebInspector.ConsoleMessage.timestampComparator = function (a, b) |
423 { | 445 { |
424 return a.timestamp - b.timestamp; | 446 return a.timestamp - b.timestamp; |
(...skipping 11 matching lines...) Expand all Loading... | |
436 | 458 |
437 WebInspector.ConsoleDispatcher.prototype = { | 459 WebInspector.ConsoleDispatcher.prototype = { |
438 /** | 460 /** |
439 * @override | 461 * @override |
440 * @param {!ConsoleAgent.ConsoleMessage} payload | 462 * @param {!ConsoleAgent.ConsoleMessage} payload |
441 */ | 463 */ |
442 messageAdded: function(payload) | 464 messageAdded: function(payload) |
443 { | 465 { |
444 var consoleMessage = new WebInspector.ConsoleMessage( | 466 var consoleMessage = new WebInspector.ConsoleMessage( |
445 this._console.target(), | 467 this._console.target(), |
468 payload.sequenceNumber, | |
446 payload.source, | 469 payload.source, |
447 payload.level, | 470 payload.level, |
448 payload.text, | 471 payload.text, |
449 payload.type, | 472 payload.type, |
450 payload.url, | 473 payload.url, |
451 payload.line, | 474 payload.line, |
452 payload.column, | 475 payload.column, |
453 payload.networkRequestId, | 476 payload.networkRequestId, |
454 payload.parameters, | 477 payload.parameters, |
455 payload.stackTrace, | 478 payload.stackTrace, |
456 payload.timestamp * 1000, // Convert to ms. | 479 payload.timestamp * 1000, // Convert to ms. |
457 payload.executionContextId, | 480 payload.executionContextId, |
458 payload.asyncStackTrace, | 481 payload.asyncStackTrace, |
459 payload.scriptId); | 482 payload.scriptId, |
483 payload.relatedSequenceNumber); | |
460 this._console.addMessage(consoleMessage); | 484 this._console.addMessage(consoleMessage); |
461 }, | 485 }, |
462 | 486 |
463 /** | 487 /** |
464 * @override | 488 * @override |
465 * @param {number} count | 489 * @param {number} count |
466 */ | 490 */ |
467 messageRepeatCountUpdated: function(count) | 491 messageRepeatCountUpdated: function(count) |
468 { | 492 { |
469 }, | 493 }, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); | 572 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); |
549 }, | 573 }, |
550 | 574 |
551 __proto__: WebInspector.Object.prototype | 575 __proto__: WebInspector.Object.prototype |
552 } | 576 } |
553 | 577 |
554 /** | 578 /** |
555 * @type {!WebInspector.MultitargetConsoleModel} | 579 * @type {!WebInspector.MultitargetConsoleModel} |
556 */ | 580 */ |
557 WebInspector.multitargetConsoleModel; | 581 WebInspector.multitargetConsoleModel; |
OLD | NEW |