1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * @extends {WebInspector.Object}
9 WebInspector.Console = function()
11 /** @type {!Array.<!WebInspector.Console.Message>} */
18 WebInspector.Console.Events = {
19 MessageAdded: "messageAdded"
25 WebInspector.Console.MessageLevel = {
33 * @param {string} text
34 * @param {!WebInspector.Console.MessageLevel} level
35 * @param {number} timestamp
36 * @param {boolean} show
38 WebInspector.Console.Message = function(text, level, timestamp, show)
42 this.timestamp = (typeof timestamp === "number") ? timestamp : Date.now();
49 WebInspector.Console.UIDelegate = function()
53 WebInspector.Console.UIDelegate.prototype = {
55 * @return {!Promise.<undefined>}
57 showConsole: function() { }
60 WebInspector.Console.prototype = {
62 * @param {!WebInspector.Console.UIDelegate} uiDelegate
64 setUIDelegate: function(uiDelegate)
66 this._uiDelegate = uiDelegate;
70 * @param {string} text
71 * @param {!WebInspector.Console.MessageLevel} level
72 * @param {boolean=} show
74 addMessage: function(text, level, show)
76 var message = new WebInspector.Console.Message(text, level || WebInspector.Console.MessageLevel.Log, Date.now(), show || false);
77 this._messages.push(message);
78 this.dispatchEventToListeners(WebInspector.Console.Events.MessageAdded, message);
82 * @param {string} text
86 this.addMessage(text, WebInspector.Console.MessageLevel.Log);
90 * @param {string} text
94 this.addMessage(text, WebInspector.Console.MessageLevel.Warning);
98 * @param {string} text
100 error: function(text)
102 this.addMessage(text, WebInspector.Console.MessageLevel.Error, true);
106 * @return {!Array.<!WebInspector.Console.Message>}
110 return this._messages;
115 this.showPromise().done();
119 * @return {!Promise.<undefined>}
121 showPromise: function()
123 if (this._uiDelegate)
124 return this._uiDelegate.showConsole();
125 return Promise.reject();
128 __proto__: WebInspector.Object.prototype
131 WebInspector.console = new WebInspector.Console();