Bug 1360293 - Enable the Mozilla ESlint recommended rules for tools/. r?njn
MozReview-Commit-ID: JMcgZ9taEV5
new file mode 100644
--- /dev/null
+++ b/tools/.eslintrc.js
@@ -0,0 +1,11 @@
+"use strict";
+
+module.exports = {
+ extends: [
+ "plugin:mozilla/recommended"
+ ],
+
+ plugins: [
+ "mozilla"
+ ]
+}
--- a/tools/leak-gauge/leak-gauge.html
+++ b/tools/leak-gauge/leak-gauge.html
@@ -16,79 +16,75 @@ pre { margin: 0; }
pre.output { border: medium solid; padding: 1em; margin: 1em; }
</style>
<script type="text/javascript">
function runfile(file) {
var result = "Results of processing log " + file.fileName + " :\n";
var fileReader = new FileReader();
- fileReader.onload = function(e)
- {
+ fileReader.onload = function(e) {
runContents(result, e.target.result);
}
fileReader.readAsText(file, "iso-8859-1");
}
function runContents(result, contents) {
// A hash of objects (keyed by the first word of the line in the log)
// that have two public methods, handle_line and dump (to be called using
// call, above), along with any private data they need.
var handlers = {
"DOMWINDOW": {
count: 0,
windows: {},
- handle_line: function(line) {
+ handle_line(line) {
var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
if (match) {
var addr = match[1];
var verb = match[2];
var rest = match[3];
if (verb == "created") {
- var m = rest.match(/ outer=([0-9a-f]*)$/);
+ let m = rest.match(/ outer=([0-9a-f]*)$/);
if (!m)
throw "outer expected";
this.windows[addr] = { outer: m[1] };
++this.count;
} else if (verb == "destroyed") {
delete this.windows[addr];
} else if (verb == "SetNewDocument") {
- var m = rest.match(/^ (.*)$/);
+ let m = rest.match(/^ (.*)$/);
if (!m)
throw "URI expected";
this.windows[addr][m[1]] = true;
}
}
},
- dump: function() {
+ dump() {
for (var addr in this.windows) {
var winobj = this.windows[addr];
var outer = winobj.outer;
delete winobj.outer;
result += "Leaked " + (outer == "0" ? "outer" : "inner") +
" window " + addr + " " +
(outer == "0" ? "" : "(outer " + outer + ") ") +
"at address " + addr + ".\n";
for (var uri in winobj) {
result += " ... with URI \"" + uri + "\".\n";
}
}
},
- summary: function() {
- var len = 0;
- for (var w in this.windows)
- ++len;
- result += 'Leaked ' + len + ' out of ' +
+ summary() {
+ result += "Leaked " + Object.keys(this.windows).length + " out of " +
this.count + " DOM Windows\n";
}
},
"DOCUMENT": {
count: 0,
docs: {},
- handle_line: function(line) {
+ handle_line(line) {
var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
if (match) {
var addr = match[1];
var verb = match[2];
var rest = match[3];
if (verb == "created") {
this.docs[addr] = {};
++this.count;
@@ -103,39 +99,36 @@ function runContents(result, contents) {
var doc_info = this.docs[addr];
doc_info[uri] = true;
if ("nim" in doc_info) {
doc_info["nim"][uri] = true;
}
}
}
},
- dump: function() {
+ dump() {
for (var addr in this.docs) {
var doc = this.docs[addr];
result += "Leaked document at address " + addr + ".\n";
for (var uri in doc) {
if (uri != "nim") {
result += " ... with URI \"" + uri + "\".\n";
}
}
}
},
- summary: function() {
- var len = 0;
- for (var w in this.docs)
- ++len;
- result += 'Leaked ' + len + ' out of ' +
+ summary() {
+ result += "Leaked " + Object.keys(this.docs).length + " out of " +
this.count + " documents\n";
}
},
"DOCSHELL": {
count: 0,
shells: {},
- handle_line: function(line) {
+ handle_line(line) {
var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
if (match) {
var addr = match[1];
var verb = match[2];
var rest = match[3];
if (verb == "created") {
this.shells[addr] = {};
++this.count;
@@ -145,37 +138,34 @@ function runContents(result, contents) {
verb == "SetCurrentURI") {
var m = rest.match(/^ (.*)$/);
if (!m)
throw "URI expected";
this.shells[addr][m[1]] = true;
}
}
},
- dump: function() {
+ dump() {
for (var addr in this.shells) {
var doc = this.shells[addr];
result += "Leaked docshell at address " + addr + ".\n";
for (var uri in doc) {
result += " ... which loaded URI \"" + uri + "\".\n";
}
}
},
- summary: function() {
- var len = 0;
- for (var w in this.shells)
- ++len;
- result += 'Leaked ' + len + ' out of ' +
+ summary() {
+ result += "Leaked " + Object.keys(this.shells).length + " out of " +
this.count + " docshells\n";
}
},
"NODEINFOMANAGER": {
count: 0,
nims: {},
- handle_line: function(line) {
+ handle_line(line) {
var match = line.match(/^([0-9a-f]*) (\S*)(.*)/);
if (match) {
var addr = match[1];
var verb = match[2];
var rest = match[3];
if (verb == "created") {
this.nims[addr] = {};
++this.count;
@@ -192,56 +182,53 @@ function runContents(result, contents) {
for (var uri in doc_info) {
nim_info[uri] = true;
}
doc_info["nim"] = nim_info;
}
}
}
},
- dump: function() {
+ dump() {
for (var addr in this.nims) {
var nim = this.nims[addr];
result += "Leaked content nodes associated with node info manager at address " + addr + ".\n";
for (var uri in nim) {
result += " ... with document URI \"" + uri + "\".\n";
}
}
},
- summary: function() {
- var len = 0;
- for (var w in this.nims)
- ++len;
- result += 'Leaked content nodes in ' + len + ' out of ' +
+ summary() {
+ result += "Leaked content nodes in " + Object.keys(this.nims).length + " out of " +
this.count + " documents\n";
}
}
};
var lines = contents.split(/[\r\n]+/);
for (var j in lines) {
var line = lines[j];
// strip off initial "-", thread id, and thread pointer; separate
// first word and rest
var matches = line.match(/^\-?[0-9]*\[[0-9a-f]*\]: (\S*) (.*)$/);
if (matches) {
- var handler = matches[1];
+ let handler = matches[1];
var data = matches[2];
if (typeof(handlers[handler]) != "undefined") {
handlers[handler].handle_line(data);
}
}
}
- for (var handler in handlers)
+ for (let handler in handlers)
handlers[handler].dump();
if (result.length)
result += "\n";
result += "Summary:\n";
- for (var handler in handlers)
+ for (let handler in handlers)
handlers[handler].summary();
result += "\n";
var out = document.createElement("pre");
out.className = "output";
out.appendChild(document.createTextNode(result));
document.body.appendChild(out);
}
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "plugin:mozilla/xpcshell-test"
+ ]
+};
--- a/tools/profiler/tests/test_asm.js
+++ b/tools/profiler/tests/test_asm.js
@@ -17,21 +17,23 @@ function run_test() {
let jsFuns = Cu.getJSTestingFunctions();
if (!jsFuns.isAsmJSCompilationAvailable())
return;
const ms = 10;
p.StartProfiler(10000, ms, ["js"], 1);
let stack = null;
- function ffi_function(){
+ function ffi_function() {
var delayMS = 5;
while (1) {
let then = Date.now();
- do {} while (Date.now() - then < delayMS);
+ do {
+ // do nothing
+ } while (Date.now() - then < delayMS);
var thread0 = p.getProfileData().threads[0];
if (delayMS > 30000)
return;
delayMS *= 2;
@@ -51,17 +53,17 @@ function run_test() {
function asmjs_function() {
ffi();
}
return asmjs_function;
}
do_check_true(jsFuns.isAsmJSModule(asmjs_module));
- var asmjs_function = asmjs_module(null, {ffi:ffi_function});
+ var asmjs_function = asmjs_module(null, {ffi: ffi_function});
do_check_true(jsFuns.isAsmJSFunction(asmjs_function));
asmjs_function();
do_check_neq(stack, null);
var i1 = stack.indexOf("entry trampoline");
do_check_true(i1 !== -1);
--- a/tools/profiler/tests/test_enterjit_osr.js
+++ b/tools/profiler/tests/test_enterjit_osr.js
@@ -13,34 +13,34 @@ function run_test() {
// This test assumes that it's starting on an empty profiler stack.
// (Note that the other profiler tests also assume the profiler
// isn't already started.)
do_check_true(!p.IsActive());
const ms = 5;
p.StartProfiler(100, ms, ["js"], 1);
- function arbitrary_name(){
+ function arbitrary_name() {
// A frame for |arbitrary_name| has been pushed. Do a sequence of
// increasingly long spins until we get a sample.
var delayMS = 5;
while (1) {
do_print("loop: ms = " + delayMS);
let then = Date.now();
do {
let n = 10000;
while (--n); // OSR happens here
// Spin in the hope of getting a sample.
} while (Date.now() - then < delayMS);
let pr = p.getProfileData().threads[0];
if (pr.samples.data.length > 0 || delayMS > 30000)
return pr;
delayMS *= 2;
}
- };
+ }
var profile = arbitrary_name();
do_check_neq(profile.samples.data.length, 0);
var lastSample = profile.samples.data[profile.samples.data.length - 1];
var stack = getInflatedStackLocations(profile, lastSample);
do_print(stack);
--- a/tools/profiler/tests/test_enterjit_osr_disabling.js
+++ b/tools/profiler/tests/test_enterjit_osr_disabling.js
@@ -6,16 +6,16 @@ function run_test() {
p = p.getService(Ci.nsIProfiler);
if (!p)
return;
do_check_true(!p.IsActive());
p.StartProfiler(100, 10, ["js"], 1);
// The function is entered with the profiler enabled
- (function (){
+ (function() {
p.StopProfiler();
let n = 10000;
while (--n); // OSR happens here with the profiler disabled.
// An assertion will fail when this function returns, if the
// profiler stack was misbalanced.
})();
}
--- a/tools/profiler/tests/test_enterjit_osr_enabling.js
+++ b/tools/profiler/tests/test_enterjit_osr_enabling.js
@@ -5,17 +5,17 @@ function run_test() {
return;
p = p.getService(Ci.nsIProfiler);
if (!p)
return;
do_check_true(!p.IsActive());
// The function is entered with the profiler disabled.
- (function (){
+ (function() {
p.StartProfiler(100, 10, ["js"], 1);
let n = 10000;
while (--n); // OSR happens here with the profiler enabled.
// An assertion will fail when this function returns, if the
// profiler stack was misbalanced.
})();
p.StopProfiler();
}
--- a/tools/profiler/tests/test_get_features.js
+++ b/tools/profiler/tests/test_get_features.js
@@ -1,12 +1,12 @@
/* 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/. */
-
+
function run_test() {
// If we can't get the profiler component then assume gecko was
// built without it and pass all the tests
var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
if (!profilerCc)
return;
var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
--- a/tools/profiler/tests/test_start.js
+++ b/tools/profiler/tests/test_start.js
@@ -1,12 +1,12 @@
/* 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/. */
-
+
function run_test() {
// If we can't get the profiler component then assume gecko was
// built without it and pass all the tests
var profilerCc = Cc["@mozilla.org/tools/profiler;1"];
if (!profilerCc)
return;
var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
--- a/tools/quitter/QuitterObserver.js
+++ b/tools/quitter/QuitterObserver.js
@@ -16,18 +16,17 @@ function QuitterObserver() {}
QuitterObserver.prototype = {
classDescription: "Quitter Observer for use in testing.",
classID: Components.ID("{c235a986-5ac1-4f28-ad73-825dae9bad90}"),
contractID: "@mozilla.org/quitter-observer;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]),
_xpcom_categories: [{category: "profile-after-change", service: true }],
isFrameScriptLoaded: false,
- observe: function(aSubject, aTopic, aData)
- {
+ observe(aSubject, aTopic, aData) {
if (aTopic == "profile-after-change") {
this.init();
} else if (!this.isFrameScriptLoaded &&
aTopic == "chrome-document-global-created") {
var messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
getService(Ci.nsIMessageBroadcaster);
// Register for any messages our API needs us to handle
@@ -35,35 +34,33 @@ QuitterObserver.prototype = {
messageManager.loadFrameScript(CHILD_SCRIPT, true);
this.isFrameScriptLoaded = true;
} else if (aTopic == "xpcom-shutdown") {
this.uninit();
}
},
- init: function()
- {
+ init() {
var obs = Services.obs;
obs.addObserver(this, "xpcom-shutdown");
obs.addObserver(this, "chrome-document-global-created");
},
- uninit: function()
- {
+ uninit() {
var obs = Services.obs;
obs.removeObserver(this, "chrome-document-global-created");
},
/**
* messageManager callback function
* This will get requests from our API in the window and process them in chrome for it
**/
- receiveMessage: function(aMessage) {
- switch(aMessage.name) {
+ receiveMessage(aMessage) {
+ switch (aMessage.name) {
case "Quitter.Quit":
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
appStartup.quit(Ci.nsIAppStartup.eForceQuit);
break;
}
}
};
--- a/tools/quitter/contentscript.js
+++ b/tools/quitter/contentscript.js
@@ -1,22 +1,24 @@
/* 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/. */
+/* eslint-env mozilla/frame-script */
+
var Ci = Components.interfaces;
var Cc = Components.classes;
var Cu = Components.utils;
function Quitter() {
}
Quitter.prototype = {
- toString: function() { return "[Quitter]"; },
- quit: function() { sendSyncMessage('Quitter.Quit', {}); }
+ toString() { return "[Quitter]"; },
+ quit() { sendSyncMessage("Quitter.Quit", {}); }
};
// This is a frame script, so it may be running in a content process.
// In any event, it is targeted at a specific "tab", so we listen for
// the DOMWindowCreated event to be notified about content windows
// being created in this context.
function QuitterManager() {