Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: Source/devtools/front_end/sdk/ConsoleModel.js

Issue 1095943002: DevTools: [console] Logged promise rejections do not change state once handled (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: for landing Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/devtools/front_end/main/Main.js ('k') | Source/devtools/front_end/ui/smallIcon.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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._messageById = 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",
55 MessageUpdated: "MessageUpdated",
52 CommandEvaluated: "CommandEvaluated", 56 CommandEvaluated: "CommandEvaluated",
53 } 57 }
54 58
55 WebInspector.ConsoleModel.prototype = { 59 WebInspector.ConsoleModel.prototype = {
56 _enableAgent: function() 60 _enableAgent: function()
57 { 61 {
58 this._enablingConsole = true; 62 this._enablingConsole = true;
59 63
60 /** 64 /**
61 * @this {WebInspector.ConsoleModel} 65 * @this {WebInspector.ConsoleModel}
62 */ 66 */
63 function callback() 67 function callback()
64 { 68 {
65 delete this._enablingConsole; 69 delete this._enablingConsole;
66 } 70 }
67 this._consoleAgent.enable(callback.bind(this)); 71 this._consoleAgent.enable(callback.bind(this));
68 }, 72 },
69 73
70 /** 74 /**
71 * @param {!WebInspector.ConsoleMessage} msg 75 * @param {!WebInspector.ConsoleMessage} msg
72 */ 76 */
73 addMessage: function(msg) 77 addMessage: function(msg)
74 { 78 {
75 msg.index = this._messages.length; 79 if (msg.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError && msg._relatedMessageId) {
80 var relatedMessage = this._messageById.get(msg._relatedMessageId);
81 if (!relatedMessage)
82 return;
83 this._errors--;
84 this._revokedErrors++;
85 relatedMessage.level = WebInspector.ConsoleMessage.MessageLevel.Revo kedError;
86 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Messa geUpdated, relatedMessage);
87 return;
88 }
89
76 this._messages.push(msg); 90 this._messages.push(msg);
91 if (msg._messageId)
92 this._messageById.set(msg._messageId, msg);
77 this._incrementErrorWarningCount(msg); 93 this._incrementErrorWarningCount(msg);
78
79 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg); 94 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, msg);
80 }, 95 },
81 96
82 /** 97 /**
83 * @param {!WebInspector.ConsoleMessage} msg 98 * @param {!WebInspector.ConsoleMessage} msg
84 */ 99 */
85 _incrementErrorWarningCount: function(msg) 100 _incrementErrorWarningCount: function(msg)
86 { 101 {
87 switch (msg.level) { 102 switch (msg.level) {
88 case WebInspector.ConsoleMessage.MessageLevel.Warning: 103 case WebInspector.ConsoleMessage.MessageLevel.Warning:
89 this.warnings++; 104 this._warnings++;
90 break; 105 break;
91 case WebInspector.ConsoleMessage.MessageLevel.Error: 106 case WebInspector.ConsoleMessage.MessageLevel.Error:
92 this.errors++; 107 this._errors++;
108 break;
109 case WebInspector.ConsoleMessage.MessageLevel.RevokedError:
110 this._revokedErrors++;
93 break; 111 break;
94 } 112 }
95 }, 113 },
96 114
97 /** 115 /**
98 * @return {!Array.<!WebInspector.ConsoleMessage>} 116 * @return {!Array.<!WebInspector.ConsoleMessage>}
99 */ 117 */
100 messages: function() 118 messages: function()
101 { 119 {
102 return this._messages; 120 return this._messages;
103 }, 121 },
104 122
105 requestClearMessages: function() 123 requestClearMessages: function()
106 { 124 {
107 this._consoleAgent.clearMessages(); 125 this._consoleAgent.clearMessages();
108 this._messagesCleared(); 126 this._messagesCleared();
109 }, 127 },
110 128
111 _messagesCleared: function() 129 _messagesCleared: function()
112 { 130 {
113 this._messages = []; 131 this._messages = [];
114 this.errors = 0; 132 this._messageById.clear();
115 this.warnings = 0; 133 this._errors = 0;
134 this._revokedErrors = 0;
135 this._warnings = 0;
116 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared); 136 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl eared);
117 }, 137 },
118 138
139 /**
140 * @return {number}
141 */
142 errors: function()
143 {
144 return this._errors;
145 },
146
147 /**
148 * @return {number}
149 */
150 revokedErrors: function()
151 {
152 return this._revokedErrors;
153 },
154
155 /**
156 * @return {number}
157 */
158 warnings: function()
159 {
160 return this._warnings;
161 },
162
119 __proto__: WebInspector.SDKModel.prototype 163 __proto__: WebInspector.SDKModel.prototype
120 } 164 }
121 165
122 /** 166 /**
123 * @param {!WebInspector.ExecutionContext} executionContext 167 * @param {!WebInspector.ExecutionContext} executionContext
124 * @param {string} text 168 * @param {string} text
125 * @param {boolean=} useCommandLineAPI 169 * @param {boolean=} useCommandLineAPI
126 */ 170 */
127 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext, text, useCommandLineAPI) 171 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext, text, useCommandLineAPI)
128 { 172 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 * @param {?string=} url 211 * @param {?string=} url
168 * @param {number=} line 212 * @param {number=} line
169 * @param {number=} column 213 * @param {number=} column
170 * @param {!NetworkAgent.RequestId=} requestId 214 * @param {!NetworkAgent.RequestId=} requestId
171 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters 215 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters
172 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace 216 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace
173 * @param {number=} timestamp 217 * @param {number=} timestamp
174 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId 218 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId
175 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace 219 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace
176 * @param {?string=} scriptId 220 * @param {?string=} scriptId
221 * @param {number=} messageId
222 * @param {number=} relatedMessageId
177 */ 223 */
178 WebInspector.ConsoleMessage = function(target, source, level, messageText, type, url, line, column, requestId, parameters, stackTrace, timestamp, executionConte xtId, asyncStackTrace, scriptId) 224 WebInspector.ConsoleMessage = function(target, source, level, messageText, type, url, line, column, requestId, parameters, stackTrace, timestamp, executionConte xtId, asyncStackTrace, scriptId, messageId, relatedMessageId)
179 { 225 {
180 this._target = target; 226 this._target = target;
181 this.source = source; 227 this.source = source;
182 this.level = level; 228 this.level = level;
183 this.messageText = messageText; 229 this.messageText = messageText;
184 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; 230 this.type = type || WebInspector.ConsoleMessage.MessageType.Log;
185 /** @type {string|undefined} */ 231 /** @type {string|undefined} */
186 this.url = url || undefined; 232 this.url = url || undefined;
187 /** @type {number} */ 233 /** @type {number} */
188 this.line = line || 0; 234 this.line = line || 0;
189 /** @type {number} */ 235 /** @type {number} */
190 this.column = column || 0; 236 this.column = column || 0;
191 this.parameters = parameters; 237 this.parameters = parameters;
192 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */ 238 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */
193 this.stackTrace = stackTrace; 239 this.stackTrace = stackTrace;
194 this.timestamp = timestamp || Date.now(); 240 this.timestamp = timestamp || Date.now();
195 this.executionContextId = executionContextId || 0; 241 this.executionContextId = executionContextId || 0;
196 this.asyncStackTrace = asyncStackTrace; 242 this.asyncStackTrace = asyncStackTrace;
197 this.scriptId = scriptId || null; 243 this.scriptId = scriptId || null;
244 this._messageId = messageId || 0;
245 this._relatedMessageId = relatedMessageId || 0;
198 246
199 this.request = requestId ? target.networkLog.requestForId(requestId) : null; 247 this.request = requestId ? target.networkLog.requestForId(requestId) : null;
200 248
201 if (this.request) { 249 if (this.request) {
202 var initiator = this.request.initiator(); 250 var initiator = this.request.initiator();
203 if (initiator) { 251 if (initiator) {
204 this.stackTrace = initiator.stackTrace || undefined; 252 this.stackTrace = initiator.stackTrace || undefined;
205 this.asyncStackTrace = initiator.asyncStackTrace; 253 this.asyncStackTrace = initiator.asyncStackTrace;
206 if (initiator.url) { 254 if (initiator.url) {
207 this.url = initiator.url; 255 this.url = initiator.url;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 314
267 /** 315 /**
268 * @return {boolean} 316 * @return {boolean}
269 */ 317 */
270 isErrorOrWarning: function() 318 isErrorOrWarning: function()
271 { 319 {
272 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error); 320 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error);
273 }, 321 },
274 322
275 /** 323 /**
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 324 * @param {?WebInspector.ConsoleMessage} msg
300 * @return {boolean} 325 * @return {boolean}
301 */ 326 */
302 isEqual: function(msg) 327 isEqual: function(msg)
303 { 328 {
304 if (!msg) 329 if (!msg)
305 return false; 330 return false;
306 331
332 if (this._messageId || msg._messageId)
333 return false;
334 if (this._relatedMessageId || msg._relatedMessageId)
335 return false;
336
307 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) 337 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace))
308 return false; 338 return false;
309 339
310 var asyncTrace1 = this.asyncStackTrace; 340 var asyncTrace1 = this.asyncStackTrace;
311 var asyncTrace2 = msg.asyncStackTrace; 341 var asyncTrace2 = msg.asyncStackTrace;
312 while (asyncTrace1 || asyncTrace2) { 342 while (asyncTrace1 || asyncTrace2) {
313 if (!asyncTrace1 || !asyncTrace2) 343 if (!asyncTrace1 || !asyncTrace2)
314 return false; 344 return false;
315 if (asyncTrace1.description !== asyncTrace2.description) 345 if (asyncTrace1.description !== asyncTrace2.description)
316 return false; 346 return false;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 434 }
405 435
406 /** 436 /**
407 * @enum {string} 437 * @enum {string}
408 */ 438 */
409 WebInspector.ConsoleMessage.MessageLevel = { 439 WebInspector.ConsoleMessage.MessageLevel = {
410 Log: "log", 440 Log: "log",
411 Info: "info", 441 Info: "info",
412 Warning: "warning", 442 Warning: "warning",
413 Error: "error", 443 Error: "error",
414 Debug: "debug" 444 Debug: "debug",
445 RevokedError: "revokedError"
415 }; 446 };
416 447
417 /** 448 /**
418 * @param {!WebInspector.ConsoleMessage} a 449 * @param {!WebInspector.ConsoleMessage} a
419 * @param {!WebInspector.ConsoleMessage} b 450 * @param {!WebInspector.ConsoleMessage} b
420 * @return {number} 451 * @return {number}
421 */ 452 */
422 WebInspector.ConsoleMessage.timestampComparator = function (a, b) 453 WebInspector.ConsoleMessage.timestampComparator = function (a, b)
423 { 454 {
424 return a.timestamp - b.timestamp; 455 return a.timestamp - b.timestamp;
(...skipping 24 matching lines...) Expand all
449 payload.type, 480 payload.type,
450 payload.url, 481 payload.url,
451 payload.line, 482 payload.line,
452 payload.column, 483 payload.column,
453 payload.networkRequestId, 484 payload.networkRequestId,
454 payload.parameters, 485 payload.parameters,
455 payload.stackTrace, 486 payload.stackTrace,
456 payload.timestamp * 1000, // Convert to ms. 487 payload.timestamp * 1000, // Convert to ms.
457 payload.executionContextId, 488 payload.executionContextId,
458 payload.asyncStackTrace, 489 payload.asyncStackTrace,
459 payload.scriptId); 490 payload.scriptId,
491 payload.messageId,
492 payload.relatedMessageId);
460 this._console.addMessage(consoleMessage); 493 this._console.addMessage(consoleMessage);
461 }, 494 },
462 495
463 /** 496 /**
464 * @override 497 * @override
465 * @param {number} count 498 * @param {number} count
466 */ 499 */
467 messageRepeatCountUpdated: function(count) 500 messageRepeatCountUpdated: function(count)
468 { 501 {
469 }, 502 },
(...skipping 10 matching lines...) Expand all
480 513
481 /** 514 /**
482 * @constructor 515 * @constructor
483 * @extends {WebInspector.Object} 516 * @extends {WebInspector.Object}
484 * @implements {WebInspector.TargetManager.Observer} 517 * @implements {WebInspector.TargetManager.Observer}
485 */ 518 */
486 WebInspector.MultitargetConsoleModel = function() 519 WebInspector.MultitargetConsoleModel = function()
487 { 520 {
488 WebInspector.targetManager.observeTargets(this); 521 WebInspector.targetManager.observeTargets(this);
489 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn spector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this); 522 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn spector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
523 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn spector.ConsoleModel.Events.MessageUpdated, this._consoleMessageUpdated, this);
490 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn spector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this); 524 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn spector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this);
491 } 525 }
492 526
493 WebInspector.MultitargetConsoleModel.prototype = { 527 WebInspector.MultitargetConsoleModel.prototype = {
494 /** 528 /**
495 * @override 529 * @override
496 * @param {!WebInspector.Target} target 530 * @param {!WebInspector.Target} target
497 */ 531 */
498 targetAdded: function(target) 532 targetAdded: function(target)
499 { 533 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 * @param {!WebInspector.Event} event 570 * @param {!WebInspector.Event} event
537 */ 571 */
538 _consoleMessageAdded: function(event) 572 _consoleMessageAdded: function(event)
539 { 573 {
540 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, event.data); 574 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd ded, event.data);
541 }, 575 },
542 576
543 /** 577 /**
544 * @param {!WebInspector.Event} event 578 * @param {!WebInspector.Event} event
545 */ 579 */
580 _consoleMessageUpdated: function(event)
581 {
582 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageUp dated, event.data);
583 },
584
585 /**
586 * @param {!WebInspector.Event} event
587 */
546 _commandEvaluated: function(event) 588 _commandEvaluated: function(event)
547 { 589 {
548 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data); 590 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv aluated, event.data);
549 }, 591 },
550 592
551 __proto__: WebInspector.Object.prototype 593 __proto__: WebInspector.Object.prototype
552 } 594 }
553 595
554 /** 596 /**
555 * @type {!WebInspector.MultitargetConsoleModel} 597 * @type {!WebInspector.MultitargetConsoleModel}
556 */ 598 */
557 WebInspector.multitargetConsoleModel; 599 WebInspector.multitargetConsoleModel;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/main/Main.js ('k') | Source/devtools/front_end/ui/smallIcon.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698