| 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 this._enableAgent(); | 45 this._enableAgent(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 WebInspector.ConsoleModel.Events = { | 48 WebInspector.ConsoleModel.Events = { |
| 50 ConsoleCleared: "ConsoleCleared", | 49 ConsoleCleared: "ConsoleCleared", |
| 51 MessageAdded: "MessageAdded", | 50 MessageAdded: "MessageAdded", |
| 52 RepeatCountUpdated: "RepeatCountUpdated", | |
| 53 CommandEvaluated: "CommandEvaluated", | 51 CommandEvaluated: "CommandEvaluated", |
| 54 } | 52 } |
| 55 | 53 |
| 56 WebInspector.ConsoleModel.prototype = { | 54 WebInspector.ConsoleModel.prototype = { |
| 57 _enableAgent: function() | 55 _enableAgent: function() |
| 58 { | 56 { |
| 59 if (WebInspector.settings.monitoringXHREnabled.get()) | 57 if (WebInspector.settings.monitoringXHREnabled.get()) |
| 60 this._consoleAgent.setMonitoringXHREnabled(true); | 58 this._consoleAgent.setMonitoringXHREnabled(true); |
| 61 | 59 |
| 62 this._enablingConsole = true; | 60 this._enablingConsole = true; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 85 */ | 83 */ |
| 86 addMessage: function(msg, isFromBackend) | 84 addMessage: function(msg, isFromBackend) |
| 87 { | 85 { |
| 88 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms
g.request)) | 86 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(ms
g.request)) |
| 89 return; | 87 return; |
| 90 | 88 |
| 91 msg.index = this.messages.length; | 89 msg.index = this.messages.length; |
| 92 this.messages.push(msg); | 90 this.messages.push(msg); |
| 93 this._incrementErrorWarningCount(msg); | 91 this._incrementErrorWarningCount(msg); |
| 94 | 92 |
| 95 if (isFromBackend) | |
| 96 this._previousMessage = msg; | |
| 97 | |
| 98 this._interruptRepeatCount = !isFromBackend; | |
| 99 | |
| 100 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); | 93 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); |
| 101 }, | 94 }, |
| 102 | 95 |
| 103 /** | 96 /** |
| 104 * @param {string} text | 97 * @param {string} text |
| 105 * @param {boolean} useCommandLineAPI | 98 * @param {boolean} useCommandLineAPI |
| 106 */ | 99 */ |
| 107 evaluateCommand: function(text, useCommandLineAPI) | 100 evaluateCommand: function(text, useCommandLineAPI) |
| 108 { | 101 { |
| 109 this.show(); | 102 this.show(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 this.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true); | 160 this.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true); |
| 168 }, | 161 }, |
| 169 | 162 |
| 170 /** | 163 /** |
| 171 * @param {!WebInspector.ConsoleMessage} msg | 164 * @param {!WebInspector.ConsoleMessage} msg |
| 172 */ | 165 */ |
| 173 _incrementErrorWarningCount: function(msg) | 166 _incrementErrorWarningCount: function(msg) |
| 174 { | 167 { |
| 175 switch (msg.level) { | 168 switch (msg.level) { |
| 176 case WebInspector.ConsoleMessage.MessageLevel.Warning: | 169 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
| 177 this.warnings += msg.repeatDelta; | 170 this.warnings++; |
| 178 break; | 171 break; |
| 179 case WebInspector.ConsoleMessage.MessageLevel.Error: | 172 case WebInspector.ConsoleMessage.MessageLevel.Error: |
| 180 this.errors += msg.repeatDelta; | 173 this.errors++; |
| 181 break; | 174 break; |
| 182 } | 175 } |
| 183 }, | 176 }, |
| 184 | 177 |
| 185 requestClearMessages: function() | 178 requestClearMessages: function() |
| 186 { | 179 { |
| 187 this._consoleAgent.clearMessages(); | 180 this._consoleAgent.clearMessages(); |
| 188 this.clearMessages(); | 181 this.clearMessages(); |
| 189 }, | 182 }, |
| 190 | 183 |
| 191 clearMessages: function() | 184 clearMessages: function() |
| 192 { | 185 { |
| 193 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); | 186 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); |
| 194 | 187 |
| 195 this.messages = []; | 188 this.messages = []; |
| 196 delete this._previousMessage; | |
| 197 | |
| 198 this.errors = 0; | 189 this.errors = 0; |
| 199 this.warnings = 0; | 190 this.warnings = 0; |
| 200 }, | 191 }, |
| 201 | 192 |
| 202 /** | |
| 203 * @param {number} count | |
| 204 */ | |
| 205 _messageRepeatCountUpdated: function(count) | |
| 206 { | |
| 207 var msg = this._previousMessage; | |
| 208 if (!msg) | |
| 209 return; | |
| 210 | |
| 211 var prevRepeatCount = msg.totalRepeatCount; | |
| 212 | |
| 213 if (!this._interruptRepeatCount) { | |
| 214 msg.repeatDelta = count - prevRepeatCount; | |
| 215 msg.repeatCount = msg.repeatCount + msg.repeatDelta; | |
| 216 msg.totalRepeatCount = count; | |
| 217 | |
| 218 this._incrementErrorWarningCount(msg); | |
| 219 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Repea
tCountUpdated, msg); | |
| 220 } else { | |
| 221 var msgCopy = msg.clone(); | |
| 222 msgCopy.totalRepeatCount = count; | |
| 223 msgCopy.repeatCount = (count - prevRepeatCount) || 1; | |
| 224 msgCopy.repeatDelta = msgCopy.repeatCount; | |
| 225 this.addMessage(msgCopy, true); | |
| 226 } | |
| 227 }, | |
| 228 | |
| 229 __proto__: WebInspector.Object.prototype | 193 __proto__: WebInspector.Object.prototype |
| 230 } | 194 } |
| 231 | 195 |
| 232 /** | 196 /** |
| 233 * @constructor | 197 * @constructor |
| 234 * @param {string} source | 198 * @param {string} source |
| 235 * @param {?string} level | 199 * @param {?string} level |
| 236 * @param {string} messageText | 200 * @param {string} messageText |
| 237 * @param {string=} type | 201 * @param {string=} type |
| 238 * @param {?string=} url | 202 * @param {?string=} url |
| 239 * @param {number=} line | 203 * @param {number=} line |
| 240 * @param {number=} column | 204 * @param {number=} column |
| 241 * @param {number=} repeatCount | |
| 242 * @param {!NetworkAgent.RequestId=} requestId | 205 * @param {!NetworkAgent.RequestId=} requestId |
| 243 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters | 206 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters |
| 244 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace | 207 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace |
| 245 * @param {boolean=} isOutdated | 208 * @param {boolean=} isOutdated |
| 246 */ | 209 */ |
| 247 WebInspector.ConsoleMessage = function(source, level, messageText, type, url, li
ne, column, repeatCount, requestId, parameters, stackTrace, isOutdated) | 210 WebInspector.ConsoleMessage = function(source, level, messageText, type, url, li
ne, column, requestId, parameters, stackTrace, isOutdated) |
| 248 { | 211 { |
| 249 this.source = source; | 212 this.source = source; |
| 250 this.level = level; | 213 this.level = level; |
| 251 this.messageText = messageText; | 214 this.messageText = messageText; |
| 252 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; | 215 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; |
| 253 this.url = url || null; | 216 this.url = url || null; |
| 254 this.line = line || 0; | 217 this.line = line || 0; |
| 255 this.column = column || 0; | 218 this.column = column || 0; |
| 256 this.parameters = parameters; | 219 this.parameters = parameters; |
| 257 this.stackTrace = stackTrace; | 220 this.stackTrace = stackTrace; |
| 258 this.isOutdated = isOutdated; | 221 this.isOutdated = isOutdated; |
| 259 | |
| 260 repeatCount = repeatCount || 1; | |
| 261 this.repeatCount = repeatCount; | |
| 262 this.repeatDelta = repeatCount; | |
| 263 this.totalRepeatCount = repeatCount; | |
| 264 this.request = requestId ? WebInspector.networkLog.requestForId(requestId) :
null; | 222 this.request = requestId ? WebInspector.networkLog.requestForId(requestId) :
null; |
| 265 } | 223 } |
| 266 | 224 |
| 267 WebInspector.ConsoleMessage.prototype = { | 225 WebInspector.ConsoleMessage.prototype = { |
| 226 |
| 268 /** | 227 /** |
| 269 * @return {boolean} | 228 * @return {boolean} |
| 270 */ | 229 */ |
| 230 isGroupMessage: function() |
| 231 { |
| 232 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup
|| |
| 233 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupColl
apsed || |
| 234 this.type === WebInspector.ConsoleMessage.MessageType.EndGroup; |
| 235 }, |
| 236 |
| 237 /** |
| 238 * @return {boolean} |
| 239 */ |
| 271 isErrorOrWarning: function() | 240 isErrorOrWarning: function() |
| 272 { | 241 { |
| 273 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning
|| this.level === WebInspector.ConsoleMessage.MessageLevel.Error); | 242 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning
|| this.level === WebInspector.ConsoleMessage.MessageLevel.Error); |
| 274 }, | 243 }, |
| 275 | 244 |
| 276 /** | 245 /** |
| 277 * @return {!WebInspector.ConsoleMessage} | 246 * @return {!WebInspector.ConsoleMessage} |
| 278 */ | 247 */ |
| 279 clone: function() | 248 clone: function() |
| 280 { | 249 { |
| 281 return new WebInspector.ConsoleMessage( | 250 return new WebInspector.ConsoleMessage( |
| 282 this.source, | 251 this.source, |
| 283 this.level, | 252 this.level, |
| 284 this.messageText, | 253 this.messageText, |
| 285 this.type, | 254 this.type, |
| 286 this.url, | 255 this.url, |
| 287 this.line, | 256 this.line, |
| 288 this.column, | 257 this.column, |
| 289 this.repeatCount, | |
| 290 this.request ? this.request.requestId : undefined, | 258 this.request ? this.request.requestId : undefined, |
| 291 this.parameters, | 259 this.parameters, |
| 292 this.stackTrace, | 260 this.stackTrace, |
| 293 this.isOutdated); | 261 this.isOutdated); |
| 294 }, | 262 }, |
| 295 | 263 |
| 296 /** | 264 /** |
| 297 * @param {?WebInspector.ConsoleMessage} msg | 265 * @param {?WebInspector.ConsoleMessage} msg |
| 298 * @return {boolean} | 266 * @return {boolean} |
| 299 */ | 267 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 311 return false; | 279 return false; |
| 312 for (var i = 0; i < l.length; i++) { | 280 for (var i = 0; i < l.length; i++) { |
| 313 if (l[i].url !== r[i].url || | 281 if (l[i].url !== r[i].url || |
| 314 l[i].functionName !== r[i].functionName || | 282 l[i].functionName !== r[i].functionName || |
| 315 l[i].lineNumber !== r[i].lineNumber || | 283 l[i].lineNumber !== r[i].lineNumber || |
| 316 l[i].columnNumber !== r[i].columnNumber) | 284 l[i].columnNumber !== r[i].columnNumber) |
| 317 return false; | 285 return false; |
| 318 } | 286 } |
| 319 } | 287 } |
| 320 | 288 |
| 289 if (this.parameters) { |
| 290 if (!msg.parameters || this.parameters.length !== msg.parameters.len
gth) |
| 291 return false; |
| 292 |
| 293 for (var i = 0; i < msg.parameters.length; ++i) { |
| 294 // Never treat objects as equal - their properties might change
over time. |
| 295 if (this.parameters[i].type !== msg.parameters[i].type || msg.pa
rameters[i].type === "object" || this.parameters[i].value !== msg.parameters[i].
value) |
| 296 return false; |
| 297 } |
| 298 } |
| 299 |
| 321 return (this.source === msg.source) | 300 return (this.source === msg.source) |
| 322 && (this.type === msg.type) | 301 && (this.type === msg.type) |
| 323 && (this.level === msg.level) | 302 && (this.level === msg.level) |
| 324 && (this.line === msg.line) | 303 && (this.line === msg.line) |
| 325 && (this.url === msg.url) | 304 && (this.url === msg.url) |
| 326 && (this.messageText === msg.messageText) | 305 && (this.messageText === msg.messageText) |
| 327 && (this.request === msg.request); | 306 && (this.request === msg.request); |
| 328 } | 307 } |
| 329 } | 308 } |
| 330 | 309 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 messageAdded: function(payload) | 373 messageAdded: function(payload) |
| 395 { | 374 { |
| 396 var consoleMessage = new WebInspector.ConsoleMessage( | 375 var consoleMessage = new WebInspector.ConsoleMessage( |
| 397 payload.source, | 376 payload.source, |
| 398 payload.level, | 377 payload.level, |
| 399 payload.text, | 378 payload.text, |
| 400 payload.type, | 379 payload.type, |
| 401 payload.url, | 380 payload.url, |
| 402 payload.line, | 381 payload.line, |
| 403 payload.column, | 382 payload.column, |
| 404 payload.repeatCount, | |
| 405 payload.networkRequestId, | 383 payload.networkRequestId, |
| 406 payload.parameters, | 384 payload.parameters, |
| 407 payload.stackTrace, | 385 payload.stackTrace, |
| 408 this._console._enablingConsole); | 386 this._console._enablingConsole); |
| 409 this._console.addMessage(consoleMessage, true); | 387 this._console.addMessage(consoleMessage, true); |
| 410 }, | 388 }, |
| 411 | 389 |
| 412 /** | 390 /** |
| 413 * @param {number} count | 391 * @param {number} count |
| 414 */ | 392 */ |
| 415 messageRepeatCountUpdated: function(count) | 393 messageRepeatCountUpdated: function(count) |
| 416 { | 394 { |
| 417 this._console._messageRepeatCountUpdated(count); | |
| 418 }, | 395 }, |
| 419 | 396 |
| 420 messagesCleared: function() | 397 messagesCleared: function() |
| 421 { | 398 { |
| 422 if (!WebInspector.settings.preserveConsoleLog.get()) | 399 if (!WebInspector.settings.preserveConsoleLog.get()) |
| 423 this._console.clearMessages(); | 400 this._console.clearMessages(); |
| 424 } | 401 } |
| 425 } | 402 } |
| 426 | 403 |
| 427 /** | 404 /** |
| 428 * @type {!WebInspector.ConsoleModel} | 405 * @type {!WebInspector.ConsoleModel} |
| 429 */ | 406 */ |
| 430 WebInspector.console; | 407 WebInspector.console; |
| OLD | NEW |