mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-09 05:08:28 +08:00
The unrestricted annotation is Closure-specific and can be removed. This patch removes all comments with only the unrestricted annotation in them. R=szuend@chromium.org No-Presubmit: True Bug: 1011811 Change-Id: Iba0723644f53f5307c3077d341271af86becc32a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2569758 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
115 lines
2.1 KiB
JavaScript
115 lines
2.1 KiB
JavaScript
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import {ObjectWrapper} from './Object.js';
|
|
import {reveal} from './Revealer.js';
|
|
|
|
/**
|
|
* @type {!Console}
|
|
*/
|
|
let consoleInstance;
|
|
|
|
export class Console extends ObjectWrapper {
|
|
/**
|
|
* Instantiable via the instance() factory below.
|
|
*
|
|
* @private
|
|
*/
|
|
constructor() {
|
|
super();
|
|
/** @type {!Array.<!Message>} */
|
|
this._messages = [];
|
|
}
|
|
|
|
/**
|
|
* @param {{forceNew: boolean}} opts
|
|
*/
|
|
static instance({forceNew} = {forceNew: false}) {
|
|
if (!consoleInstance || forceNew) {
|
|
consoleInstance = new Console();
|
|
}
|
|
|
|
return consoleInstance;
|
|
}
|
|
|
|
/**
|
|
* @param {string} text
|
|
* @param {!MessageLevel} level
|
|
* @param {boolean=} show
|
|
*/
|
|
addMessage(text, level, show) {
|
|
const message = new Message(text, level || MessageLevel.Info, Date.now(), show || false);
|
|
this._messages.push(message);
|
|
this.dispatchEventToListeners(Events.MessageAdded, message);
|
|
}
|
|
|
|
/**
|
|
* @param {string} text
|
|
*/
|
|
log(text) {
|
|
this.addMessage(text, MessageLevel.Info);
|
|
}
|
|
|
|
/**
|
|
* @param {string} text
|
|
*/
|
|
warn(text) {
|
|
this.addMessage(text, MessageLevel.Warning);
|
|
}
|
|
|
|
/**
|
|
* @param {string} text
|
|
*/
|
|
error(text) {
|
|
this.addMessage(text, MessageLevel.Error, true);
|
|
}
|
|
|
|
/**
|
|
* @return {!Array.<!Message>}
|
|
*/
|
|
messages() {
|
|
return this._messages;
|
|
}
|
|
|
|
show() {
|
|
this.showPromise();
|
|
}
|
|
|
|
/**
|
|
* @return {!Promise.<void>}
|
|
*/
|
|
showPromise() {
|
|
return reveal(this);
|
|
}
|
|
}
|
|
|
|
/** @enum {symbol} */
|
|
export const Events = {
|
|
MessageAdded: Symbol('messageAdded')
|
|
};
|
|
|
|
/**
|
|
* @enum {string}
|
|
*/
|
|
export const MessageLevel = {
|
|
Info: 'info',
|
|
Warning: 'warning',
|
|
Error: 'error'
|
|
};
|
|
|
|
export class Message {
|
|
/**
|
|
* @param {string} text
|
|
* @param {!MessageLevel} level
|
|
* @param {number} timestamp
|
|
* @param {boolean} show
|
|
*/
|
|
constructor(text, level, timestamp, show) {
|
|
this.text = text;
|
|
this.level = level;
|
|
this.timestamp = (typeof timestamp === 'number') ? timestamp : Date.now();
|
|
this.show = show;
|
|
}
|
|
}
|