forked from mirrors/gecko-dev
This patch was autogenerated by my decomponents.py
It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.
It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.
It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)
MozReview-Commit-ID: DeSHcClQ7cG
--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
159 lines
5 KiB
JavaScript
159 lines
5 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
// This constant tells how many messages to process in a single timer execution.
|
|
const MESSAGES_IN_INTERVAL = 1500
|
|
|
|
const STORAGE_MAX_EVENTS = 1000;
|
|
|
|
var _consoleStorage = new Map();
|
|
|
|
const CONSOLEAPISTORAGE_CID = Components.ID('{96cf7855-dfa9-4c6d-8276-f9705b4890f2}');
|
|
|
|
/**
|
|
* The ConsoleAPIStorage is meant to cache window.console API calls for later
|
|
* reuse by other components when needed. For example, the Web Console code can
|
|
* display the cached messages when it opens for the active tab.
|
|
*
|
|
* ConsoleAPI messages are stored as they come from the ConsoleAPI code, with
|
|
* all their properties. They are kept around until the inner window object that
|
|
* created the messages is destroyed. Messages are indexed by the inner window
|
|
* ID.
|
|
*
|
|
* Usage:
|
|
* let ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"]
|
|
* .getService(Ci.nsIConsoleAPIStorage);
|
|
*
|
|
* // Get the cached events array for the window you want (use the inner
|
|
* // window ID).
|
|
* let events = ConsoleAPIStorage.getEvents(innerWindowID);
|
|
* events.forEach(function(event) { ... });
|
|
*
|
|
* // Clear the events for the given inner window ID.
|
|
* ConsoleAPIStorage.clearEvents(innerWindowID);
|
|
*/
|
|
function ConsoleAPIStorageService() {
|
|
this.init();
|
|
}
|
|
|
|
ConsoleAPIStorageService.prototype = {
|
|
classID : CONSOLEAPISTORAGE_CID,
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIConsoleAPIStorage,
|
|
Ci.nsIObserver]),
|
|
classInfo: XPCOMUtils.generateCI({
|
|
classID: CONSOLEAPISTORAGE_CID,
|
|
contractID: '@mozilla.org/consoleAPI-storage;1',
|
|
interfaces: [Ci.nsIConsoleAPIStorage, Ci.nsIObserver],
|
|
flags: Ci.nsIClassInfo.SINGLETON
|
|
}),
|
|
|
|
observe: function CS_observe(aSubject, aTopic, aData)
|
|
{
|
|
if (aTopic == "xpcom-shutdown") {
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
Services.obs.removeObserver(this, "inner-window-destroyed");
|
|
Services.obs.removeObserver(this, "memory-pressure");
|
|
}
|
|
else if (aTopic == "inner-window-destroyed") {
|
|
let innerWindowID = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
this.clearEvents(innerWindowID + "");
|
|
}
|
|
else if (aTopic == "memory-pressure") {
|
|
this.clearEvents();
|
|
}
|
|
},
|
|
|
|
/** @private */
|
|
init: function CS_init()
|
|
{
|
|
Services.obs.addObserver(this, "xpcom-shutdown");
|
|
Services.obs.addObserver(this, "inner-window-destroyed");
|
|
Services.obs.addObserver(this, "memory-pressure");
|
|
},
|
|
|
|
/**
|
|
* Get the events array by inner window ID or all events from all windows.
|
|
*
|
|
* @param string [aId]
|
|
* Optional, the inner window ID for which you want to get the array of
|
|
* cached events.
|
|
* @returns array
|
|
* The array of cached events for the given window. If no |aId| is
|
|
* given this function returns all of the cached events, from any
|
|
* window.
|
|
*/
|
|
getEvents: function CS_getEvents(aId)
|
|
{
|
|
if (aId != null) {
|
|
return (_consoleStorage.get(aId) || []).slice(0);
|
|
}
|
|
|
|
let result = [];
|
|
|
|
for (let [id, events] of _consoleStorage) {
|
|
result.push.apply(result, events);
|
|
}
|
|
|
|
return result.sort(function(a, b) {
|
|
return a.timeStamp - b.timeStamp;
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Record an event associated with the given window ID.
|
|
*
|
|
* @param string aId
|
|
* The ID of the inner window for which the event occurred or "jsm" for
|
|
* messages logged from JavaScript modules..
|
|
* @param string aOuterId
|
|
* This ID is used as 3rd parameters for the console-api-log-event
|
|
* notification.
|
|
* @param object aEvent
|
|
* A JavaScript object you want to store.
|
|
*/
|
|
recordEvent: function CS_recordEvent(aId, aOuterId, aEvent)
|
|
{
|
|
if (!_consoleStorage.has(aId)) {
|
|
_consoleStorage.set(aId, []);
|
|
}
|
|
|
|
let storage = _consoleStorage.get(aId);
|
|
|
|
storage.push(aEvent);
|
|
|
|
// truncate
|
|
if (storage.length > STORAGE_MAX_EVENTS) {
|
|
storage.shift();
|
|
}
|
|
|
|
Services.obs.notifyObservers(aEvent, "console-api-log-event", aOuterId);
|
|
Services.obs.notifyObservers(aEvent, "console-storage-cache-event", aId);
|
|
},
|
|
|
|
/**
|
|
* Clear storage data for the given window.
|
|
*
|
|
* @param string [aId]
|
|
* Optional, the inner window ID for which you want to clear the
|
|
* messages. If this is not specified all of the cached messages are
|
|
* cleared, from all window objects.
|
|
*/
|
|
clearEvents: function CS_clearEvents(aId)
|
|
{
|
|
if (aId != null) {
|
|
_consoleStorage.delete(aId);
|
|
}
|
|
else {
|
|
_consoleStorage.clear();
|
|
Services.obs.notifyObservers(null, "console-storage-reset");
|
|
}
|
|
},
|
|
};
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ConsoleAPIStorageService]);
|