Bug 1558298: Part 9 - Make MozillaLogger.js less insane. r=nika
☠☠ backed out by f9bf5e4b0b4f ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Tue, 11 Jun 2019 11:28:47 -0700
changeset 540531 0f6b382f06261055566d91b84866a51a80e474bd
parent 540530 6ccaa25367f28c27c27746593db3bd5cfaed5f57
child 540532 fddf2808fedf7ca16097af3b5c7c46ed44fc2053
push id11529
push userarchaeopteryx@coole-files.de
push dateThu, 04 Jul 2019 15:22:33 +0000
treeherdermozilla-beta@ebb510a784b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1558298
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1558298: Part 9 - Make MozillaLogger.js less insane. r=nika Differential Revision: https://phabricator.services.mozilla.com/D34598
testing/mochitest/tests/SimpleTest/setup.js
testing/specialpowers/content/MozillaLogger.js
--- a/testing/mochitest/tests/SimpleTest/setup.js
+++ b/testing/mochitest/tests/SimpleTest/setup.js
@@ -122,17 +122,17 @@ if (params.failureFile) {
 // Breaks execution and enters the JS debugger on a test failure
 if (params.debugOnFailure) {
   TestRunner.debugOnFailure = true;
 }
 
 // logFile to write our results
 if (params.logFile) {
   var spl = new SpecialPowersLogger(params.logFile);
-  TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback());
+  TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.logCallback);
 }
 
 // A temporary hack for android 4.0 where Fennec utilizes the pandaboard so much it reboots
 if (params.runSlower) {
   TestRunner.runSlower = true;
 }
 
 if (params.dumpOutputDirectory) {
--- a/testing/specialpowers/content/MozillaLogger.js
+++ b/testing/specialpowers/content/MozillaLogger.js
@@ -1,135 +1,114 @@
 /**
  * MozillaLogger, a base class logger that just logs to stdout.
  */
 
 "use strict";
 
 /* import-globals-from SpecialPowers.jsm */
 
-function MozillaLogger(aPath) {
-}
-
 function formatLogMessage(msg) {
-    return msg.info.join(" ") + "\n";
+  return msg.info.join(" ") + "\n";
 }
 
-MozillaLogger.prototype = {
-  init(path) {},
-
-  getLogCallback() {
-    return function(msg) {
-      var data = formatLogMessage(msg);
-      dump(data);
+class MozillaLogger {
+  get logCallback() {
+    return (msg) => {
+      this.log(formatLogMessage(msg));
     };
-  },
+  }
 
   log(msg) {
     dump(msg);
-  },
+  }
 
-  close() {},
-};
+  close() {}
+}
 
 
 /**
  * SpecialPowersLogger, inherits from MozillaLogger and utilizes SpecialPowers.
  * intented to be used in content scripts to write to a file
  */
-function SpecialPowersLogger(aPath) {
-  // Call the base constructor
-  MozillaLogger.call(this);
-  this.prototype = new MozillaLogger(aPath);
-  this.init(aPath);
-}
+class SpecialPowersLogger extends MozillaLogger {
+  constructor(aPath) {
+    super();
 
-SpecialPowersLogger.prototype = {
-  init(path) {
-    SpecialPowers.setLogFile(path);
-  },
+    SpecialPowers.setLogFile(aPath);
+  }
 
-  getLogCallback() {
-    return function(msg) {
+  get logCallback() {
+    return (msg) => {
       var data = formatLogMessage(msg);
-      SpecialPowers.log(data);
+      this.log(data);
 
       if (data.includes("SimpleTest FINISH")) {
-        SpecialPowers.closeLogFile();
+        this.close();
       }
     };
-  },
+  }
 
   log(msg) {
     SpecialPowers.log(msg);
-  },
+  }
 
   close() {
     SpecialPowers.closeLogFile();
-  },
-};
+  }
+}
 
 
 /**
  * MozillaFileLogger, a log listener that can write to a local file.
  * intended to be run from chrome space
  */
 
 /** Init the file logger with the absolute path to the file.
     It will create and append if the file already exists **/
-function MozillaFileLogger(aPath) {
-  // Call the base constructor
-  MozillaLogger.call(this);
-  this.prototype = new MozillaLogger(aPath);
-  this.init(aPath);
-}
-
-MozillaFileLogger.prototype = {
+class MozillaFileLogger extends MozillaLogger {
+  constructor(aPath) {
+    super();
 
-  init(path) {
-    var PR_WRITE_ONLY   = 0x02; // Open for writing only.
-    var PR_CREATE_FILE  = 0x08;
-    var PR_APPEND       = 0x10;
-    this._file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
-    this._file.initWithPath(path);
-    this._foStream = Cc["@mozilla.org/network/file-output-stream;1"]
-                       .createInstance(Ci.nsIFileOutputStream);
-    this._foStream.init(this._file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND,
-                                     436 /* 0664 */, 0);
+    const {FileUtils} = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
+
+    this._file = FileUtils.File(aPath);
+    this._foStream = FileUtils.openFileOutputStream(
+        this._file, (FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
+                     FileUtils.MODE_APPEND));
 
     this._converter = Cc["@mozilla.org/intl/converter-output-stream;1"]
                         .createInstance(Ci.nsIConverterOutputStream);
     this._converter.init(this._foStream, "UTF-8");
-  },
+  }
 
-  getLogCallback() {
-    return function(msg) {
-      var data = formatLogMessage(msg);
-      if (MozillaFileLogger._converter) {
-        this._converter.writeString(data);
-      }
+  get logCallback() {
+    return (msg) => {
+      if (this._converter) {
+        var data = formatLogMessage(msg);
+        this.log(data);
 
-      if (data.includes("SimpleTest FINISH")) {
-        MozillaFileLogger.close();
+        if (data.includes("SimpleTest FINISH")) {
+          this.close();
+        }
       }
     };
-  },
+  }
 
   log(msg) {
     if (this._converter) {
       this._converter.writeString(msg);
     }
-  },
+  }
+
   close() {
-    if (this._converter) {
-      this._converter.flush();
-      this._converter.close();
-    }
+    this._converter.flush();
+    this._converter.close();
 
     this._foStream = null;
     this._converter = null;
     this._file = null;
-  },
-};
+  }
+}
 
 this.MozillaLogger = MozillaLogger;
 this.SpecialPowersLogger = SpecialPowersLogger;
 this.MozillaFileLogger = MozillaFileLogger;