From a24dca9645a9fd4f4af4d321c933e015a8b67251 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 7 Nov 2022 17:56:10 +0000 Subject: [PATCH] Bug 1798212 - Replace defineModuleGetter in Integration.sys.mjs with a ES version. r=settings-reviewers,mossop Differential Revision: https://phabricator.services.mozilla.com/D161014 --- .../downloads/DownloadsViewUI.sys.mjs | 4 ++-- .../components/downloads/content/downloads.js | 4 ++-- .../unit/test_DownloadsViewableInternally.js | 4 ++-- browser/components/preferences/preferences.js | 4 ++-- .../components/downloads/DownloadCore.sys.mjs | 4 ++-- .../downloads/DownloadIntegration.sys.mjs | 4 ++-- toolkit/components/downloads/Downloads.sys.mjs | 4 ++-- toolkit/components/downloads/test/unit/head.js | 4 ++-- toolkit/modules/Integration.sys.mjs | 14 ++++++-------- .../modules/tests/xpcshell/test_Integration.js | 17 ++++------------- toolkit/mozapps/downloads/HelperAppDlg.jsm | 4 ++-- .../lib/rules/valid-lazy.js | 2 +- .../eslint-plugin-mozilla/tests/valid-lazy.js | 2 +- uriloader/exthandler/ExtHandlerService.sys.mjs | 4 ++-- .../test_downloads_improvements_migration.js | 4 ++-- 15 files changed, 34 insertions(+), 45 deletions(-) diff --git a/browser/components/downloads/DownloadsViewUI.sys.mjs b/browser/components/downloads/DownloadsViewUI.sys.mjs index 0a02d6f39478..772b1230549f 100644 --- a/browser/components/downloads/DownloadsViewUI.sys.mjs +++ b/browser/components/downloads/DownloadsViewUI.sys.mjs @@ -39,10 +39,10 @@ XPCOMUtils.defineLazyServiceGetter( import { Integration } from "resource://gre/modules/Integration.sys.mjs"; -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); const HTML_NS = "http://www.w3.org/1999/xhtml"; diff --git a/browser/components/downloads/content/downloads.js b/browser/components/downloads/content/downloads.js index 2de6331f2fce..eefbc510554f 100644 --- a/browser/components/downloads/content/downloads.js +++ b/browser/components/downloads/content/downloads.js @@ -51,10 +51,10 @@ const { Integration } = ChromeUtils.importESModule( ); /* global DownloadIntegration */ -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( this, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); // DownloadsPanel diff --git a/browser/components/downloads/test/unit/test_DownloadsViewableInternally.js b/browser/components/downloads/test/unit/test_DownloadsViewableInternally.js index 44477ff86258..07925bc7d505 100644 --- a/browser/components/downloads/test/unit/test_DownloadsViewableInternally.js +++ b/browser/components/downloads/test/unit/test_DownloadsViewableInternally.js @@ -25,10 +25,10 @@ const { ); /* global DownloadIntegration */ -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( this, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); const HandlerService = Cc[ diff --git a/browser/components/preferences/preferences.js b/browser/components/preferences/preferences.js index de60f05699bd..9e9ac5171fe6 100644 --- a/browser/components/preferences/preferences.js +++ b/browser/components/preferences/preferences.js @@ -28,10 +28,10 @@ var { Integration } = ChromeUtils.importESModule( "resource://gre/modules/Integration.sys.mjs" ); /* global DownloadIntegration */ -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( this, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); var { PrivateBrowsingUtils } = ChromeUtils.importESModule( diff --git a/toolkit/components/downloads/DownloadCore.sys.mjs b/toolkit/components/downloads/DownloadCore.sys.mjs index ab50d61339fc..6e47f8df634e 100644 --- a/toolkit/components/downloads/DownloadCore.sys.mjs +++ b/toolkit/components/downloads/DownloadCore.sys.mjs @@ -39,10 +39,10 @@ XPCOMUtils.defineLazyServiceGetter( Ci.nsIExternalHelperAppService ); -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); const BackgroundFileSaverStreamListener = Components.Constructor( diff --git a/toolkit/components/downloads/DownloadIntegration.sys.mjs b/toolkit/components/downloads/DownloadIntegration.sys.mjs index a99c6661900b..d0a7c6ddd632 100644 --- a/toolkit/components/downloads/DownloadIntegration.sys.mjs +++ b/toolkit/components/downloads/DownloadIntegration.sys.mjs @@ -74,10 +74,10 @@ XPCOMUtils.defineLazyServiceGetter( Ci.nsIApplicationReputationService ); -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); XPCOMUtils.defineLazyGetter(lazy, "gCombinedDownloadIntegration", () => { return lazy.DownloadIntegration; diff --git a/toolkit/components/downloads/Downloads.sys.mjs b/toolkit/components/downloads/Downloads.sys.mjs index c217e199676e..ae5c17abd36a 100644 --- a/toolkit/components/downloads/Downloads.sys.mjs +++ b/toolkit/components/downloads/Downloads.sys.mjs @@ -21,10 +21,10 @@ ChromeUtils.defineESModuleGetters(lazy, { DownloadSummary: "resource://gre/modules/DownloadList.sys.mjs", }); -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); /** diff --git a/toolkit/components/downloads/test/unit/head.js b/toolkit/components/downloads/test/unit/head.js index aa17d37b8799..b8e40e62bad5 100644 --- a/toolkit/components/downloads/test/unit/head.js +++ b/toolkit/components/downloads/test/unit/head.js @@ -46,10 +46,10 @@ XPCOMUtils.defineLazyServiceGetter( ); /* global DownloadIntegration */ -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( this, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); const ServerSocket = Components.Constructor( diff --git a/toolkit/modules/Integration.sys.mjs b/toolkit/modules/Integration.sys.mjs index faac5a93df69..499997023f4a 100644 --- a/toolkit/modules/Integration.sys.mjs +++ b/toolkit/modules/Integration.sys.mjs @@ -104,8 +104,6 @@ * reference changes when new integration overrides are registered. */ -import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; - /** * Maps integration point names to IntegrationPoint objects. */ @@ -253,7 +251,7 @@ IntegrationPoint.prototype = { /** * Defines a getter to retrieve the dynamically generated object implementing * the integration methods, loading the root implementation lazily from the - * specified JSM module. For example: + * specified sys.mjs module. For example: * * Integration.test.defineModuleGetter(this, "TestIntegration", * "resource://testing-common/TestIntegration.sys.mjs"); @@ -264,13 +262,13 @@ IntegrationPoint.prototype = { * The name of the getter to define. * @param moduleUrl * The URL used to obtain the module. - * @param symbol [optional] - * The name of the symbol exported by the module. This can be omitted - * if the name of the exported symbol is equal to the getter name. */ - defineModuleGetter(targetObject, name, moduleUrl, symbol) { + defineESModuleGetter(targetObject, name, moduleUrl) { let moduleHolder = {}; - XPCOMUtils.defineLazyModuleGetter(moduleHolder, name, moduleUrl, symbol); + // eslint-disable-next-line mozilla/lazy-getter-object-name + ChromeUtils.defineESModuleGetters(moduleHolder, { + [name]: moduleUrl, + }); Object.defineProperty(targetObject, name, { get: () => this.getCombined(moduleHolder[name]), configurable: true, diff --git a/toolkit/modules/tests/xpcshell/test_Integration.js b/toolkit/modules/tests/xpcshell/test_Integration.js index 324dca5384e3..d4b61f01efe0 100644 --- a/toolkit/modules/tests/xpcshell/test_Integration.js +++ b/toolkit/modules/tests/xpcshell/test_Integration.js @@ -218,30 +218,21 @@ add_task(async function test_xpcom_throws() { }); /** - * Checks that getters defined by defineModuleGetter are able to retrieve the + * Checks that getters defined by defineESModuleGetter are able to retrieve the * latest version of the combined integration object. */ -add_task(async function test_defineModuleGetter() { +add_task(async function test_defineESModuleGetter() { let objectForGetters = {}; - // Test with and without the optional "symbol" parameter. - Integration.testModule.defineModuleGetter( + Integration.testModule.defineESModuleGetter( objectForGetters, "TestIntegration", - "resource://testing-common/TestIntegration.jsm" - ); - Integration.testModule.defineModuleGetter( - objectForGetters, - "integration", - "resource://testing-common/TestIntegration.jsm", - "TestIntegration" + "resource://testing-common/TestIntegration.sys.mjs" ); Integration.testModule.register(overrideFn); - await assertCombinedResults(objectForGetters.integration, 1); await assertCombinedResults(objectForGetters.TestIntegration, 1); Integration.testModule.unregister(overrideFn); - await assertCombinedResults(objectForGetters.integration, 0); await assertCombinedResults(objectForGetters.TestIntegration, 0); }); diff --git a/toolkit/mozapps/downloads/HelperAppDlg.jsm b/toolkit/mozapps/downloads/HelperAppDlg.jsm index 529f9e0e2409..a161ee4445c9 100644 --- a/toolkit/mozapps/downloads/HelperAppDlg.jsm +++ b/toolkit/mozapps/downloads/HelperAppDlg.jsm @@ -25,10 +25,10 @@ XPCOMUtils.defineLazyServiceGetter( const { Integration } = ChromeUtils.importESModule( "resource://gre/modules/Integration.sys.mjs" ); -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); // ///////////////////////////////////////////////////////////////////////////// diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js index 28055825d30e..f5d5f15cc84c 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js @@ -25,7 +25,7 @@ const callExpressionDefinitions = [ /^loader\.lazyServiceGetter\(lazy, "(\w+)"/, /^loader\.lazyRequireGetter\(lazy, "(\w+)"/, /^XPCOMUtils\.defineLazyGetter\(lazy, "(\w+)"/, - /^Integration\.downloads\.defineModuleGetter\(lazy, "(\w+)"/, + /^Integration\.downloads\.defineESModuleGetter\(lazy, "(\w+)"/, /^XPCOMUtils\.defineLazyModuleGetter\(lazy, "(\w+)"/, /^ChromeUtils\.defineModuleGetter\(lazy, "(\w+)"/, /^XPCOMUtils\.defineLazyPreferenceGetter\(lazy, "(\w+)"/, diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/valid-lazy.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/valid-lazy.js index 4796291dae9d..6e207584fa92 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/tests/valid-lazy.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/tests/valid-lazy.js @@ -45,7 +45,7 @@ ruleTester.run("valid-lazy", rule, { `, ` const lazy = {}; - Integration.downloads.defineModuleGetter(lazy, "foo", "foo.jsm"); + Integration.downloads.defineESModuleGetter(lazy, "foo", "foo.sys.mjs"); if (x) { lazy.foo.bar(); } `, ` diff --git a/uriloader/exthandler/ExtHandlerService.sys.mjs b/uriloader/exthandler/ExtHandlerService.sys.mjs index c51fd74ade77..60ab01182bf4 100644 --- a/uriloader/exthandler/ExtHandlerService.sys.mjs +++ b/uriloader/exthandler/ExtHandlerService.sys.mjs @@ -25,10 +25,10 @@ ChromeUtils.defineESModuleGetters(lazy, { }); import { Integration } from "resource://gre/modules/Integration.sys.mjs"; -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( lazy, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); XPCOMUtils.defineLazyServiceGetter( diff --git a/uriloader/exthandler/tests/unit/test_downloads_improvements_migration.js b/uriloader/exthandler/tests/unit/test_downloads_improvements_migration.js index 1383ddae7ff4..44ff4dd0fe28 100644 --- a/uriloader/exthandler/tests/unit/test_downloads_improvements_migration.js +++ b/uriloader/exthandler/tests/unit/test_downloads_improvements_migration.js @@ -13,10 +13,10 @@ const { Integration } = ChromeUtils.importESModule( ); /* global DownloadIntegration */ -Integration.downloads.defineModuleGetter( +Integration.downloads.defineESModuleGetter( this, "DownloadIntegration", - "resource://gre/modules/DownloadIntegration.jsm" + "resource://gre/modules/DownloadIntegration.sys.mjs" ); /**