Chromium Code Reviews| 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.Object} | 33 * @extends {WebInspector.Object} |
| 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 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ | 38 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ |
| 39 this.messages = []; | 39 this.messages = []; |
| 40 this.warnings = 0; | 40 this.warnings = 0; |
| 41 this.errors = 0; | 41 this.errors = 0; |
| 42 this._interruptRepeatCount = false; | |
| 43 this._target = target; | 42 this._target = target; |
| 44 this._consoleAgent = target.consoleAgent(); | 43 this._consoleAgent = target.consoleAgent(); |
| 45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); | 44 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); |
| 46 } | 45 } |
| 47 | 46 |
| 48 WebInspector.ConsoleModel.Events = { | 47 WebInspector.ConsoleModel.Events = { |
| 49 ConsoleCleared: "console-cleared", | 48 ConsoleCleared: "console-cleared", |
| 50 MessageAdded: "console-message-added", | 49 MessageAdded: "console-message-added", |
| 51 RepeatCountUpdated: "repeat-count-updated" | 50 RepeatCountUpdated: "repeat-count-updated" |
| 52 } | 51 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 86 |
| 88 /** | 87 /** |
| 89 * @param {!WebInspector.ConsoleMessage} msg | 88 * @param {!WebInspector.ConsoleMessage} msg |
| 90 * @param {boolean=} isFromBackend | 89 * @param {boolean=} isFromBackend |
| 91 */ | 90 */ |
| 92 addMessage: function(msg, isFromBackend) | 91 addMessage: function(msg, isFromBackend) |
| 93 { | 92 { |
| 94 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms g.request)) | 93 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms g.request)) |
| 95 return; | 94 return; |
| 96 | 95 |
| 97 msg.index = this.messages.length; | 96 var interruptRepeatCount = !isFromBackend || WebInspector.settings.conso leTimestampsEnabled.get(); |
| 98 this.messages.push(msg); | |
| 99 this._incrementErrorWarningCount(msg); | |
| 100 | 97 |
| 101 if (isFromBackend) | 98 /** |
| 99 * @param {?WebInspector.ConsoleMessage} msg | |
| 100 * @return {boolean} | |
| 101 */ | |
| 102 function isGroupMessage(msg) | |
| 103 { | |
| 104 return !!msg && ((msg.type === WebInspector.ConsoleMessage.MessageTy pe.StartGroup) | |
| 105 || (msg.type === WebInspector.ConsoleMessage.MessageType.StartGr oupCollapsed) | |
| 106 || (msg.type === WebInspector.ConsoleMessage.MessageType.EndGrou p)); | |
| 107 } | |
| 108 | |
| 109 if (!interruptRepeatCount && !isGroupMessage(this._previousMessage) && m sg.isEqual(this._previousMessage)) { | |
| 110 this._previousMessage.timestamp = msg.timestamp; | |
| 111 this._previousMessage.repeatCount++; | |
|
apavlov
2014/03/21 09:30:46
For things other than loop counters we tend to use
| |
| 112 this._incrementErrorWarningCount(this._previousMessage); | |
| 113 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Repea tCountUpdated, this._previousMessage); | |
| 114 } else { | |
| 115 msg.index = this.messages.length; | |
| 116 this.messages.push(msg); | |
| 117 this._incrementErrorWarningCount(msg); | |
| 102 this._previousMessage = msg; | 118 this._previousMessage = msg; |
| 103 | 119 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Messa geAdded, msg); |
| 104 this._interruptRepeatCount = !isFromBackend; | 120 } |
| 105 | |
| 106 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg); | |
| 107 }, | 121 }, |
| 108 | 122 |
| 109 /** | 123 /** |
| 110 * @param {string} text | 124 * @param {string} text |
| 111 * @param {?string} newPromptText | 125 * @param {?string} newPromptText |
| 112 * @param {boolean} useCommandLineAPI | 126 * @param {boolean} useCommandLineAPI |
| 113 */ | 127 */ |
| 114 evaluateCommand: function(text, newPromptText, useCommandLineAPI) | 128 evaluateCommand: function(text, newPromptText, useCommandLineAPI) |
| 115 { | 129 { |
| 116 if (!this._uiDelegate) | 130 if (!this._uiDelegate) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 this.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true); | 192 this.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true); |
| 179 }, | 193 }, |
| 180 | 194 |
| 181 /** | 195 /** |
| 182 * @param {!WebInspector.ConsoleMessage} msg | 196 * @param {!WebInspector.ConsoleMessage} msg |
| 183 */ | 197 */ |
| 184 _incrementErrorWarningCount: function(msg) | 198 _incrementErrorWarningCount: function(msg) |
| 185 { | 199 { |
| 186 switch (msg.level) { | 200 switch (msg.level) { |
| 187 case WebInspector.ConsoleMessage.MessageLevel.Warning: | 201 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
| 188 this.warnings += msg.repeatDelta; | 202 this.warnings++; |
|
apavlov
2014/03/21 09:30:46
ditto
| |
| 189 break; | 203 break; |
| 190 case WebInspector.ConsoleMessage.MessageLevel.Error: | 204 case WebInspector.ConsoleMessage.MessageLevel.Error: |
| 191 this.errors += msg.repeatDelta; | 205 this.errors++; |
|
apavlov
2014/03/21 09:30:46
ditto
| |
| 192 break; | 206 break; |
| 193 } | 207 } |
| 194 }, | 208 }, |
| 195 | 209 |
| 196 requestClearMessages: function() | 210 requestClearMessages: function() |
| 197 { | 211 { |
| 198 this._consoleAgent.clearMessages(); | 212 this._consoleAgent.clearMessages(); |
| 199 this.clearMessages(); | 213 this.clearMessages(); |
| 200 }, | 214 }, |
| 201 | 215 |
| 202 clearMessages: function() | 216 clearMessages: function() |
| 203 { | 217 { |
| 204 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared); | 218 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared); |
| 205 | 219 |
| 206 this.messages = []; | 220 this.messages = []; |
| 207 delete this._previousMessage; | 221 delete this._previousMessage; |
| 208 | 222 |
| 209 this.errors = 0; | 223 this.errors = 0; |
| 210 this.warnings = 0; | 224 this.warnings = 0; |
| 211 }, | 225 }, |
| 212 | 226 |
| 213 /** | |
| 214 * @param {number} count | |
| 215 */ | |
| 216 _messageRepeatCountUpdated: function(count) | |
| 217 { | |
| 218 var msg = this._previousMessage; | |
| 219 if (!msg) | |
| 220 return; | |
| 221 | |
| 222 var prevRepeatCount = msg.totalRepeatCount; | |
| 223 | |
| 224 if (!this._interruptRepeatCount) { | |
| 225 msg.repeatDelta = count - prevRepeatCount; | |
| 226 msg.repeatCount = msg.repeatCount + msg.repeatDelta; | |
| 227 msg.totalRepeatCount = count; | |
| 228 | |
| 229 this._incrementErrorWarningCount(msg); | |
| 230 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Repea tCountUpdated, msg); | |
| 231 } else { | |
| 232 var msgCopy = msg.clone(); | |
| 233 msgCopy.totalRepeatCount = count; | |
| 234 msgCopy.repeatCount = (count - prevRepeatCount) || 1; | |
| 235 msgCopy.repeatDelta = msgCopy.repeatCount; | |
| 236 this.addMessage(msgCopy, true); | |
| 237 } | |
| 238 }, | |
| 239 | |
| 240 __proto__: WebInspector.Object.prototype | 227 __proto__: WebInspector.Object.prototype |
| 241 } | 228 } |
| 242 | 229 |
| 243 /** | 230 /** |
| 244 * @interface | 231 * @interface |
| 245 */ | 232 */ |
| 246 WebInspector.ConsoleModel.UIDelegate = function() { } | 233 WebInspector.ConsoleModel.UIDelegate = function() { } |
| 247 | 234 |
| 248 WebInspector.ConsoleModel.UIDelegate.prototype = { | 235 WebInspector.ConsoleModel.UIDelegate.prototype = { |
| 249 /** | 236 /** |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 262 | 249 |
| 263 /** | 250 /** |
| 264 * @constructor | 251 * @constructor |
| 265 * @param {string} source | 252 * @param {string} source |
| 266 * @param {?string} level | 253 * @param {?string} level |
| 267 * @param {string} messageText | 254 * @param {string} messageText |
| 268 * @param {string=} type | 255 * @param {string=} type |
| 269 * @param {?string=} url | 256 * @param {?string=} url |
| 270 * @param {number=} line | 257 * @param {number=} line |
| 271 * @param {number=} column | 258 * @param {number=} column |
| 272 * @param {number=} repeatCount | |
| 273 * @param {!NetworkAgent.RequestId=} requestId | 259 * @param {!NetworkAgent.RequestId=} requestId |
| 274 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters | 260 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters |
| 275 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace | 261 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace |
| 262 * @param {number=} timestamp | |
| 276 * @param {boolean=} isOutdated | 263 * @param {boolean=} isOutdated |
| 277 */ | 264 */ |
| 278 WebInspector.ConsoleMessage = function(source, level, messageText, type, url, li ne, column, repeatCount, requestId, parameters, stackTrace, isOutdated) | 265 WebInspector.ConsoleMessage = function(source, level, messageText, type, url, li ne, column, requestId, parameters, stackTrace, timestamp, isOutdated) |
| 279 { | 266 { |
| 280 this.source = source; | 267 this.source = source; |
| 281 this.level = level; | 268 this.level = level; |
| 282 this.messageText = messageText; | 269 this.messageText = messageText; |
| 283 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; | 270 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; |
| 284 this.url = url || null; | 271 this.url = url || null; |
| 285 this.line = line || 0; | 272 this.line = line || 0; |
| 286 this.column = column || 0; | 273 this.column = column || 0; |
| 287 this.parameters = parameters; | 274 this.parameters = parameters; |
| 288 this.stackTrace = stackTrace; | 275 this.stackTrace = stackTrace; |
| 276 this.timestamp = timestamp || Date.now(); | |
| 289 this.isOutdated = isOutdated; | 277 this.isOutdated = isOutdated; |
| 290 | 278 |
| 291 repeatCount = repeatCount || 1; | 279 this.repeatCount = 1; |
| 292 this.repeatCount = repeatCount; | |
| 293 this.repeatDelta = repeatCount; | |
| 294 this.totalRepeatCount = repeatCount; | |
| 295 this.request = requestId ? WebInspector.networkLog.requestForId(requestId) : null; | 280 this.request = requestId ? WebInspector.networkLog.requestForId(requestId) : null; |
| 296 } | 281 } |
| 297 | 282 |
| 298 WebInspector.ConsoleMessage.prototype = { | 283 WebInspector.ConsoleMessage.prototype = { |
| 299 /** | 284 /** |
| 300 * @return {boolean} | 285 * @return {boolean} |
| 301 */ | 286 */ |
| 302 isErrorOrWarning: function() | 287 isErrorOrWarning: function() |
| 303 { | 288 { |
| 304 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error); | 289 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error); |
| 305 }, | 290 }, |
| 306 | 291 |
| 307 /** | 292 /** |
| 308 * @return {!WebInspector.ConsoleMessage} | 293 * @return {!WebInspector.ConsoleMessage} |
| 309 */ | 294 */ |
| 310 clone: function() | 295 clone: function() |
| 311 { | 296 { |
| 312 return new WebInspector.ConsoleMessage( | 297 return new WebInspector.ConsoleMessage( |
| 313 this.source, | 298 this.source, |
| 314 this.level, | 299 this.level, |
| 315 this.messageText, | 300 this.messageText, |
| 316 this.type, | 301 this.type, |
| 317 this.url, | 302 this.url, |
| 318 this.line, | 303 this.line, |
| 319 this.column, | 304 this.column, |
| 320 this.repeatCount, | |
| 321 this.request ? this.request.requestId : undefined, | 305 this.request ? this.request.requestId : undefined, |
| 322 this.parameters, | 306 this.parameters, |
| 323 this.stackTrace, | 307 this.stackTrace, |
| 308 this.timestamp, | |
| 324 this.isOutdated); | 309 this.isOutdated); |
| 325 }, | 310 }, |
| 326 | 311 |
| 327 /** | 312 /** |
| 328 * @param {?WebInspector.ConsoleMessage} msg | 313 * @param {?WebInspector.ConsoleMessage} msg |
| 329 * @return {boolean} | 314 * @return {boolean} |
| 330 */ | 315 */ |
| 331 isEqual: function(msg) | 316 isEqual: function(msg) |
| 332 { | 317 { |
| 333 if (!msg) | 318 if (!msg) |
| 334 return false; | 319 return false; |
| 335 | 320 |
| 321 if (this.parameters) { | |
| 322 if (!msg.parameters) | |
| 323 return false; | |
| 324 var l = this.parameters; | |
|
apavlov
2014/03/21 09:30:46
"l" is a poor variable name, since it's easily "co
| |
| 325 var r = msg.parameters; | |
| 326 if (l.length !== r.length) | |
| 327 return false; | |
| 328 // Never treat objects as equal - their properties might change over time. | |
| 329 for (var i = 0; i < l.length; i++) { | |
|
apavlov
2014/03/21 09:30:46
prefix ++ for consistency
| |
| 330 if (WebInspector.RemoteObject.fromPayload(l[i]).type === "object ") | |
| 331 return false; | |
| 332 } | |
| 333 } | |
| 334 | |
| 336 if (this.stackTrace) { | 335 if (this.stackTrace) { |
| 337 if (!msg.stackTrace) | 336 if (!msg.stackTrace) |
| 338 return false; | 337 return false; |
| 339 var l = this.stackTrace; | 338 var l = this.stackTrace; |
| 340 var r = msg.stackTrace; | 339 var r = msg.stackTrace; |
| 341 if (l.length !== r.length) | 340 if (l.length !== r.length) |
| 342 return false; | 341 return false; |
| 343 for (var i = 0; i < l.length; i++) { | 342 for (var i = 0; i < l.length; i++) { |
| 344 if (l[i].url !== r[i].url || | 343 if (l[i].url !== r[i].url || |
| 345 l[i].functionName !== r[i].functionName || | 344 l[i].functionName !== r[i].functionName || |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 messageAdded: function(payload) | 424 messageAdded: function(payload) |
| 426 { | 425 { |
| 427 var consoleMessage = new WebInspector.ConsoleMessage( | 426 var consoleMessage = new WebInspector.ConsoleMessage( |
| 428 payload.source, | 427 payload.source, |
| 429 payload.level, | 428 payload.level, |
| 430 payload.text, | 429 payload.text, |
| 431 payload.type, | 430 payload.type, |
| 432 payload.url, | 431 payload.url, |
| 433 payload.line, | 432 payload.line, |
| 434 payload.column, | 433 payload.column, |
| 435 payload.repeatCount, | |
| 436 payload.networkRequestId, | 434 payload.networkRequestId, |
| 437 payload.parameters, | 435 payload.parameters, |
| 438 payload.stackTrace, | 436 payload.stackTrace, |
| 437 payload.timestamp * 1000, // Convert to ms. | |
| 439 this._console._enablingConsole); | 438 this._console._enablingConsole); |
| 440 this._console.addMessage(consoleMessage, true); | 439 this._console.addMessage(consoleMessage, true); |
| 441 }, | 440 }, |
| 442 | 441 |
| 443 /** | |
| 444 * @param {number} count | |
| 445 */ | |
| 446 messageRepeatCountUpdated: function(count) | |
| 447 { | |
| 448 this._console._messageRepeatCountUpdated(count); | |
| 449 }, | |
| 450 | |
| 451 messagesCleared: function() | 442 messagesCleared: function() |
| 452 { | 443 { |
| 453 if (!WebInspector.settings.preserveConsoleLog.get()) | 444 if (!WebInspector.settings.preserveConsoleLog.get()) |
| 454 this._console.clearMessages(); | 445 this._console.clearMessages(); |
| 455 } | 446 } |
| 456 } | 447 } |
| 457 | 448 |
| 458 /** | 449 /** |
| 459 * @type {!WebInspector.ConsoleModel} | 450 * @type {!WebInspector.ConsoleModel} |
| 460 */ | 451 */ |
| 461 WebInspector.console; | 452 WebInspector.console; |
| OLD | NEW |