2011-09-15 18:20:22 +00:00
|
|
|
/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-11-09 20:19:19 +00:00
|
|
|
|
|
|
|
let Cu = Components.utils;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
let Cc = Components.classes;
|
2012-06-02 10:45:32 +00:00
|
|
|
|
2011-06-01 06:33:22 +00:00
|
|
|
// The maximum allowed number of concurrent timers per page.
|
|
|
|
const MAX_PAGE_TIMERS = 10000;
|
2010-11-09 20:19:19 +00:00
|
|
|
|
2012-06-02 10:45:32 +00:00
|
|
|
// The regular expression used to parse %s/%d and other placeholders for
|
|
|
|
// variables in strings that need to be interpolated.
|
|
|
|
const ARGUMENT_PATTERN = /%\d*\.?\d*([osdif])\b/g;
|
|
|
|
|
|
|
|
// The maximum stacktrace depth when populating the stacktrace array used for
|
|
|
|
// console.trace().
|
|
|
|
const DEFAULT_MAX_STACKTRACE_DEPTH = 200;
|
|
|
|
|
|
|
|
// The console API methods are async and their action is executed later. This
|
|
|
|
// delay tells how much later.
|
2012-06-12 11:25:07 +00:00
|
|
|
const CALL_DELAY = 15; // milliseconds
|
|
|
|
|
|
|
|
// This constant tells how many messages to process in a single timer execution.
|
|
|
|
const MESSAGES_IN_INTERVAL = 1500;
|
2012-06-02 10:45:32 +00:00
|
|
|
|
2010-11-09 20:19:19 +00:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2011-08-24 20:34:16 +00:00
|
|
|
Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm");
|
2012-04-24 15:52:11 +00:00
|
|
|
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2010-11-09 20:19:19 +00:00
|
|
|
|
2012-07-07 10:21:04 +00:00
|
|
|
/**
|
|
|
|
* The window.console API implementation. One instance is lazily created for
|
|
|
|
* every inner window, when the window.console object is accessed.
|
|
|
|
*/
|
2010-11-09 20:19:19 +00:00
|
|
|
function ConsoleAPI() {}
|
|
|
|
ConsoleAPI.prototype = {
|
|
|
|
|
|
|
|
classID: Components.ID("{b49c18f8-3379-4fc0-8c90-d7772c1a9ff3}"),
|
|
|
|
|
2012-07-07 10:21:04 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIObserver]),
|
2010-11-09 20:19:19 +00:00
|
|
|
|
2012-06-02 10:45:32 +00:00
|
|
|
_timerInitialized: false,
|
|
|
|
_queuedCalls: null,
|
2012-07-07 10:21:04 +00:00
|
|
|
_window: null,
|
|
|
|
_innerID: null,
|
|
|
|
_outerID: null,
|
|
|
|
_windowDestroyed: false,
|
|
|
|
_timer: null,
|
2012-06-02 10:45:32 +00:00
|
|
|
|
2010-11-09 20:19:19 +00:00
|
|
|
// nsIDOMGlobalPropertyInitializer
|
|
|
|
init: function CA_init(aWindow) {
|
2012-07-07 10:21:04 +00:00
|
|
|
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
let windowUtils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
|
|
|
|
this._outerID = windowUtils.outerWindowID;
|
|
|
|
this._innerID = windowUtils.currentInnerWindowID;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
2011-06-01 06:33:22 +00:00
|
|
|
|
2010-11-17 20:20:20 +00:00
|
|
|
let self = this;
|
2011-02-08 07:18:18 +00:00
|
|
|
let chromeObject = {
|
2010-11-17 20:20:20 +00:00
|
|
|
// window.console API
|
|
|
|
log: function CA_log() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("log", arguments);
|
2010-11-17 20:20:20 +00:00
|
|
|
},
|
|
|
|
info: function CA_info() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("info", arguments);
|
2010-11-17 20:20:20 +00:00
|
|
|
},
|
|
|
|
warn: function CA_warn() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("warn", arguments);
|
2010-11-17 20:20:20 +00:00
|
|
|
},
|
|
|
|
error: function CA_error() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("error", arguments);
|
2010-12-10 17:28:17 +00:00
|
|
|
},
|
2011-04-08 21:20:41 +00:00
|
|
|
debug: function CA_debug() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("debug", arguments);
|
2011-04-08 21:20:41 +00:00
|
|
|
},
|
2011-04-11 17:48:15 +00:00
|
|
|
trace: function CA_trace() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("trace", arguments);
|
2011-04-11 17:48:15 +00:00
|
|
|
},
|
2011-06-09 13:27:30 +00:00
|
|
|
// Displays an interactive listing of all the properties of an object.
|
|
|
|
dir: function CA_dir() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("dir", arguments);
|
2011-06-09 13:27:30 +00:00
|
|
|
},
|
2011-06-14 11:38:11 +00:00
|
|
|
group: function CA_group() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("group", arguments);
|
2011-06-14 11:38:11 +00:00
|
|
|
},
|
|
|
|
groupCollapsed: function CA_groupCollapsed() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("groupCollapsed", arguments);
|
2011-06-14 11:38:11 +00:00
|
|
|
},
|
|
|
|
groupEnd: function CA_groupEnd() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("groupEnd", arguments);
|
2011-06-14 11:38:11 +00:00
|
|
|
},
|
2011-06-01 06:33:22 +00:00
|
|
|
time: function CA_time() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("time", arguments);
|
2011-06-01 06:33:22 +00:00
|
|
|
},
|
|
|
|
timeEnd: function CA_timeEnd() {
|
2012-07-07 10:21:04 +00:00
|
|
|
self.queueCall("timeEnd", arguments);
|
2011-06-01 06:33:22 +00:00
|
|
|
},
|
2012-07-12 20:04:37 +00:00
|
|
|
profile: function CA_profile() {
|
|
|
|
// Send a notification picked up by the profiler if installed.
|
|
|
|
// This must happen right away otherwise we will miss samples
|
|
|
|
let consoleEvent = {
|
|
|
|
action: "profile",
|
|
|
|
arguments: arguments
|
|
|
|
};
|
|
|
|
consoleEvent.wrappedJSObject = consoleEvent;
|
|
|
|
Services.obs.notifyObservers(consoleEvent, "console-api-profiler",
|
|
|
|
null);
|
|
|
|
},
|
|
|
|
profileEnd: function CA_profileEnd() {
|
|
|
|
// Send a notification picked up by the profiler if installed.
|
|
|
|
// This must happen right away otherwise we will miss samples
|
|
|
|
let consoleEvent = {
|
|
|
|
action: "profileEnd",
|
|
|
|
arguments: arguments
|
|
|
|
};
|
|
|
|
consoleEvent.wrappedJSObject = consoleEvent;
|
|
|
|
Services.obs.notifyObservers(consoleEvent, "console-api-profiler",
|
|
|
|
null);
|
|
|
|
},
|
2011-02-08 07:18:18 +00:00
|
|
|
__exposedProps__: {
|
|
|
|
log: "r",
|
|
|
|
info: "r",
|
|
|
|
warn: "r",
|
2011-04-08 21:20:41 +00:00
|
|
|
error: "r",
|
|
|
|
debug: "r",
|
2011-04-11 17:48:15 +00:00
|
|
|
trace: "r",
|
2011-06-14 11:38:11 +00:00
|
|
|
dir: "r",
|
|
|
|
group: "r",
|
|
|
|
groupCollapsed: "r",
|
2011-06-01 06:33:22 +00:00
|
|
|
groupEnd: "r",
|
|
|
|
time: "r",
|
2012-07-12 20:04:37 +00:00
|
|
|
timeEnd: "r",
|
|
|
|
profile: "r",
|
|
|
|
profileEnd: "r"
|
2011-02-08 07:18:18 +00:00
|
|
|
}
|
2010-11-17 20:20:20 +00:00
|
|
|
};
|
2011-02-08 07:18:18 +00:00
|
|
|
|
|
|
|
// We need to return an actual content object here, instead of a wrapped
|
|
|
|
// chrome object. This allows things like console.log.bind() to work.
|
2011-05-03 20:43:08 +00:00
|
|
|
let contentObj = Cu.createObjectIn(aWindow);
|
|
|
|
function genPropDesc(fun) {
|
|
|
|
return { enumerable: true, configurable: true, writable: true,
|
|
|
|
value: chromeObject[fun].bind(chromeObject) };
|
|
|
|
}
|
|
|
|
const properties = {
|
|
|
|
log: genPropDesc('log'),
|
|
|
|
info: genPropDesc('info'),
|
|
|
|
warn: genPropDesc('warn'),
|
|
|
|
error: genPropDesc('error'),
|
|
|
|
debug: genPropDesc('debug'),
|
|
|
|
trace: genPropDesc('trace'),
|
2011-06-09 13:27:30 +00:00
|
|
|
dir: genPropDesc('dir'),
|
2011-06-14 11:38:11 +00:00
|
|
|
group: genPropDesc('group'),
|
|
|
|
groupCollapsed: genPropDesc('groupCollapsed'),
|
|
|
|
groupEnd: genPropDesc('groupEnd'),
|
2011-06-01 06:33:22 +00:00
|
|
|
time: genPropDesc('time'),
|
|
|
|
timeEnd: genPropDesc('timeEnd'),
|
2012-07-12 20:04:37 +00:00
|
|
|
profile: genPropDesc('profile'),
|
|
|
|
profileEnd: genPropDesc('profileEnd'),
|
2011-05-03 20:43:08 +00:00
|
|
|
__noSuchMethod__: { enumerable: true, configurable: true, writable: true,
|
|
|
|
value: function() {} },
|
|
|
|
__mozillaConsole__: { value: true }
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperties(contentObj, properties);
|
|
|
|
Cu.makeObjectPropsNormal(contentObj);
|
2011-02-08 07:18:18 +00:00
|
|
|
|
2012-06-02 10:45:32 +00:00
|
|
|
this._queuedCalls = [];
|
2012-07-07 10:21:04 +00:00
|
|
|
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
this._window = Cu.getWeakReference(aWindow);
|
|
|
|
this.timerRegistry = {};
|
2012-06-02 10:45:32 +00:00
|
|
|
|
2011-05-03 20:43:08 +00:00
|
|
|
return contentObj;
|
2010-11-09 20:19:19 +00:00
|
|
|
},
|
|
|
|
|
2011-06-01 06:33:22 +00:00
|
|
|
observe: function CA_observe(aSubject, aTopic, aData)
|
|
|
|
{
|
2012-07-07 10:21:04 +00:00
|
|
|
if (aTopic == "inner-window-destroyed") {
|
2011-06-01 06:33:22 +00:00
|
|
|
let innerWindowID = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
2012-07-07 10:21:04 +00:00
|
|
|
if (innerWindowID == this._innerID) {
|
|
|
|
Services.obs.removeObserver(this, "inner-window-destroyed");
|
|
|
|
this._windowDestroyed = true;
|
|
|
|
if (!this._timerInitialized) {
|
|
|
|
this.timerRegistry = {};
|
|
|
|
}
|
|
|
|
}
|
2012-06-02 10:45:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue a call to a console method. See the CALL_DELAY constant.
|
|
|
|
*
|
|
|
|
* @param string aMethod
|
|
|
|
* The console method the code has invoked.
|
|
|
|
* @param object aArguments
|
|
|
|
* The arguments passed to the console method.
|
|
|
|
*/
|
2012-07-07 10:21:04 +00:00
|
|
|
queueCall: function CA_queueCall(aMethod, aArguments)
|
2012-06-02 10:45:32 +00:00
|
|
|
{
|
|
|
|
let metaForCall = {
|
2012-07-07 10:21:04 +00:00
|
|
|
isPrivate: PrivateBrowsingUtils.isWindowPrivate(this._window.get()),
|
2012-06-02 10:45:32 +00:00
|
|
|
timeStamp: Date.now(),
|
|
|
|
stack: this.getStackTrace(aMethod != "trace" ? 1 : null),
|
|
|
|
};
|
|
|
|
|
|
|
|
this._queuedCalls.push([aMethod, aArguments, metaForCall]);
|
|
|
|
|
|
|
|
if (!this._timerInitialized) {
|
2012-07-07 10:21:04 +00:00
|
|
|
this._timer.initWithCallback(this._timerCallback.bind(this), CALL_DELAY,
|
|
|
|
Ci.nsITimer.TYPE_REPEATING_SLACK);
|
2012-06-02 10:45:32 +00:00
|
|
|
this._timerInitialized = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer callback used to process each of the queued calls.
|
|
|
|
* @private
|
|
|
|
*/
|
2012-06-12 11:25:07 +00:00
|
|
|
_timerCallback: function CA__timerCallback()
|
2012-06-02 10:45:32 +00:00
|
|
|
{
|
2012-06-12 11:25:07 +00:00
|
|
|
this._queuedCalls.splice(0, MESSAGES_IN_INTERVAL)
|
|
|
|
.forEach(this._processQueuedCall, this);
|
|
|
|
|
|
|
|
if (!this._queuedCalls.length) {
|
|
|
|
this._timerInitialized = false;
|
2012-07-07 10:21:04 +00:00
|
|
|
this._timer.cancel();
|
|
|
|
|
|
|
|
if (this._windowDestroyed) {
|
|
|
|
ConsoleAPIStorage.clearEvents(this._innerID);
|
|
|
|
this.timerRegistry = {};
|
|
|
|
}
|
2012-06-12 11:25:07 +00:00
|
|
|
}
|
2012-06-02 10:45:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a queued call to a console method.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param array aCall
|
|
|
|
* Array that holds information about the queued call.
|
|
|
|
*/
|
|
|
|
_processQueuedCall: function CA__processQueuedItem(aCall)
|
|
|
|
{
|
|
|
|
let [method, args, meta] = aCall;
|
|
|
|
|
|
|
|
let notifyMeta = {
|
2012-04-24 15:52:11 +00:00
|
|
|
isPrivate: meta.isPrivate,
|
2012-06-02 10:45:32 +00:00
|
|
|
timeStamp: meta.timeStamp,
|
|
|
|
frame: meta.stack[0],
|
|
|
|
};
|
|
|
|
|
|
|
|
let notifyArguments = null;
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
case "log":
|
|
|
|
case "info":
|
|
|
|
case "warn":
|
|
|
|
case "error":
|
|
|
|
case "debug":
|
|
|
|
notifyArguments = this.processArguments(args);
|
|
|
|
break;
|
|
|
|
case "trace":
|
|
|
|
notifyArguments = meta.stack;
|
|
|
|
break;
|
|
|
|
case "group":
|
|
|
|
case "groupCollapsed":
|
|
|
|
notifyArguments = this.beginGroup(args);
|
|
|
|
break;
|
|
|
|
case "groupEnd":
|
|
|
|
case "dir":
|
|
|
|
notifyArguments = args;
|
|
|
|
break;
|
|
|
|
case "time":
|
2012-07-07 10:21:04 +00:00
|
|
|
notifyArguments = this.startTimer(args[0], meta.timeStamp);
|
2012-06-02 10:45:32 +00:00
|
|
|
break;
|
|
|
|
case "timeEnd":
|
2012-07-07 10:21:04 +00:00
|
|
|
notifyArguments = this.stopTimer(args[0], meta.timeStamp);
|
2012-06-02 10:45:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// unknown console API method!
|
|
|
|
return;
|
2011-06-01 06:33:22 +00:00
|
|
|
}
|
2012-06-02 10:45:32 +00:00
|
|
|
|
|
|
|
this.notifyObservers(method, notifyArguments, notifyMeta);
|
2011-06-01 06:33:22 +00:00
|
|
|
},
|
|
|
|
|
2010-11-09 20:19:19 +00:00
|
|
|
/**
|
2011-08-24 20:34:16 +00:00
|
|
|
* Notify all observers of any console API call.
|
|
|
|
*
|
|
|
|
* @param string aLevel
|
|
|
|
* The message level.
|
|
|
|
* @param mixed aArguments
|
|
|
|
* The arguments given to the console API call.
|
2012-06-02 10:45:32 +00:00
|
|
|
* @param object aMeta
|
|
|
|
* Object that holds metadata about the console API call:
|
2012-04-24 15:52:11 +00:00
|
|
|
* - isPrivate - Whether the window is in private browsing mode.
|
2012-06-02 10:45:32 +00:00
|
|
|
* - frame - the youngest content frame in the call stack.
|
|
|
|
* - timeStamp - when the console API call occurred.
|
|
|
|
*/
|
|
|
|
notifyObservers: function CA_notifyObservers(aLevel, aArguments, aMeta) {
|
2010-11-09 20:19:19 +00:00
|
|
|
let consoleEvent = {
|
2012-07-07 10:21:04 +00:00
|
|
|
ID: this._outerID,
|
|
|
|
innerID: this._innerID,
|
2010-11-09 20:19:19 +00:00
|
|
|
level: aLevel,
|
2012-06-02 10:45:32 +00:00
|
|
|
filename: aMeta.frame.filename,
|
|
|
|
lineNumber: aMeta.frame.lineNumber,
|
|
|
|
functionName: aMeta.frame.functionName,
|
2012-01-11 10:51:49 +00:00
|
|
|
arguments: aArguments,
|
2012-06-02 10:45:32 +00:00
|
|
|
timeStamp: aMeta.timeStamp,
|
2010-11-09 20:19:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
consoleEvent.wrappedJSObject = consoleEvent;
|
|
|
|
|
2012-04-24 15:52:11 +00:00
|
|
|
// Store non-private messages for which the inner window was not destroyed.
|
2012-07-07 10:21:04 +00:00
|
|
|
if (!aMeta.isPrivate) {
|
|
|
|
ConsoleAPIStorage.recordEvent(this._innerID, consoleEvent);
|
2012-06-02 10:45:32 +00:00
|
|
|
}
|
2011-08-24 20:34:16 +00:00
|
|
|
|
2012-06-02 10:45:32 +00:00
|
|
|
Services.obs.notifyObservers(consoleEvent, "console-api-log-event",
|
2012-07-07 10:21:04 +00:00
|
|
|
this._outerID);
|
2011-04-11 17:48:15 +00:00
|
|
|
},
|
|
|
|
|
2011-09-15 18:20:22 +00:00
|
|
|
/**
|
|
|
|
* Process the console API call arguments in order to perform printf-like
|
|
|
|
* string substitution.
|
|
|
|
* TODO: object substitution should display an interactive property list (bug
|
|
|
|
* 685815) and width and precision qualifiers should be taken into account
|
|
|
|
* (bug 685813).
|
|
|
|
*
|
|
|
|
* @param mixed aArguments
|
|
|
|
* The arguments given to the console API call.
|
|
|
|
**/
|
|
|
|
processArguments: function CA_processArguments(aArguments) {
|
2012-06-02 10:45:32 +00:00
|
|
|
if (aArguments.length < 2 || typeof aArguments[0] != "string") {
|
2011-09-15 18:20:22 +00:00
|
|
|
return aArguments;
|
|
|
|
}
|
|
|
|
let args = Array.prototype.slice.call(aArguments);
|
|
|
|
let format = args.shift();
|
|
|
|
// Format specification regular expression.
|
2012-06-02 10:45:32 +00:00
|
|
|
let processed = format.replace(ARGUMENT_PATTERN, function CA_PA_substitute(match, submatch) {
|
|
|
|
switch (submatch) {
|
2011-09-15 18:20:22 +00:00
|
|
|
case "o":
|
|
|
|
case "s":
|
2011-10-07 12:29:33 +00:00
|
|
|
return String(args.shift());
|
2011-09-15 18:20:22 +00:00
|
|
|
case "d":
|
|
|
|
case "i":
|
|
|
|
return parseInt(args.shift());
|
|
|
|
case "f":
|
|
|
|
return parseFloat(args.shift());
|
|
|
|
default:
|
2012-06-02 10:45:32 +00:00
|
|
|
return submatch;
|
2011-09-15 18:20:22 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
args.unshift(processed);
|
|
|
|
return args;
|
|
|
|
},
|
|
|
|
|
2011-04-11 17:48:15 +00:00
|
|
|
/**
|
|
|
|
* Build the stacktrace array for the console.trace() call.
|
|
|
|
*
|
2012-06-02 10:45:32 +00:00
|
|
|
* @param number [aMaxDepth=DEFAULT_MAX_STACKTRACE_DEPTH]
|
|
|
|
* Optional maximum stacktrace depth.
|
2011-04-11 17:48:15 +00:00
|
|
|
* @return array
|
|
|
|
* Each element is a stack frame that holds the following properties:
|
|
|
|
* filename, lineNumber, functionName and language.
|
2012-06-02 10:45:32 +00:00
|
|
|
*/
|
|
|
|
getStackTrace: function CA_getStackTrace(aMaxDepth) {
|
|
|
|
if (!aMaxDepth) {
|
|
|
|
aMaxDepth = DEFAULT_MAX_STACKTRACE_DEPTH;
|
|
|
|
}
|
|
|
|
|
2011-04-11 17:48:15 +00:00
|
|
|
let stack = [];
|
2012-06-02 10:45:32 +00:00
|
|
|
let frame = Components.stack.caller.caller;
|
2011-04-11 17:48:15 +00:00
|
|
|
while (frame = frame.caller) {
|
|
|
|
if (frame.language == Ci.nsIProgrammingLanguage.JAVASCRIPT ||
|
|
|
|
frame.language == Ci.nsIProgrammingLanguage.JAVASCRIPT2) {
|
|
|
|
stack.push({
|
|
|
|
filename: frame.filename,
|
|
|
|
lineNumber: frame.lineNumber,
|
|
|
|
functionName: frame.name,
|
|
|
|
language: frame.language,
|
|
|
|
});
|
2012-06-02 10:45:32 +00:00
|
|
|
if (stack.length == aMaxDepth) {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 17:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
2011-06-14 11:38:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Begin a new group for logging output together.
|
|
|
|
**/
|
|
|
|
beginGroup: function CA_beginGroup() {
|
|
|
|
return Array.prototype.join.call(arguments[0], " ");
|
2011-06-01 06:33:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2012-07-07 10:21:04 +00:00
|
|
|
* A registry of started timers. Timer maps are key-value pairs of timer
|
|
|
|
* names to timer start times, for all timers defined in the page. Timer
|
2011-06-01 06:33:22 +00:00
|
|
|
* names are prepended with the inner window ID in order to avoid conflicts
|
|
|
|
* with Object.prototype functions.
|
|
|
|
*/
|
2012-07-07 10:21:04 +00:00
|
|
|
timerRegistry: null,
|
2011-06-01 06:33:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new timer by recording the current time under the specified name.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The name of the timer.
|
2012-06-02 10:45:32 +00:00
|
|
|
* @param number [aTimestamp=Date.now()]
|
|
|
|
* Optional timestamp that tells when the timer was originally started.
|
2011-06-01 06:33:22 +00:00
|
|
|
* @return object
|
|
|
|
* The name property holds the timer name and the started property
|
|
|
|
* holds the time the timer was started. In case of error, it returns
|
|
|
|
* an object with the single property "error" that contains the key
|
|
|
|
* for retrieving the localized error message.
|
|
|
|
**/
|
2012-07-07 10:21:04 +00:00
|
|
|
startTimer: function CA_startTimer(aName, aTimestamp) {
|
2011-06-01 06:33:22 +00:00
|
|
|
if (!aName) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-07 10:21:04 +00:00
|
|
|
if (Object.keys(this.timerRegistry).length > MAX_PAGE_TIMERS - 1) {
|
2011-06-01 06:33:22 +00:00
|
|
|
return { error: "maxTimersExceeded" };
|
|
|
|
}
|
2012-07-07 10:21:04 +00:00
|
|
|
let key = this._innerID + "-" + aName.toString();
|
|
|
|
if (!(key in this.timerRegistry)) {
|
|
|
|
this.timerRegistry[key] = aTimestamp || Date.now();
|
2011-06-01 06:33:22 +00:00
|
|
|
}
|
2012-07-07 10:21:04 +00:00
|
|
|
return { name: aName, started: this.timerRegistry[key] };
|
2011-06-01 06:33:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the timer with the specified name and retrieve the elapsed time.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The name of the timer.
|
2012-06-02 10:45:32 +00:00
|
|
|
* @param number [aTimestamp=Date.now()]
|
|
|
|
* Optional timestamp that tells when the timer was originally stopped.
|
2011-06-01 06:33:22 +00:00
|
|
|
* @return object
|
|
|
|
* The name property holds the timer name and the duration property
|
|
|
|
* holds the number of milliseconds since the timer was started.
|
|
|
|
**/
|
2012-07-07 10:21:04 +00:00
|
|
|
stopTimer: function CA_stopTimer(aName, aTimestamp) {
|
2011-06-01 06:33:22 +00:00
|
|
|
if (!aName) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-07 10:21:04 +00:00
|
|
|
let key = this._innerID + "-" + aName.toString();
|
|
|
|
if (!(key in this.timerRegistry)) {
|
2011-06-01 06:33:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-07 10:21:04 +00:00
|
|
|
let duration = (aTimestamp || Date.now()) - this.timerRegistry[key];
|
|
|
|
delete this.timerRegistry[key];
|
2011-06-01 06:33:22 +00:00
|
|
|
return { name: aName, duration: duration };
|
2011-05-12 12:29:17 +00:00
|
|
|
}
|
2010-11-09 20:19:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let NSGetFactory = XPCOMUtils.generateNSGetFactory([ConsoleAPI]);
|