Skip to content

Commit

Permalink
Bug 1360293 - Enable the Mozilla ESlint recommended rules for tools/.…
Browse files Browse the repository at this point in the history
… r=jryans

MozReview-Commit-ID: JMcgZ9taEV5

--HG--
extra : rebase_source : 806d9aa8c470ab35253682a5f16e528ca8d73cc5
  • Loading branch information
Dan Banner committed May 1, 2017
1 parent fe285a1 commit c07b5f8
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 54 deletions.
11 changes: 11 additions & 0 deletions tools/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

module.exports = {
extends: [
"plugin:mozilla/recommended"
],

plugins: [
"mozilla"
]
}
57 changes: 22 additions & 35 deletions tools/leak-gauge/leak-gauge.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
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");
Expand All @@ -36,29 +35,29 @@
"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;
Expand All @@ -72,18 +71,15 @@
}
}
},
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];
Expand All @@ -108,7 +104,7 @@
}
}
},
dump: function() {
dump() {
for (var addr in this.docs) {
var doc = this.docs[addr];
result += "Leaked document at address " + addr + ".\n";
Expand All @@ -119,18 +115,15 @@
}
}
},
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];
Expand All @@ -150,7 +143,7 @@
}
}
},
dump: function() {
dump() {
for (var addr in this.shells) {
var doc = this.shells[addr];
result += "Leaked docshell at address " + addr + ".\n";
Expand All @@ -159,18 +152,15 @@
}
}
},
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];
Expand All @@ -197,7 +187,7 @@
}
}
},
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";
Expand All @@ -206,11 +196,8 @@
}
}
},
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";
}
}
Expand All @@ -223,20 +210,20 @@
// 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";

Expand Down
7 changes: 7 additions & 0 deletions tools/profiler/tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
]
};
8 changes: 5 additions & 3 deletions tools/profiler/tests/test_asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ function run_test() {
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];

Expand Down Expand Up @@ -56,7 +58,7 @@ function run_test() {

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();
Expand Down
4 changes: 2 additions & 2 deletions tools/profiler/tests/test_enterjit_osr.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function run_test() {
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;
Expand All @@ -35,7 +35,7 @@ function run_test() {
return pr;
delayMS *= 2;
}
};
}

var profile = arbitrary_name();

Expand Down
2 changes: 1 addition & 1 deletion tools/profiler/tests/test_enterjit_osr_disabling.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function run_test() {

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.
Expand Down
2 changes: 1 addition & 1 deletion tools/profiler/tests/test_enterjit_osr_enabling.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function run_test() {
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.
Expand Down
2 changes: 1 addition & 1 deletion tools/profiler/tests/test_get_features.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 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
Expand Down
2 changes: 1 addition & 1 deletion tools/profiler/tests/test_start.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 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
Expand Down
13 changes: 5 additions & 8 deletions tools/quitter/QuitterObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ QuitterObserver.prototype = {
_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 &&
Expand All @@ -40,15 +39,13 @@ QuitterObserver.prototype = {
}
},

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");
},
Expand All @@ -57,8 +54,8 @@ QuitterObserver.prototype = {
* 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);
Expand Down
6 changes: 4 additions & 2 deletions tools/quitter/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* 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;
Expand All @@ -10,8 +12,8 @@ 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.
Expand Down

0 comments on commit c07b5f8

Please sign in to comment.