Bug 122213 - Display time and date of messages in toolkit's Error Console. r=neil sr=bz

This commit is contained in:
aceman 2011-12-17 05:22:26 +01:00
parent 067bb8a581
commit c475fda161
5 changed files with 42 additions and 17 deletions

View File

@ -43,7 +43,7 @@
#include "nsISupports.idl"
#include "nsIConsoleMessage.idl"
[scriptable, uuid(b0196fc7-1913-441a-882a-453c0d8b89b8)]
[scriptable, uuid(537ff844-c325-4047-92f5-e1c292d108bc)]
interface nsIScriptError : nsIConsoleMessage
{
/** pseudo-flag for default case */
@ -81,6 +81,15 @@ interface nsIScriptError : nsIConsoleMessage
*/
readonly attribute string category;
/*
The time (in milliseconds from the Epoch) that the script error instance
was initialised, and thus the time when the error occurred.
Currently used to display date and time of the message in Error console.
The timestamp is initialized as JS_now/1000 so that it can be
compared to Date.now in Javascript.
*/
readonly attribute long long timeStamp;
void init(in wstring message,
in wstring sourceName,
in wstring sourceLine,
@ -96,7 +105,7 @@ interface nsIScriptError : nsIConsoleMessage
* An interface that nsIScriptError objects can implement to allow
* them to be initialized with a window id.
*/
[scriptable, uuid(4472646b-c928-4d76-9e7c-6b91da7f24cc)]
[scriptable, uuid(444c5e66-a85d-4a3b-83ce-4c71882b09a3)]
interface nsIScriptError2 : nsISupports {
/* Get the window id this was initialized with. Zero will be
returned if init() was used instead of initWithWindowID(). */
@ -106,10 +115,6 @@ interface nsIScriptError2 : nsISupports {
returned if init() was used instead of initWithWindowID(). */
readonly attribute unsigned long long innerWindowID;
/* Elapsed time, in milliseconds, from a platform-specific zero time to the
time the message was created. */
readonly attribute long long timeStamp;
/* This should be called instead of nsIScriptError.init to
initialize with a window id. The window id should be for the
inner window associated with this error. */

View File

@ -155,7 +155,7 @@ nsScriptError::InitWithWindowID(const PRUnichar *message,
mColumnNumber = columnNumber;
mFlags = flags;
mCategory.Assign(category);
mTimeStamp = PR_Now() / 1000;
mTimeStamp = JS_Now() / 1000;
mInnerWindowID = aInnerWindowID;
if (aInnerWindowID) {

View File

@ -3965,7 +3965,7 @@ private:
nsCString mCategory;
PRUint64 mOuterWindowID;
PRUint64 mInnerWindowID;
PRUint64 mTimeStamp;
PRInt64 mTimeStamp;
};
/***************************************************************************/

View File

@ -177,6 +177,7 @@
row.setAttribute("type", warning ? "warning" : "error");
row.setAttribute("msg", aObject.errorMessage);
row.setAttribute("category", aObject.category);
row.setAttribute("time", this.properFormatTime(aObject.timeStamp));
if (aObject.lineNumber || aObject.sourceName) {
row.setAttribute("href", aObject.sourceName);
row.setAttribute("line", aObject.lineNumber);
@ -217,7 +218,19 @@
this.mCService.reset();
]]></body>
</method>
<method name="properFormatTime">
<parameter name="aTime"/>
<body><![CDATA[
const dateServ = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
.getService(Components.interfaces.nsIScriptableDateFormat);
let errorTime = new Date(aTime);
return dateServ.FormatDateTime("", dateServ.dateFormatShort, dateServ.timeFormatSeconds,
errorTime.getFullYear(), errorTime.getMonth() + 1, errorTime.getDate(),
errorTime.getHours(), errorTime.getMinutes(), errorTime.getSeconds());
]]></body>
</method>
<method name="copySelectedItem">
<body><![CDATA[
if (this.mSelectedItem) try {
@ -340,6 +353,9 @@
<xul:image class="console-icon" xbl:inherits="src,type"/>
</xul:box>
<xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
<xul:box class="console-row-time">
<xul:label class="label" xbl:inherits="value=time"/>
</xul:box>
<xul:box class="console-row-msg" align="start">
<xul:label class="label" xbl:inherits="value=typetext"/>
<xul:description class="console-error-msg" xbl:inherits="xbl:text=msg" flex="1"/>
@ -366,15 +382,18 @@
</content>
<implementation>
<method name="toString">
<body><![CDATA[
var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
var strBundle = this._ConsoleBox.mStrBundle;
let msg = "";
let strBundle = this._ConsoleBox.mStrBundle;
if (this.hasAttribute("time"))
msg += strBundle.getFormattedString("errTime", [this.getAttribute("time")]) + "\n";
msg += this.getAttribute("typetext") + " " + this.getAttribute("msg");
if (this.hasAttribute("line") && this.hasAttribute("href")) {
msg += "\n" + strBundle.getFormattedString("errFile",
msg += "\n" + strBundle.getFormattedString("errFile",
[this.getAttribute("href")]) + "\n";
if (this.hasAttribute("col")) {
msg += strBundle.getFormattedString("errLineCol",
@ -382,10 +401,10 @@
} else
msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
}
if (this.hasAttribute("code"))
msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
return msg;
]]></body>
</method>

View File

@ -4,3 +4,4 @@ errFile=Source File: %S
errLine=Line: %S
errLineCol=Line: %S, Column: %S
errCode=Source Code:
errTime=Timestamp: %S