1
0
mirror of https://github.com/moparisthebest/FireTray synced 2025-01-07 19:48:03 -05:00

Using __proto__ to set a prototype is now deprecated (FF30).

This commit is contained in:
foudfou 2014-05-30 19:35:27 +02:00
parent e8890c9ac0
commit 738c412c23
2 changed files with 151 additions and 165 deletions

View File

@ -331,13 +331,11 @@ function BasicFormatter(dateFormat) {
if (dateFormat) if (dateFormat)
this.dateFormat = dateFormat; this.dateFormat = dateFormat;
} }
BasicFormatter.prototype = { BasicFormatter.prototype = Object.create(Formatter.prototype);
__proto__: Formatter.prototype, BasicFormatter.prototype.constructor = BasicFormatter;
BasicFormatter.prototype.format = function BF_format(message) {
format: function BF_format(message) { return message.time + "\t" + message.loggerName + "\t" + message.levelDesc
return message.time + "\t" + message.loggerName + "\t" + message.levelDesc + "\t" + message.message + "\n";
+ "\t" + message.message + "\n";
}
}; };
/* /*
@ -372,12 +370,10 @@ function DumpAppender(formatter) {
this._name = "DumpAppender"; this._name = "DumpAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
DumpAppender.prototype = { DumpAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, DumpAppender.prototype.constructor = DumpAppender;
DumpAppender.prototype.doAppend = function DApp_doAppend(message) {
doAppend: function DApp_doAppend(message) { dump(message);
dump(message);
}
}; };
/* /*
@ -389,17 +385,14 @@ function ConsoleAppender(formatter) {
this._name = "ConsoleAppender"; this._name = "ConsoleAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
ConsoleAppender.prototype = { ConsoleAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, ConsoleAppender.prototype.doAppend = function CApp_doAppend(message) {
if (message.level > Log4Moz.Level.Warn) {
doAppend: function CApp_doAppend(message) { Cu.reportError(message);
if (message.level > Log4Moz.Level.Warn) { return;
Cu.reportError(message);
return;
}
Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService).logStringMessage(message);
} }
Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService).logStringMessage(message);
}; };
/** /**
@ -414,20 +407,20 @@ function BlockingStreamAppender(formatter) {
this._name = "BlockingStreamAppender"; this._name = "BlockingStreamAppender";
Appender.call(this, formatter); Appender.call(this, formatter);
} }
BlockingStreamAppender.prototype = { BlockingStreamAppender.prototype = Object.create(Appender.prototype);
__proto__: Appender.prototype, BlockingStreamAppender.prototype.constructor = BlockingStreamAppender;
BlockingStreamAppender.prototype._converterStream = null, // holds the nsIConverterOutputStream
BlockingStreamAppender.prototype._outputStream = null, // holds the underlying nsIOutputStream
_converterStream: null, // holds the nsIConverterOutputStream /**
_outputStream: null, // holds the underlying nsIOutputStream * Output stream to write to.
*
/** * This will automatically open the stream if it doesn't exist yet by
* Output stream to write to. * calling newOutputStream. The resulting raw stream is wrapped in a
* * nsIConverterOutputStream to ensure text is written as UTF-8.
* This will automatically open the stream if it doesn't exist yet by */
* calling newOutputStream. The resulting raw stream is wrapped in a Object.defineProperty(BlockingStreamAppender, "outputStream", {
* nsIConverterOutputStream to ensure text is written as UTF-8. get: function outputStream() {
*/
get outputStream() {
if (!this._outputStream) { if (!this._outputStream) {
// First create a raw stream. We can bail out early if that fails. // First create a raw stream. We can bail out early if that fails.
this._outputStream = this.newOutputStream(); this._outputStream = this.newOutputStream();
@ -439,43 +432,43 @@ BlockingStreamAppender.prototype = {
// the instance if we already have one. // the instance if we already have one.
if (!this._converterStream) { if (!this._converterStream) {
this._converterStream = Cc["@mozilla.org/intl/converter-output-stream;1"] this._converterStream = Cc["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Ci.nsIConverterOutputStream); .createInstance(Ci.nsIConverterOutputStream);
} }
this._converterStream.init( this._converterStream.init(
this._outputStream, "UTF-8", STREAM_SEGMENT_SIZE, this._outputStream, "UTF-8", STREAM_SEGMENT_SIZE,
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
} }
return this._converterStream; return this._converterStream;
}, }
});
newOutputStream: function newOutputStream() { BlockingStreamAppender.prototype.newOutputStream = function newOutputStream() {
throw "Stream-based appenders need to implement newOutputStream()!"; throw "Stream-based appenders need to implement newOutputStream()!";
}, };
reset: function reset() { BlockingStreamAppender.prototype.reset = function reset() {
if (!this._outputStream) { if (!this._outputStream) {
return; return;
} }
this.outputStream.close(); this.outputStream.close();
this._outputStream = null; this._outputStream = null;
}, };
doAppend: function doAppend(message) { BlockingStreamAppender.prototype.doAppend = function doAppend(message) {
if (!message) { if (!message) {
return; return;
} }
try { try {
this.outputStream.writeString(message); this.outputStream.writeString(message);
} catch(ex) { } catch(ex) {
if (ex.result == Cr.NS_BASE_STREAM_CLOSED) { if (ex.result == Cr.NS_BASE_STREAM_CLOSED) {
// The underlying output stream is closed, so let's open a new one // The underlying output stream is closed, so let's open a new one
// and try again. // and try again.
this._outputStream = null; this._outputStream = null;
try { try {
this.outputStream.writeString(message); this.outputStream.writeString(message);
} catch (ex) { } catch (ex) {
// Ah well, we tried, but something seems to be hosed permanently. // Ah well, we tried, but something seems to be hosed permanently.
}
} }
} }
} }
@ -493,28 +486,27 @@ function StorageStreamAppender(formatter) {
this._name = "StorageStreamAppender"; this._name = "StorageStreamAppender";
BlockingStreamAppender.call(this, formatter); BlockingStreamAppender.call(this, formatter);
} }
StorageStreamAppender.prototype = { StorageStreamAppender.prototype = Object.create(BlockingStreamAppender.prototype);
__proto__: BlockingStreamAppender.prototype, StorageStreamAppender.prototype.constructor = StorageStreamAppender;
_ss: null, StorageStreamAppender.prototype._ss = null,
newOutputStream: function newOutputStream() { StorageStreamAppender.prototype.newOutputStream = function newOutputStream() {
let ss = this._ss = Cc["@mozilla.org/storagestream;1"] let ss = this._ss = Cc["@mozilla.org/storagestream;1"]
.createInstance(Ci.nsIStorageStream); .createInstance(Ci.nsIStorageStream);
ss.init(STREAM_SEGMENT_SIZE, PR_UINT32_MAX, null); ss.init(STREAM_SEGMENT_SIZE, PR_UINT32_MAX, null);
return ss.getOutputStream(0); return ss.getOutputStream(0);
}, };
getInputStream: function getInputStream() { StorageStreamAppender.prototype.getInputStream = function getInputStream() {
if (!this._ss) { if (!this._ss) {
return null; return null;
}
return this._ss.newInputStream(0);
},
reset: function reset() {
BlockingStreamAppender.prototype.reset.call(this);
this._ss = null;
} }
return this._ss.newInputStream(0);
};
StorageStreamAppender.prototype.reset = function reset() {
BlockingStreamAppender.prototype.reset.call(this);
this._ss = null;
}; };
/** /**
@ -529,24 +521,23 @@ function FileAppender(file, formatter) {
this._file = file; // nsIFile this._file = file; // nsIFile
BlockingStreamAppender.call(this, formatter); BlockingStreamAppender.call(this, formatter);
} }
FileAppender.prototype = { FileAppender.prototype = Object.create(BlockingStreamAppender.prototype);
__proto__: BlockingStreamAppender.prototype, FileAppender.prototype.constructor = FileAppender;
newOutputStream: function newOutputStream() { FileAppender.prototype.newOutputStream = function newOutputStream() {
try { try {
return FileUtils.openFileOutputStream(this._file); return FileUtils.openFileOutputStream(this._file);
} catch(e) { } catch(e) {
return null; return null;
} }
}, };
reset: function reset() { FileAppender.prototype.reset = function reset() {
BlockingStreamAppender.prototype.reset.call(this); BlockingStreamAppender.prototype.reset.call(this);
try { try {
this._file.remove(false); this._file.remove(false);
} catch (e) { } catch (e) {
// File didn't exist in the first place, or we're on Windows. Meh. // File didn't exist in the first place, or we're on Windows. Meh.
}
} }
}; };
@ -567,38 +558,37 @@ function RotatingFileAppender(file, formatter, maxSize, maxBackups) {
this._maxSize = maxSize; this._maxSize = maxSize;
this._maxBackups = maxBackups; this._maxBackups = maxBackups;
} }
RotatingFileAppender.prototype = { RotatingFileAppender.prototype = Object.create(FileAppender.prototype);
__proto__: FileAppender.prototype, RotatingFileAppender.prototype.constructor = RotatingFileAppender;
doAppend: function doAppend(message) { RotatingFileAppender.prototype.doAppend = function doAppend(message) {
FileAppender.prototype.doAppend.call(this, message); FileAppender.prototype.doAppend.call(this, message);
try { try {
this.rotateLogs(); this.rotateLogs();
} catch(e) { } catch(e) {
dump("Error writing file:" + e + "\n"); dump("Error writing file:" + e + "\n");
}
},
rotateLogs: function rotateLogs() {
if (this._file.exists() && this._file.fileSize < this._maxSize) {
return;
}
BlockingStreamAppender.prototype.reset.call(this);
for (let i = this.maxBackups - 1; i > 0; i--) {
let backup = this._file.parent.clone();
backup.append(this._file.leafName + "." + i);
if (backup.exists()) {
backup.moveTo(this._file.parent, this._file.leafName + "." + (i + 1));
}
}
let cur = this._file.clone();
if (cur.exists()) {
cur.moveTo(cur.parent, cur.leafName + ".1");
}
// Note: this._file still points to the same file
} }
}; };
RotatingFileAppender.prototype.rotateLogs = function rotateLogs() {
if (this._file.exists() && this._file.fileSize < this._maxSize) {
return;
}
BlockingStreamAppender.prototype.reset.call(this);
for (let i = this.maxBackups - 1; i > 0; i--) {
let backup = this._file.parent.clone();
backup.append(this._file.leafName + "." + i);
if (backup.exists()) {
backup.moveTo(this._file.parent, this._file.leafName + "." + (i + 1));
}
}
let cur = this._file.clone();
if (cur.exists()) {
cur.moveTo(cur.parent, cur.leafName + ".1");
}
// Note: this._file still points to the same file
};

View File

@ -85,46 +85,42 @@ firetray.Logging = {
setupLogging: function(loggerName) { setupLogging: function(loggerName) {
// lifted from log4moz.js // lifted from log4moz.js
function SimpleFormatter() {} function SimpleFormatter() {LogMod.Formatter.call(this);}
SimpleFormatter.prototype = { SimpleFormatter.prototype = Object.create(LogMod.Formatter.prototype);
__proto__: LogMod.Formatter.prototype, SimpleFormatter.prototype.constructor = SimpleFormatter;
SimpleFormatter.prototype.format = function(message) {
let messageString = "";
if (message.hasOwnProperty("message"))
messageString = message.message;
else
// The trick below prevents errors further down because mo is null or
// undefined.
messageString = [
("" + mo) for each
([,mo] in Iterator(message.messageObjects))].join(" ");
format: function(message) { let date = new Date(message.time);
let messageString = ""; let dateStr = date.getHours() + ":" + date.getMinutes() + ":" +
if (message.hasOwnProperty("message")) date.getSeconds() + "." + date.getMilliseconds();
messageString = message.message; let stringLog = dateStr + " " +
else message.levelDesc + " " + message.loggerName + " " +
// The trick below prevents errors further down because mo is null or messageString + "\n";
// undefined.
messageString = [
("" + mo) for each
([,mo] in Iterator(message.messageObjects))].join(" ");
let date = new Date(message.time); if (message.exception)
let dateStr = date.getHours() + ":" + date.getMinutes() + ":" + stringLog += message.stackTrace + "\n";
date.getSeconds() + "." + date.getMilliseconds();
let stringLog = dateStr + " " +
message.levelDesc + " " + message.loggerName + " " +
messageString + "\n";
if (message.exception) return stringLog;
stringLog += message.stackTrace + "\n";
return stringLog;
}
}; };
function ColorTermFormatter() {} function ColorTermFormatter() {SimpleFormatter.call(this);}
ColorTermFormatter.prototype = { ColorTermFormatter.prototype = Object.create(SimpleFormatter.prototype);
__proto__: SimpleFormatter.prototype, ColorTermFormatter.prototype.constructor = ColorTermFormatter;
ColorTermFormatter.prototype.format = function(message) {
let color = colorTermLogColors[message.levelDesc];
let stringLog = SimpleFormatter.prototype.format.call(this, message);
stringLog = color + stringLog + COLOR_RESET;
format: function(message) { return stringLog;
let color = colorTermLogColors[message.levelDesc];
let stringLog = SimpleFormatter.prototype.format.call(this, message);
stringLog = color + stringLog + COLOR_RESET;
return stringLog;
}
}; };
// Loggers are hierarchical, affiliation is handled by a '.' in the name. // Loggers are hierarchical, affiliation is handled by a '.' in the name.