Closed Bug 1772969 Opened 2 months ago Closed 2 months ago

Rewrite XPCOMUtils.defineLazyModuleGetter consumers with alias

Categories

(Core :: XPConnect, task)

task

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(4 files)

XPCOMUtils.defineLazyModuleGetter supports 4th parameter, to import symbol with different name.
https://searchfox.org/mozilla-central/rev/426022c17bb140b7e2017c127c2fe2a47481dd18/js/xpconnect/loader/XPCOMUtils.jsm#203-209

* @param aName
*        The name of the getter to define on aObject for the module.
* @param aResource
*        The URL used to obtain the module.
* @param aSymbol
*        The name of the symbol exported by the module.
*        This parameter is optional and defaults to aName.

example usage:
https://searchfox.org/mozilla-central/rev/426022c17bb140b7e2017c127c2fe2a47481dd18/remote/shared/messagehandler/ModuleCache.jsm#25-30

XPCOMUtils.defineLazyModuleGetter(
  this,
  "getTestModuleClass",
  "chrome://mochitests/content/browser/remote/shared/messagehandler/test/browser/resources/modules/ModuleRegistry.jsm",
  "getModuleClass"
);

This is not supported by defineESMGetters API

Possible options are:

  • Fix module that exports the symbol
    • Export with different name from the module
    • Export with alias from the module
  • Fix module that imports the symbol
    • Just import without alias
  • Support alias in the lazy getter API

https://searchfox.org/mozilla-central/rev/49566d906ad040cf233b0a5acd597e1a63b92f72/remote/shared/messagehandler/ModuleCache.jsm#16,22-23,25-32

XPCOMUtils.defineLazyModuleGetters(lazy, {
...
  getModuleClass:
    "chrome://remote/content/webdriver-bidi/modules/ModuleRegistry.jsm",
...
});

XPCOMUtils.defineLazyModuleGetter(
  lazy,
  "getTestModuleClass",
  "chrome://mochitests/content/browser/remote/shared/messagehandler/test/browser/resources/modules/ModuleRegistry.jsm",
  "getModuleClass"
);

In this case, the testing module can export with getTestModuleClass alias.

https://searchfox.org/mozilla-central/rev/49566d906ad040cf233b0a5acd597e1a63b92f72/services/sync/modules/engines/extension-storage.js#34-39

XPCOMUtils.defineLazyModuleGetter(
  lazy,
  "extensionStorageSyncKinto",
  "resource://gre/modules/ExtensionStorageSyncKinto.jsm",
  "extensionStorageSync"
);

https://searchfox.org/mozilla-central/rev/49566d906ad040cf233b0a5acd597e1a63b92f72/toolkit/components/extensions/ExtensionStorageSync.jsm#41-47

// We might end up falling back to kinto...
XPCOMUtils.defineLazyModuleGetter(
  lazy,
  "extensionStorageSyncKinto",
  "resource://gre/modules/ExtensionStorageSyncKinto.jsm",
  "extensionStorageSync"
);

In those 2 cases, the kinto module can export with extensionStorageSyncKinto alias.

https://searchfox.org/mozilla-central/rev/49566d906ad040cf233b0a5acd597e1a63b92f72/toolkit/components/taskscheduler/TaskScheduler.jsm#16-28

XPCOMUtils.defineLazyModuleGetter(
  lazy,
  "WinImpl",
  "resource://gre/modules/TaskSchedulerWinImpl.jsm",
  "_TaskSchedulerWinImpl"
);

XPCOMUtils.defineLazyModuleGetter(
  lazy,
  "MacOSImpl",
  "resource://gre/modules/TaskSchedulerMacOSImpl.jsm",
  "_TaskSchedulerMacOSImpl"
);

In those 2 cases, I don't think those modules need to export with _TaskScheduler prefix.
Just renaming the symbols should solve.

https://searchfox.org/mozilla-central/rev/49566d906ad040cf233b0a5acd597e1a63b92f72/toolkit/components/downloads/DownloadIntegration.jsm#120-127,181

// We have to use the gCombinedDownloadIntegration identifier because, in this
// module only, the DownloadIntegration identifier refers to the base version.
Integration.downloads.defineModuleGetter(
  lazy,
  "gCombinedDownloadIntegration",
  "resource://gre/modules/DownloadIntegration.jsm",
  "DownloadIntegration"
);
...
var DownloadIntegration = {

This case doesn't need alias, because lazy getter on lazy object doesn't conflict with global variable.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Summary: Figure out what to do with lazy getter API with alias → Rewrite XPCOMUtils.defineLazyModuleGetter consumers with alias
Attachment #9281954 - Attachment description: Bug 1772969 - Part 1: Rename getModuleClass with getTestModuleClass in test ModuleRegistry.jsm module. r?#webdriver-reviewers! → Bug 1772969 - Part 1: Define lazy getter for ModuleRegistry.jsm on different objects for each protocol. r?#webdriver-reviewers!
Attachment #9281957 - Attachment description: Bug 1772969 - Part 4: Stop using different name for DownloadIntegration. r?Gijs! → Bug 1772969 - Part 4: Use plain lazy getter to add alias for DownloadIntegration. r?Gijs!
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/95c504ebc0ac
Part 1: Define lazy getter for ModuleRegistry.jsm on different objects for each protocol. r=webdriver-reviewers,jdescottes
https://hg.mozilla.org/integration/autoland/rev/f59ba82197c4
Part 2: Rename ExtensionStorageSync with ExtensionStorageSyncKinto for Kinto implementation. r=markh
https://hg.mozilla.org/integration/autoland/rev/e649299772e3
Part 3: Remove _TaskScheduler prefix from implementations. r=nalexander
https://hg.mozilla.org/integration/autoland/rev/9b8ccbaf78b7
Part 4: Use plain lazy getter to add alias for DownloadIntegration. r=Gijs
You need to log in before you can comment on or make changes to this bug.