Bug 1372427 - enforce "var" declarations only at top-level. r=MattN

MozReview-Commit-ID: 1bzsOoyidnR

--HG--
extra : rebase_source : fa4ca6a5f23e8102a7fd3f7839ef75913a2664a8
This commit is contained in:
Jonathan Guillotte-Blouin 2017-06-14 17:30:32 -07:00
Родитель 9d800f76e8
Коммит 940afb49f2
21 изменённых файлов: 84 добавлений и 81 удалений

Просмотреть файл

@ -2,6 +2,8 @@
module.exports = {
rules: {
"mozilla/var-only-at-top-level": "error",
curly: ["error", "all"],
indent: ["error", 2, {
SwitchCase: 1,

Просмотреть файл

@ -11,7 +11,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
var satchelFormListener = {
let satchelFormListener = {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIFormSubmitObserver,
Ci.nsIObserver,

Просмотреть файл

@ -13,13 +13,13 @@ var gChromeScript;
* Returns the element with the specified |name| attribute.
*/
function $_(formNum, name) {
var form = document.getElementById("form" + formNum);
let form = document.getElementById("form" + formNum);
if (!form) {
ok(false, "$_ couldn't find requested form " + formNum);
return null;
}
var element = form.elements.namedItem(name);
let element = form.elements.namedItem(name);
if (!element) {
ok(false, "$_ couldn't find requested element " + name);
return null;
@ -40,8 +40,8 @@ function $_(formNum, name) {
// Mochitest gives us a sendKey(), but it's targeted to a specific element.
// This basically sends an untargeted key event, to whatever's focused.
function doKey(aKey, modifier) {
var keyName = "DOM_VK_" + aKey.toUpperCase();
var key = SpecialPowers.Ci.nsIDOMKeyEvent[keyName];
let keyName = "DOM_VK_" + aKey.toUpperCase();
let key = SpecialPowers.Ci.nsIDOMKeyEvent[keyName];
// undefined --> null
if (!modifier) {
@ -49,7 +49,7 @@ function doKey(aKey, modifier) {
}
// Window utils for sending fake key events.
var wutils = SpecialPowers.getDOMWindowUtils(window);
let wutils = SpecialPowers.getDOMWindowUtils(window);
if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
wutils.sendKeyEvent("keypress", key, 0, modifier);
@ -70,14 +70,14 @@ function getMenuEntries() {
throw new Error("no autocomplete results");
}
var results = gLastAutoCompleteResults;
let results = gLastAutoCompleteResults;
gLastAutoCompleteResults = null;
return results;
}
function checkArrayValues(actualValues, expectedValues, msg) {
is(actualValues.length, expectedValues.length, "Checking array values: " + msg);
for (var i = 0; i < expectedValues.length; i++) {
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], msg + " Checking array entry #" + i);
}
}
@ -118,13 +118,13 @@ var checkObserver = {
// - if there are too few messages, test will time out
// - if there are too many messages, test will error out here
//
var expected = this.verifyStack.shift();
let expected = this.verifyStack.shift();
countEntries(expected.name, expected.value,
function(num) {
ok(num > 0, expected.message);
if (checkObserver.verifyStack.length == 0) {
var callback = checkObserver.callback;
let callback = checkObserver.callback;
checkObserver.callback = null;
callback();
}
@ -137,12 +137,12 @@ function checkForSave(name, value, message) {
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
let form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
let button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
@ -262,7 +262,7 @@ function promiseACShown() {
}
function satchelCommonSetup() {
var chromeURL = SimpleTest.getTestFileURL("parent_utils.js");
let chromeURL = SimpleTest.getTestFileURL("parent_utils.js");
gChromeScript = SpecialPowers.loadChromeScript(chromeURL);
gChromeScript.addMessageListener("onpopupshown", ({ results }) => {
gLastAutoCompleteResults = results;

Просмотреть файл

@ -5,8 +5,8 @@
<script>
function submitForm() {
if (location.search.indexOf("field") == -1) {
var form = document.getElementById("form");
var field = document.getElementById("field");
let form = document.getElementById("form");
let field = document.getElementById("field");
field.value = "value";
form.submit();
}

Просмотреть файл

@ -62,8 +62,8 @@ function waitForNextPopup() {
}
add_task(async function test_popup_not_move_input() {
var input = $_(1, "field1");
var rect = input.getBoundingClientRect();
let input = $_(1, "field1");
let rect = input.getBoundingClientRect();
await new Promise(resolve => updateFormHistory([
{ op: "remove" },
@ -76,7 +76,7 @@ add_task(async function test_popup_not_move_input() {
doKey("down");
await popupShown;
var newRect = input.getBoundingClientRect();
let newRect = input.getBoundingClientRect();
is(newRect.left, rect.left,
"autocomplete popup does not disturb the input position");
is(newRect.top, rect.top,

Просмотреть файл

@ -34,7 +34,7 @@ Form History test: form field autocomplete
/* import-globals-from ../../../../testing/mochitest/tests/SimpleTest/SpawnTask.js */
/* import-globals-from satchel_common.js */
var input = $_(1, "field1");
let input = $_(1, "field1");
function setupFormHistory(aCallback) {
updateFormHistory([
@ -57,7 +57,7 @@ function restoreForm() {
// Check for expected form data.
function checkForm(expectedValue) {
var formID = input.parentNode.id;
let formID = input.parentNode.id;
is(input.value, expectedValue, "Checking " + formID + " input");
}
@ -93,9 +93,9 @@ function waitForMenuChange(expectedCount) {
registerPopupShownListener(popupShownListener);
function checkMenuEntries(expectedValues) {
var actualValues = getMenuEntries();
let actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNum + " Checking length of expected menu");
for (var i = 0; i < expectedValues.length; i++) {
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #" + i);
}
}

Просмотреть файл

@ -201,7 +201,7 @@ function restoreForm() {
// Check for expected form data.
function checkForm(expectedValue) {
var formID = input.parentNode.id;
let formID = input.parentNode.id;
is(input.value, expectedValue, "Checking " + formID + " input");
}
@ -1053,9 +1053,9 @@ function waitForMenuChange(expectedCount, expectedFirstValue) {
}
function checkMenuEntries(expectedValues, testNumber) {
var actualValues = getMenuEntries();
let actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNumber + " Checking length of expected menu");
for (var i = 0; i < expectedValues.length; i++) {
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
}
}

Просмотреть файл

@ -70,7 +70,7 @@ function restoreForm() {
// Check for expected form data.
function checkForm(expectedValue) {
var formID = input.parentNode.id;
let formID = input.parentNode.id;
is(input.value, expectedValue, "Checking " + formID + " input");
}
@ -106,6 +106,7 @@ registerPopupShownListener(popupShownListener);
*/
function runTest() {
testNum++;
let datalist;
info("Starting test #" + testNum);
@ -328,8 +329,8 @@ function runTest() {
// Removing the second element while on the first then going down and
// push enter. Value should be one from the third suggesion.
doKey("down");
var datalist = document.getElementById("suggest");
var toRemove = datalist.children[1];
datalist = document.getElementById("suggest");
let toRemove = datalist.children[1];
datalist.removeChild(toRemove);
SimpleTest.executeSoon(function() {
@ -351,7 +352,7 @@ function runTest() {
// down and push enter. Value should be the on from the new suggestion.
doKey("down");
datalist = document.getElementById("suggest");
var added = new Option("Foo");
let added = new Option("Foo");
datalist.insertBefore(added, datalist.children[1]);
waitForMenuChange(4);
break;
@ -488,9 +489,9 @@ function waitForMenuChange(expectedCount) {
}
function checkMenuEntries(expectedValues, testNumber) {
var actualValues = getMenuEntries();
let actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNumber + " Checking length of expected menu");
for (var i = 0; i < expectedValues.length; i++) {
for (let i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
}
}

Просмотреть файл

@ -314,7 +314,7 @@ function startTest() {
$_(14, "test1").type = "password";
$_(14, "test1").value = "dontSaveThis";
var testData = ccNumbers.valid16;
let testData = ccNumbers.valid16;
for (let i = 0; i != testData.length; i++) {
$_(15, "test" + (i + 1)).value = testData[i];
}
@ -350,7 +350,7 @@ function startTest() {
$_(109, "test9").value = "savedValue";
// submit the first form.
var button = getFormSubmitButton(1);
let button = getFormSubmitButton(1);
button.click();
}
@ -466,7 +466,7 @@ function submitForm(formNum) {
//
setTimeout(function() {
checkObserver.waitForChecks(function() {
var nextFormNum = formNum == 22 ? 100 : (formNum + 1);
let nextFormNum = formNum == 22 ? 100 : (formNum + 1);
// Submit the next form. Special cases are Forms 21 and 100, which happen
// from an HTTPS domain in an iframe.
@ -475,7 +475,7 @@ function submitForm(formNum) {
SpecialPowers.wrap(document.getElementById("iframe").contentWindow)
.wrappedJSObject.clickButton(nextFormNum);
} else {
var button = getFormSubmitButton(nextFormNum);
let button = getFormSubmitButton(nextFormNum);
button.click();
}
});

Просмотреть файл

@ -38,9 +38,9 @@ function checkInitialState() {
}
function startTest() {
var form = document.getElementById("form1");
let form = document.getElementById("form1");
for (let i = 1; i <= numInputFields; i++) {
var newField = document.createElement("input");
let newField = document.createElement("input");
newField.setAttribute("type", "text");
newField.setAttribute("name", "test" + i);
form.appendChild(newField);
@ -54,7 +54,7 @@ function startTest() {
}
// submit the first form.
var button = getFormSubmitButton(1);
let button = getFormSubmitButton(1);
button.click();
}

Просмотреть файл

@ -142,7 +142,7 @@ function startTest() {
$_(1, "test" + numInputFields).value = numInputFields + " changed";
// submit the first form.
var button = getFormSubmitButton(1);
let button = getFormSubmitButton(1);
button.click();
}

Просмотреть файл

@ -32,7 +32,7 @@ function waitForNextPopup() {
}
add_task(async function test_popup_direction() {
var input = $_(1, "field1");
let input = $_(1, "field1");
await new Promise(resolve => updateFormHistory([
{ op: "remove" },

Просмотреть файл

@ -22,10 +22,10 @@ var formHistoryStartup = Cc["@mozilla.org/satchel/form-history-startup;1"]
formHistoryStartup.observe(null, "profile-after-change", null);
function getDBVersion(dbfile) {
var ss = Cc["@mozilla.org/storage/service;1"]
let ss = Cc["@mozilla.org/storage/service;1"]
.getService(Ci.mozIStorageService);
var dbConnection = ss.openDatabase(dbfile);
var version = dbConnection.schemaVersion;
let dbConnection = ss.openDatabase(dbfile);
let version = dbConnection.schemaVersion;
dbConnection.close();
return version;
@ -52,7 +52,7 @@ function searchEntries(terms, params, iter) {
// Count the number of entries with the given name and value, and call then(number)
// when done. If name or value is null, then the value of that field does not matter.
function countEntries(name, value, then) {
var obj = {};
let obj = {};
if (name !== null) {
obj.fieldname = name;
}
@ -76,7 +76,7 @@ function countEntries(name, value, then) {
// Perform a single form history update and call then() when done.
function updateEntry(op, name, value, then) {
var obj = { op };
let obj = { op };
if (name !== null) {
obj.fieldname = name;
}

Просмотреть файл

@ -51,8 +51,8 @@ function* tests() {
Services.obs.addObserver(TestObserver, "satchel-storage-changed", true);
// ===== test init =====
var testfile = do_get_file("asyncformhistory_expire.sqlite");
var profileDir = do_get_profile();
let testfile = do_get_file("asyncformhistory_expire.sqlite");
let profileDir = do_get_profile();
// Cleanup from any previous tests or failures.
dbFile = profileDir.clone();
@ -80,7 +80,7 @@ function* tests() {
yield countEntries("name-C", "value-C", checkExists);
// Update some existing entries to have ages relative to when the test runs.
var now = 1000 * Date.now();
let now = 1000 * Date.now();
let updateLastUsed = function updateLastUsedFn(results, age) {
let lastUsed = now - age * 24 * PR_HOURS;

Просмотреть файл

@ -13,7 +13,7 @@ var numRecords, timeGroupingSize, now;
const DEFAULT_EXPIRE_DAYS = 180;
function padLeft(number, length) {
var str = number + "";
let str = number + "";
while (str.length < length) {
str = "0" + str;
}
@ -29,11 +29,11 @@ function getFormExpiryDays() {
function run_test() {
// ===== test init =====
var testfile = do_get_file("formhistory_autocomplete.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_autocomplete.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);
@ -50,8 +50,8 @@ function run_test() {
}
add_test(function test0() {
var maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings");
var bucketSize = prefs.getIntPref("browser.formfill.bucketSize");
let maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings");
let bucketSize = prefs.getIntPref("browser.formfill.bucketSize");
// ===== Tests with constant timesUsed and varying lastUsed date =====
// insert 2 records per bucket to check alphabetical sort within

Просмотреть файл

@ -15,11 +15,11 @@ function run_test() {
function* next_test() {
try {
// ===== test init =====
var testfile = do_get_file("formhistory_v3.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_v3.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);

Просмотреть файл

@ -15,11 +15,11 @@ function run_test() {
function* next_test() {
try {
// ===== test init =====
var testfile = do_get_file("formhistory_v3v4.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_v3v4.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);

Просмотреть файл

@ -23,15 +23,15 @@ function next_test() {
}
function* tests() {
var testnum = 0;
let testnum = 0;
try {
// ===== test init =====
var testfile = do_get_file("formhistory_v999a.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_v999a.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);

Просмотреть файл

@ -23,21 +23,21 @@ function next_test() {
}
function* tests() {
var testnum = 0;
let testnum = 0;
try {
// ===== test init =====
var testfile = do_get_file("formhistory_v999b.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_v999b.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);
}
var bakFile = profileDir.clone();
let bakFile = profileDir.clone();
bakFile.append("formhistory.sqlite.corrupt");
if (bakFile.exists()) {
bakFile.remove(false);

Просмотреть файл

@ -50,7 +50,7 @@ function checkTimeDeleted(guid, checkFunction) {
}
function promiseUpdateEntry(op, name, value) {
var change = { op };
let change = { op };
if (name !== null) {
change.fieldname = name;
}
@ -107,11 +107,11 @@ add_task(async function() {
try {
// ===== test init =====
var testfile = do_get_file("formhistory_apitest.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
let testfile = do_get_file("formhistory_apitest.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
if (destFile.exists()) {
destFile.remove(false);

Просмотреть файл

@ -5,10 +5,10 @@
*
*/
var expectedNotification;
var expectedData;
let expectedNotification;
let expectedData;
var TestObserver = {
let TestObserver = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
observe(subject, topic, data) {
@ -33,7 +33,7 @@ var TestObserver = {
}
};
var testIterator = null;
let testIterator = null;
function run_test() {
do_test_pending();
@ -46,11 +46,11 @@ function next_test() {
}
function* run_test_steps() {
var testnum = 0;
var testdesc = "Setup of test form history entries";
let testnum = 0;
let testdesc = "Setup of test form history entries";
try {
var entry1 = ["entry1", "value1"];
let entry1 = ["entry1", "value1"];
/* ========== 1 ========== */
testnum = 1;
@ -63,7 +63,7 @@ function* run_test_steps() {
});
// Add the observer
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
os.addObserver(TestObserver, "satchel-storage-changed");
/* ========== 2 ========== */