From 3442ae7718679a4da8664bdbb561f746e0357203 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Wed, 2 May 2018 06:57:57 +0200 Subject: Fix unsafe "instanceof" negations https://github.com/MoonchildProductions/Pale-Moon/pull/1173 --- .eslintrc.js | 3 +++ devtools/server/child.js | 2 +- devtools/server/main.js | 2 +- mobile/android/chrome/content/InputWidgetHelper.js | 2 +- security/manager/.eslintrc.js | 3 --- services/fxaccounts/FxAccountsProfileClient.jsm | 4 ++-- services/fxaccounts/FxAccountsStorage.jsm | 2 +- services/sync/modules/record.js | 4 ++-- services/sync/modules/service.js | 2 +- services/sync/tps/extensions/mozmill/resource/driver/controller.js | 2 +- services/sync/tps/extensions/mozmill/resource/modules/assertions.js | 2 +- toolkit/.eslintrc.js | 3 --- toolkit/components/osfile/modules/osfile_unix_front.jsm | 4 ++-- toolkit/components/osfile/modules/osfile_win_front.jsm | 4 ++-- toolkit/components/reader/.eslintrc.js | 3 --- toolkit/components/webextensions/.eslintrc.js | 3 --- toolkit/modules/Sqlite.jsm | 2 +- 17 files changed, 19 insertions(+), 28 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a7a886292..3d3ad2b80 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,6 +7,9 @@ module.exports = { ], "rules": { "mozilla/import-globals": "warn", + + // No (!foo in bar) or (!object instanceof Class) + "no-unsafe-negation": "error", }, "env": { "es6": true diff --git a/devtools/server/child.js b/devtools/server/child.js index e2838f08d..c69b0a3fb 100644 --- a/devtools/server/child.js +++ b/devtools/server/child.js @@ -61,7 +61,7 @@ try { try { m = require(module); - if (!setupChild in m) { + if (!(setupChild in m)) { dumpn(`ERROR: module '${module}' does not export '${setupChild}'`); return false; } diff --git a/devtools/server/main.js b/devtools/server/main.js index 475995493..ac76adb83 100644 --- a/devtools/server/main.js +++ b/devtools/server/main.js @@ -1040,7 +1040,7 @@ var DebuggerServer = { try { m = require(module); - if (!setupParent in m) { + if (!(setupParent in m)) { dumpn(`ERROR: module '${module}' does not export '${setupParent}'`); return false; } diff --git a/mobile/android/chrome/content/InputWidgetHelper.js b/mobile/android/chrome/content/InputWidgetHelper.js index 9c753bd7b..cf66a263e 100644 --- a/mobile/android/chrome/content/InputWidgetHelper.js +++ b/mobile/android/chrome/content/InputWidgetHelper.js @@ -63,7 +63,7 @@ var InputWidgetHelper = { }, hasInputWidget: function(aElement) { - if (!aElement instanceof HTMLInputElement) + if (!(aElement instanceof HTMLInputElement)) return false; let type = aElement.getAttribute('type'); diff --git a/security/manager/.eslintrc.js b/security/manager/.eslintrc.js index dc9d688aa..6b292f366 100644 --- a/security/manager/.eslintrc.js +++ b/security/manager/.eslintrc.js @@ -131,9 +131,6 @@ module.exports = { // eslint-disable-line no-undef // No reassigning native JS objects "no-native-reassign": "error", - // No (!foo in bar) - "no-negated-in-lhs": "error", - // Nested ternary statements are confusing "no-nested-ternary": "error", diff --git a/services/fxaccounts/FxAccountsProfileClient.jsm b/services/fxaccounts/FxAccountsProfileClient.jsm index 37115a3fa..1e5edc634 100644 --- a/services/fxaccounts/FxAccountsProfileClient.jsm +++ b/services/fxaccounts/FxAccountsProfileClient.jsm @@ -89,7 +89,7 @@ this.FxAccountsProfileClient.prototype = { try { return (yield this._rawRequest(path, method, token)); } catch (ex) { - if (!ex instanceof FxAccountsProfileClientError || ex.code != 401) { + if (!(ex instanceof FxAccountsProfileClientError) || ex.code != 401) { throw ex; } // If this object was instantiated with a token then we don't refresh it. @@ -105,7 +105,7 @@ this.FxAccountsProfileClient.prototype = { try { return (yield this._rawRequest(path, method, token)); } catch (ex) { - if (!ex instanceof FxAccountsProfileClientError || ex.code != 401) { + if (!(ex instanceof FxAccountsProfileClientError) || ex.code != 401) { throw ex; } log.info("Retry fetching the profile still returned a 401 - revoking our token and failing"); diff --git a/services/fxaccounts/FxAccountsStorage.jsm b/services/fxaccounts/FxAccountsStorage.jsm index 021763b92..43e2d21a0 100644 --- a/services/fxaccounts/FxAccountsStorage.jsm +++ b/services/fxaccounts/FxAccountsStorage.jsm @@ -403,7 +403,7 @@ this.FxAccountsStorageManager.prototype = { try { yield this.secureStorage.set(this.cachedPlain.uid, toWriteSecure); } catch (ex) { - if (!ex instanceof this.secureStorage.STORAGE_LOCKED) { + if (!(ex instanceof this.secureStorage.STORAGE_LOCKED)) { throw ex; } // This shouldn't be possible as once it is unlocked it can't be diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js index 02f7f281a..f7a69d9ef 100644 --- a/services/sync/modules/record.js +++ b/services/sync/modules/record.js @@ -43,7 +43,7 @@ WBORecord.prototype = { // Get thyself from your URI, then deserialize. // Set thine 'response' field. fetch: function fetch(resource) { - if (!resource instanceof Resource) { + if (!(resource instanceof Resource)) { throw new Error("First argument must be a Resource instance."); } @@ -56,7 +56,7 @@ WBORecord.prototype = { }, upload: function upload(resource) { - if (!resource instanceof Resource) { + if (!(resource instanceof Resource)) { throw new Error("First argument must be a Resource instance."); } diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index b0eb0f41d..5c91323b5 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -455,7 +455,7 @@ Sync11Service.prototype = { this.clientsEngine = new ClientEngine(this); for (let name of engines) { - if (!name in ENGINE_MODULES) { + if (!(name in ENGINE_MODULES)) { this._log.info("Do not know about engine: " + name); continue; } diff --git a/services/sync/tps/extensions/mozmill/resource/driver/controller.js b/services/sync/tps/extensions/mozmill/resource/driver/controller.js index a378ce51f..8d66a41ae 100644 --- a/services/sync/tps/extensions/mozmill/resource/driver/controller.js +++ b/services/sync/tps/extensions/mozmill/resource/driver/controller.js @@ -978,7 +978,7 @@ function browserAdditions (controller) { }, "Timeout", timeout, aInterval); } catch (ex) { - if (!ex instanceof errors.TimeoutError) { + if (!(ex instanceof errors.TimeoutError)) { throw ex; } timed_out = true; diff --git a/services/sync/tps/extensions/mozmill/resource/modules/assertions.js b/services/sync/tps/extensions/mozmill/resource/modules/assertions.js index c9991acf0..c76f95747 100644 --- a/services/sync/tps/extensions/mozmill/resource/modules/assertions.js +++ b/services/sync/tps/extensions/mozmill/resource/modules/assertions.js @@ -659,7 +659,7 @@ Expect.prototype.waitFor = function Expect_waitFor(aCallback, aMessage, aTimeout Assert.prototype.waitFor.apply(this, arguments); } catch (ex) { - if (!ex instanceof errors.AssertionError) { + if (!(ex instanceof errors.AssertionError)) { throw ex; } message = ex.message; diff --git a/toolkit/.eslintrc.js b/toolkit/.eslintrc.js index 181f19f29..891a114b3 100644 --- a/toolkit/.eslintrc.js +++ b/toolkit/.eslintrc.js @@ -111,9 +111,6 @@ module.exports = { // No reassigning native JS objects "no-native-reassign": "error", - // No (!foo in bar) - "no-negated-in-lhs": "error", - // Nested ternary statements are confusing "no-nested-ternary": "error", diff --git a/toolkit/components/osfile/modules/osfile_unix_front.jsm b/toolkit/components/osfile/modules/osfile_unix_front.jsm index 19a27ae1a..bd60d4d84 100644 --- a/toolkit/components/osfile/modules/osfile_unix_front.jsm +++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm @@ -838,7 +838,7 @@ * implementation. */ File.DirectoryIterator.Entry.toMsg = function toMsg(value) { - if (!value instanceof File.DirectoryIterator.Entry) { + if (!(value instanceof File.DirectoryIterator.Entry)) { throw new TypeError("parameter of " + "File.DirectoryIterator.Entry.toMsg must be a " + "File.DirectoryIterator.Entry"); @@ -905,7 +905,7 @@ * is asymmetric and returns an object with a different implementation. */ File.Info.toMsg = function toMsg(stat) { - if (!stat instanceof File.Info) { + if (!(stat instanceof File.Info)) { throw new TypeError("parameter of File.Info.toMsg must be a File.Info"); } let serialized = {}; diff --git a/toolkit/components/osfile/modules/osfile_win_front.jsm b/toolkit/components/osfile/modules/osfile_win_front.jsm index 387dd08b5..1123b251c 100644 --- a/toolkit/components/osfile/modules/osfile_win_front.jsm +++ b/toolkit/components/osfile/modules/osfile_win_front.jsm @@ -909,7 +909,7 @@ * implementation. */ File.DirectoryIterator.Entry.toMsg = function toMsg(value) { - if (!value instanceof File.DirectoryIterator.Entry) { + if (!(value instanceof File.DirectoryIterator.Entry)) { throw new TypeError("parameter of " + "File.DirectoryIterator.Entry.toMsg must be a " + "File.DirectoryIterator.Entry"); @@ -958,7 +958,7 @@ * is asymmetric and returns an object with a different implementation. */ File.Info.toMsg = function toMsg(stat) { - if (!stat instanceof File.Info) { + if (!(stat instanceof File.Info)) { throw new TypeError("parameter of File.Info.toMsg must be a File.Info"); } let serialized = {}; diff --git a/toolkit/components/reader/.eslintrc.js b/toolkit/components/reader/.eslintrc.js index 1c09e0bf7..617c1f9cf 100644 --- a/toolkit/components/reader/.eslintrc.js +++ b/toolkit/components/reader/.eslintrc.js @@ -109,9 +109,6 @@ module.exports = { // No reassigning native JS objects "no-native-reassign": "error", - // No (!foo in bar) - "no-negated-in-lhs": "error", - // Nested ternary statements are confusing "no-nested-ternary": "error", diff --git a/toolkit/components/webextensions/.eslintrc.js b/toolkit/components/webextensions/.eslintrc.js index 70196fc6a..70f91ab6d 100644 --- a/toolkit/components/webextensions/.eslintrc.js +++ b/toolkit/components/webextensions/.eslintrc.js @@ -173,9 +173,6 @@ module.exports = { // eslint-disable-line no-undef // No reassigning native JS objects "no-native-reassign": "error", - // No (!foo in bar) - "no-negated-in-lhs": "error", - // Nested ternary statements are confusing "no-nested-ternary": "error", diff --git a/toolkit/modules/Sqlite.jsm b/toolkit/modules/Sqlite.jsm index e8d986c0e..6f7a7d94c 100644 --- a/toolkit/modules/Sqlite.jsm +++ b/toolkit/modules/Sqlite.jsm @@ -995,7 +995,7 @@ function cloneStorageConnection(options) { if (!source) { throw new TypeError("connection not specified in clone options."); } - if (!source instanceof Ci.mozIStorageAsyncConnection) { + if (!(source instanceof Ci.mozIStorageAsyncConnection)) { throw new TypeError("Connection must be a valid Storage connection."); } -- cgit v1.2.3