From f64146d9d7f410a652f58066bcd0dcb93dbd919e Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Thu, 5 Jan 2017 16:43:29 -0500 Subject: [PATCH] Bug 1329014 - Enable the no-extra-bind rule and use eslint --fix to autofix the errors. r=standard8 MozReview-Commit-ID: BwK94W2mHXS --HG-- extra : rebase_source : a905658829084d3a4018df81f51bb210ef1e645b --- browser/base/content/aboutNetError.xhtml | 2 +- browser/components/migration/ChromeProfileMigrator.js | 4 ++-- browser/components/migration/SafariProfileMigrator.js | 2 +- .../newtab/tests/browser/browser_newtab_overrides.js | 2 +- .../newtab/tests/browser/browser_newtabwebchannel.js | 6 +++--- .../tests/browser/browser_remotenewtab_pageloads.js | 2 +- browser/components/nsBrowserGlue.js | 2 +- browser/components/uitour/UITour.jsm | 2 +- browser/modules/SocialService.jsm | 2 +- toolkit/.eslintrc.js | 3 +++ toolkit/components/crashes/CrashManager.jsm | 2 +- toolkit/components/jsdownloads/src/DownloadCore.jsm | 8 ++++---- toolkit/components/jsdownloads/test/unit/head.js | 4 ++-- toolkit/components/places/Bookmarks.jsm | 2 +- toolkit/components/places/PlacesTransactions.jsm | 2 +- toolkit/components/places/PlacesUtils.jsm | 6 +++--- toolkit/components/places/UnifiedComplete.js | 2 +- toolkit/components/reader/AboutReader.jsm | 2 +- toolkit/components/telemetry/TelemetrySession.jsm | 2 +- toolkit/identity/IdentityProvider.jsm | 2 +- toolkit/modules/ProfileAge.jsm | 2 +- toolkit/modules/secondscreen/RokuApp.jsm | 10 +++++----- .../modules/secondscreen/SimpleServiceDiscovery.jsm | 2 +- toolkit/mozapps/extensions/content/extensions.js | 2 +- 24 files changed, 39 insertions(+), 36 deletions(-) diff --git a/browser/base/content/aboutNetError.xhtml b/browser/base/content/aboutNetError.xhtml index ee1a53ff1679..b7cac3e8fcd1 100644 --- a/browser/base/content/aboutNetError.xhtml +++ b/browser/base/content/aboutNetError.xhtml @@ -308,7 +308,7 @@ if (getErrorCode() == "weakCryptoUsed" || getErrorCode() == "sslv3Used") { setupAdvancedButton(getErrorCode() == "weakCryptoUsed"); } - }.bind(this), true, true); + }, true, true); var event = new CustomEvent("AboutNetErrorLoad", {bubbles:true}); document.dispatchEvent(event); diff --git a/browser/components/migration/ChromeProfileMigrator.js b/browser/components/migration/ChromeProfileMigrator.js index fd171064c0a6..a9f310178e7d 100644 --- a/browser/components/migration/ChromeProfileMigrator.js +++ b/browser/components/migration/ChromeProfileMigrator.js @@ -293,8 +293,8 @@ function GetBookmarksResource(aProfileFolder) { if (gotErrors) { throw new Error("The migration included errors."); } - }.bind(this)).then(() => aCallback(true), - () => aCallback(false)); + }).then(() => aCallback(true), + () => aCallback(false)); } }; } diff --git a/browser/components/migration/SafariProfileMigrator.js b/browser/components/migration/SafariProfileMigrator.js index 67492123ff41..2408cf235f2b 100644 --- a/browser/components/migration/SafariProfileMigrator.js +++ b/browser/components/migration/SafariProfileMigrator.js @@ -328,7 +328,7 @@ SearchStrings.prototype = { FormHistory.update(changes); } } - }.bind(this), aCallback)); + }, aCallback)); } }; diff --git a/browser/components/newtab/tests/browser/browser_newtab_overrides.js b/browser/components/newtab/tests/browser/browser_newtab_overrides.js index eab9092a0d70..fb5d8c75f4dd 100644 --- a/browser/components/newtab/tests/browser/browser_newtab_overrides.js +++ b/browser/components/newtab/tests/browser/browser_newtab_overrides.js @@ -135,5 +135,5 @@ function nextChangeNotificationPromise(aNewURL, testMessage) { return TestUtils.topicObserved("newtab-url-changed", function observer(aSubject, aData) { // jshint unused:false Assert.equal(aData, aNewURL, testMessage); return true; - }.bind(this)); + }); } diff --git a/browser/components/newtab/tests/browser/browser_newtabwebchannel.js b/browser/components/newtab/tests/browser/browser_newtabwebchannel.js index f003b105b227..0c31750f76e9 100644 --- a/browser/components/newtab/tests/browser/browser_newtabwebchannel.js +++ b/browser/components/newtab/tests/browser/browser_newtabwebchannel.js @@ -91,7 +91,7 @@ add_task(function* webchannel_broadcast() { NewTabWebChannel.off("foo", test_message); resolve(msg.target); } - }.bind(this)); + }); }); let countingReplyPromise = new Promise(resolve => { @@ -102,7 +102,7 @@ add_task(function* webchannel_broadcast() { NewTabWebChannel.off("reply", test_message); resolve(msg.target); } - }.bind(this)); + }); }); let countingUnloadPromise = new Promise(resolve => { @@ -147,7 +147,7 @@ add_task(function* webchannel_switch() { return new Promise(resolve => { NewTabWebChannel.once("foo", function(name, msg) { resolve(msg.target); - }.bind(this)); + }); }); } diff --git a/browser/components/newtab/tests/browser/browser_remotenewtab_pageloads.js b/browser/components/newtab/tests/browser/browser_remotenewtab_pageloads.js index e99aeffc2c11..f9cea1cc1484 100644 --- a/browser/components/newtab/tests/browser/browser_remotenewtab_pageloads.js +++ b/browser/components/newtab/tests/browser/browser_remotenewtab_pageloads.js @@ -48,5 +48,5 @@ function nextChangeNotificationPromise(aNewURL, testMessage) { return TestUtils.topicObserved("newtab-url-changed", function observer(aSubject, aData) { // jshint unused:false Assert.equal(aData, aNewURL, testMessage); return true; - }.bind(this)); + }); } diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 2af5e4d2e943..243689945a8e 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1161,7 +1161,7 @@ BrowserGlue.prototype = { if (willPrompt) { Services.tm.mainThread.dispatch(function() { DefaultBrowserCheck.prompt(RecentWindow.getMostRecentBrowserWindow()); - }.bind(this), Ci.nsIThread.DISPATCH_NORMAL); + }, Ci.nsIThread.DISPATCH_NORMAL); } } diff --git a/browser/components/uitour/UITour.jsm b/browser/components/uitour/UITour.jsm index eeb73ade9eab..4dbefa09e5d7 100644 --- a/browser/components/uitour/UITour.jsm +++ b/browser/components/uitour/UITour.jsm @@ -1318,7 +1318,7 @@ this.UITour = { ["score", rating], ["flowid", aOptions.flowId] ])); - }.bind(this)); + }); // Add it to the container. ratingContainer.appendChild(ratingElement); diff --git a/browser/modules/SocialService.jsm b/browser/modules/SocialService.jsm index c1dfce37fc20..d7beec84dd3f 100644 --- a/browser/modules/SocialService.jsm +++ b/browser/modules/SocialService.jsm @@ -450,7 +450,7 @@ this.SocialService = { getProvider: function getProvider(origin, onDone) { schedule((function() { onDone(SocialServiceInternal.providers[origin] || null); - }).bind(this)); + })); }, // Returns an unordered array of installed providers diff --git a/toolkit/.eslintrc.js b/toolkit/.eslintrc.js index c3e345d295be..bd8e0f6a46a2 100644 --- a/toolkit/.eslintrc.js +++ b/toolkit/.eslintrc.js @@ -78,6 +78,9 @@ module.exports = { // No duplicate cases in switch statements "no-duplicate-case": "error", + // Disallow unnecessary calls to .bind() + "no-extra-bind": "error", + // No labels "no-labels": "error", diff --git a/toolkit/components/crashes/CrashManager.jsm b/toolkit/components/crashes/CrashManager.jsm index 65216391c8d8..f47f5f692972 100644 --- a/toolkit/components/crashes/CrashManager.jsm +++ b/toolkit/components/crashes/CrashManager.jsm @@ -760,7 +760,7 @@ this.CrashManager.prototype = Object.freeze({ entries.sort((a, b) => { return a.date - b.date; }); return entries; - }.bind(this)); + }); }, _getStore() { diff --git a/toolkit/components/jsdownloads/src/DownloadCore.jsm b/toolkit/components/jsdownloads/src/DownloadCore.jsm index b80fc0249a33..0ba8f07b0b63 100644 --- a/toolkit/components/jsdownloads/src/DownloadCore.jsm +++ b/toolkit/components/jsdownloads/src/DownloadCore.jsm @@ -2097,7 +2097,7 @@ this.DownloadCopySaver.prototype = { } }.bind(copySaver), - onStopRequest: function(aRequest, aContext, aStatusCode) { + onStopRequest(aRequest, aContext, aStatusCode) { try { backgroundFileSaver.onStopRequest(aRequest, aContext, aStatusCode); @@ -2109,14 +2109,14 @@ this.DownloadCopySaver.prototype = { backgroundFileSaver.finish(Cr.NS_OK); } } - }.bind(copySaver), + }, - onDataAvailable: function(aRequest, aContext, aInputStream, + onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) { backgroundFileSaver.onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount); - }.bind(copySaver), + }, }); // We should check if we have been canceled in the meantime, after diff --git a/toolkit/components/jsdownloads/test/unit/head.js b/toolkit/components/jsdownloads/test/unit/head.js index 40e0a996be44..a8585ce8ae40 100644 --- a/toolkit/components/jsdownloads/test/unit/head.js +++ b/toolkit/components/jsdownloads/test/unit/head.js @@ -361,7 +361,7 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) { // Start the actual download process. persist.savePrivacyAwareURI(sourceURI, null, null, 0, null, null, targetFile, isPrivate); - }.bind(this)).then(null, do_report_unexpected_exception); + }).then(null, do_report_unexpected_exception); return deferred.promise; } @@ -429,7 +429,7 @@ function promiseStartExternalHelperAppServiceDownload(aSourceUrl) { aOffset, aCount); }, }); - }.bind(this)).then(null, do_report_unexpected_exception); + }).then(null, do_report_unexpected_exception); return deferred.promise; } diff --git a/toolkit/components/places/Bookmarks.jsm b/toolkit/components/places/Bookmarks.jsm index f01e3ab56547..058cfdb67a64 100644 --- a/toolkit/components/places/Bookmarks.jsm +++ b/toolkit/components/places/Bookmarks.jsm @@ -1380,7 +1380,7 @@ function reorderChildren(parent, orderedChildrenGuids, options) { { orphanAnno: PlacesSyncUtils.bookmarks.SYNC_PARENT_ANNO }); return children; - }.bind(this)) + }) ); } diff --git a/toolkit/components/places/PlacesTransactions.jsm b/toolkit/components/places/PlacesTransactions.jsm index 7cc741330605..ae6ec029f25c 100644 --- a/toolkit/components/places/PlacesTransactions.jsm +++ b/toolkit/components/places/PlacesTransactions.jsm @@ -621,7 +621,7 @@ var TransactionsManager = { TransactionsHistory.clearRedoEntries(); else throw new Error("either aUndoEntries or aRedoEntries should be true"); - }.bind(this)); + }); this._transactEnqueuer.alsoWaitFor(promise); return promise; diff --git a/toolkit/components/places/PlacesUtils.jsm b/toolkit/components/places/PlacesUtils.jsm index 3233641e0431..5c50f34abe20 100644 --- a/toolkit/components/places/PlacesUtils.jsm +++ b/toolkit/components/places/PlacesUtils.jsm @@ -1838,7 +1838,7 @@ this.PlacesUtils = { break; } return item; - }.bind(this); + }; const QUERY_STR = `/* do not warn (bug no): cannot use an index */ @@ -2273,7 +2273,7 @@ var Keywords = { // In any case, notify about the new keyword. yield notifyKeywordChange(url.href, keyword, source); - }.bind(this)) + }) ); }, @@ -2311,7 +2311,7 @@ var Keywords = { // Notify bookmarks about the removal. yield notifyKeywordChange(url.href, "", source); - }.bind(this))) ; + })); } }; diff --git a/toolkit/components/places/UnifiedComplete.js b/toolkit/components/places/UnifiedComplete.js index e58be76e001b..14112c4a65a3 100644 --- a/toolkit/components/places/UnifiedComplete.js +++ b/toolkit/components/places/UnifiedComplete.js @@ -1998,7 +1998,7 @@ UnifiedComplete.prototype = { yield SwitchToTabStorage.initDatabase(conn); return conn; - }.bind(this)).then(null, ex => { + }).then(null, ex => { dump("Couldn't get database handle: " + ex + "\n"); Cu.reportError(ex); }); diff --git a/toolkit/components/reader/AboutReader.jsm b/toolkit/components/reader/AboutReader.jsm index 044803ca25c7..66ba2334185a 100644 --- a/toolkit/components/reader/AboutReader.jsm +++ b/toolkit/components/reader/AboutReader.jsm @@ -911,7 +911,7 @@ AboutReader.prototype = { item.classList.add("selected"); callback(option.value); - }.bind(this), true); + }, true); if (option.value === initialValue) item.classList.add("selected"); diff --git a/toolkit/components/telemetry/TelemetrySession.jsm b/toolkit/components/telemetry/TelemetrySession.jsm index d55e3a0a8b13..b00e2ba6698c 100644 --- a/toolkit/components/telemetry/TelemetrySession.jsm +++ b/toolkit/components/telemetry/TelemetrySession.jsm @@ -1911,7 +1911,7 @@ var Impl = { // TODO: We are keeping this behaviour for now but it will be removed as soon as // bug 1127907 lands. Services.obs.notifyObservers(null, "gather-telemetry", null); - }).bind(this), Ci.nsIThread.DISPATCH_NORMAL); + }), Ci.nsIThread.DISPATCH_NORMAL); break; case "application-background": diff --git a/toolkit/identity/IdentityProvider.jsm b/toolkit/identity/IdentityProvider.jsm index 509e8e2e2770..db32094fd3f6 100644 --- a/toolkit/identity/IdentityProvider.jsm +++ b/toolkit/identity/IdentityProvider.jsm @@ -253,7 +253,7 @@ IdentityProviderService.prototype = { // sandbox. log("genKeyPair: generated keypair for provisioning flow with id:", aProvId); provFlow.caller.doGenKeyPairCallback(provFlow.kp.serializedPublicKey); - }.bind(this)); + }); }, /** diff --git a/toolkit/modules/ProfileAge.jsm b/toolkit/modules/ProfileAge.jsm index c87925d35b13..0b9ffa44b883 100644 --- a/toolkit/modules/ProfileAge.jsm +++ b/toolkit/modules/ProfileAge.jsm @@ -51,7 +51,7 @@ this.ProfileAge.prototype = { return this.computeAndPersistCreated(times) .then(function onSuccess(created) { return created; - }.bind(this)); + }); } return this.getTimes() diff --git a/toolkit/modules/secondscreen/RokuApp.jsm b/toolkit/modules/secondscreen/RokuApp.jsm index 7eaf335f5a17..7472b3a83fd9 100644 --- a/toolkit/modules/secondscreen/RokuApp.jsm +++ b/toolkit/modules/secondscreen/RokuApp.jsm @@ -60,7 +60,7 @@ RokuApp.prototype = { if (callback) { callback({ state: "unknown" }); } - }).bind(this), false); + }), false); xhr.send(null); }, @@ -91,13 +91,13 @@ RokuApp.prototype = { if (callback) { callback(xhr.status === 200); } - }).bind(this), false); + }), false); xhr.addEventListener("error", (function() { if (callback) { callback(false); } - }).bind(this), false); + }), false); xhr.send(null); }, @@ -114,13 +114,13 @@ RokuApp.prototype = { if (callback) { callback(xhr.status === 200); } - }).bind(this), false); + }), false); xhr.addEventListener("error", (function() { if (callback) { callback(false); } - }).bind(this), false); + }), false); xhr.send(null); }, diff --git a/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm b/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm index 029f7a4a9462..f170cdb2e823 100644 --- a/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm +++ b/toolkit/modules/secondscreen/SimpleServiceDiscovery.jsm @@ -80,7 +80,7 @@ var SimpleServiceDiscovery = { } else if (name.startsWith("ST")) { service.target = row.substr(4).trim(); } - }.bind(this)); + }); if (service.location && service.target) { service.location = this._forceTrailingSlash(service.location); diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 0a8bc5c20ed7..b6a42d929b2d 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -3491,7 +3491,7 @@ var gDetailView = { if (aCallback) aCallback(); - }).bind(this); + }); xhr.onerror = function(aEvent) { Cu.reportError("Error " + aEvent.target.status + " occurred while receiving " + this._addon.optionsURL);