From da48e321ecd0d846310528afdd6b3634a2e8d2db Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Sun, 21 Aug 2022 18:19:44 +0000 Subject: [PATCH] Bug 1786104 - Enable all ESLint rules on dom production files. r=smaug This changes the block of disabled rules for dom to only reference test directories, and then fixes the few failures in the two production files (rules: mozilla/use-services, no-else-return, consistent-return). Differential Revision: https://phabricator.services.mozilla.com/D155130 --- .eslintrc.js | 58 ++++++++++++++-------------- dom/base/ContentAreaDropListener.jsm | 23 +++-------- dom/base/DOMRequestHelper.jsm | 9 ++--- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5591da9f7e1b..bedddcda6e4c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -278,29 +278,29 @@ module.exports = { }, { files: [ - "dom/animation/**", + "dom/animation/test/**", "dom/base/test/*.*", "dom/base/test/unit/test_serializers_entities*.js", "dom/base/test/unit_ipc/**", "dom/base/test/jsmodules/**", - "dom/base/*.*", - "dom/canvas/**", - "dom/encoding/**", - "dom/events/**", - "dom/fetch/**", - "dom/file/**", - "dom/html/**", - "dom/jsurl/**", + "dom/canvas/test/**", + "dom/encoding/test/**", + "dom/events/test/**", + "dom/fetch/tests/**", + "dom/file/ipc/tests/**", + "dom/file/tests/**", + "dom/html/test/**", + "dom/jsurl/test/**", "dom/media/tests/**", - "dom/media/webaudio/**", + "dom/media/webaudio/test/**", "dom/media/webrtc/tests/**", - "dom/media/webspeech/**", - "dom/messagechannel/**", - "dom/midi/**", - "dom/network/**", - "dom/payments/**", - "dom/performance/**", - "dom/permission/**", + "dom/media/webspeech/recognition/test/**", + "dom/media/webspeech/synth/test/**", + "dom/messagechannel/tests/**", + "dom/midi/tests/**", + "dom/network/tests/**", + "dom/payments/test/**", + "dom/performance/tests/**", "dom/quota/test/browser/**", "dom/quota/test/common/**", "dom/quota/test/mochitest/**", @@ -308,19 +308,19 @@ module.exports = { "dom/security/test/cors/**", "dom/security/test/csp/**", "dom/security/test/mixedcontentblocker/**", - "dom/serviceworkers/**", - "dom/smil/**", + "dom/serviceworkers/test/**", + "dom/smil/test/**", "dom/tests/mochitest/**", - "dom/u2f/**", - "dom/vr/**", - "dom/webauthn/**", - "dom/webgpu/**", - "dom/websocket/**", - "dom/workers/**", - "dom/worklet/**", - "dom/xml/**", - "dom/xslt/**", - "dom/xul/**", + "dom/u2f/tests/**", + "dom/vr/test/**", + "dom/webauthn/tests/**", + "dom/webgpu/mochitest/**", + "dom/websocket/tests/**", + "dom/workers/test/**", + "dom/worklet/tests/**", + "dom/xml/test/**", + "dom/xslt/tests/**", + "dom/xul/test/**", "dom/ipc/test.xhtml", ], rules: { diff --git a/dom/base/ContentAreaDropListener.jsm b/dom/base/ContentAreaDropListener.jsm index e8622d0e02a0..87ce0fb6513e 100644 --- a/dom/base/ContentAreaDropListener.jsm +++ b/dom/base/ContentAreaDropListener.jsm @@ -142,9 +142,7 @@ ContentAreaDropListener.prototype = { } let uri = info.fixedURI; - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( - Ci.nsIScriptSecurityManager - ); + let secMan = Services.scriptSecurityManager; let flags = secMan.STANDARD; if (disallowInherit) { flags |= secMan.DISALLOW_INHERIT_PRINCIPAL; @@ -190,22 +188,13 @@ ContentAreaDropListener.prototype = { // TODO: Investigate and describe the difference between them, // or use only one principal. (Bug 1367038) if (fallbackToSystemPrincipal) { - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( - Ci.nsIScriptSecurityManager - ); - return secMan.getSystemPrincipal(); - } else { - principalURISpec = "file:///"; + return Services.scriptSecurityManager.getSystemPrincipal(); } + + principalURISpec = "file:///"; } - let ioService = Cc["@mozilla.org/network/io-service;1"].getService( - Ci.nsIIOService - ); - let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService( - Ci.nsIScriptSecurityManager - ); - return secMan.createContentPrincipal( - ioService.newURI(principalURISpec), + return Services.scriptSecurityManager.createContentPrincipal( + Services.io.newURI(principalURISpec), {} ); }, diff --git a/dom/base/DOMRequestHelper.jsm b/dom/base/DOMRequestHelper.jsm index 04ae441adee4..5bb0e39d731c 100644 --- a/dom/base/DOMRequestHelper.jsm +++ b/dom/base/DOMRequestHelper.jsm @@ -79,9 +79,8 @@ DOMRequestIpcHelper.prototype = { if (!!aMsg.weakRef == this._listeners[name].weakRef) { this._listeners[name].count++; return; - } else { - throw Components.Exception("", Cr.NS_ERROR_FAILURE); } + throw Components.Exception("", Cr.NS_ERROR_FAILURE); } aMsg.weakRef @@ -228,6 +227,7 @@ DOMRequestIpcHelper.prototype = { if (this._requests && this._requests[aId]) { return this._requests[aId]; } + return undefined; }, getPromiseResolver(aId) { @@ -264,10 +264,7 @@ DOMRequestIpcHelper.prototype = { }, _getRandomId() { - return Cc["@mozilla.org/uuid-generator;1"] - .getService(Ci.nsIUUIDGenerator) - .generateUUID() - .toString(); + return Services.uuid.generateUUID().toString(); }, createRequest() {