Closed Bug 1771463 Opened 2 years ago Closed 2 years ago

Do not export lazy getter "fxAccounts" from FxAccounts.jsm

Categories

(Firefox :: Firefox Accounts, task)

task

Tracking

()

RESOLVED FIXED
103 Branch
Tracking Status
firefox103 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

https://searchfox.org/mozilla-central/rev/b462b11e71b500e084f51e61fbd9e19ea0122c78/services/fxaccounts/FxAccounts.jsm#1615-1627

// A getter for the instance to export
XPCOMUtils.defineLazyGetter(this, "fxAccounts", function() {
  let a = new FxAccounts();

  // XXX Bug 947061 - We need a strategy for resuming email verification after
  // browser restart
  a._internal.loadAndPoll();

  return a;
});

// `AccountState` is exported for tests.
var EXPORTED_SYMBOLS = ["fxAccounts", "FxAccounts", "AccountState"];

This exports lazy getter "fxAccounts" defined on the per-JSM global this.
This is not possible with ESM, and this needs to be rewritten not to rely on global this

See Also: → 1771464

Options are:

(A) Export a plain object that has lazy getter

const LazyFxAccounts = {}; // a wrapper.  name is just an example
XPCOMUtils.defineLazyGetter(LazyFxAccounts, "fxAccounts", function() {
  let a = new FxAccounts();
  a._internal.loadAndPoll();
  return a;
});
var EXPORTED_SYMBOLS = ["LazyFxAccounts", ...];
XPCOMUtils.defineLazyModuleGetters(this, {
  LazyFxAccounts: "resource://gre/modules/FxAccounts.jsm",
});
...
LazyFxAccounts.fxAccounts.getSignedInUser()

(B) Export a function that caches the result

let cachedFxAccounts = null;
function getOrCreateFxAccounts() {
  if (!cachedFxAccounts) {
    cachedFxAccounts = new FxAccounts();
    cachedFxAccounts._internal.loadAndPoll();
  }
  return cachedFxAccounts;
}
var EXPORTED_SYMBOLS = ["getOrCreateFxAccounts", ...];
XPCOMUtils.defineLazyModuleGetters(this, {
  getOrCreateFxAccounts: "resource://gre/modules/FxAccounts.jsm",
});
...
getOrCreateFxAccounts().getSignedInUser()

:markh, can I have your opinion?

Which of the above (or yet another?) fits here?

Flags: needinfo?(markh)
Blocks: 1608279
See Also: → 1771478

I got another idea.

(C) Export a function that caches the result, and define lazy getter uses it

let cachedFxAccounts = null;
function getOrCreateFxAccounts() {
  if (!cachedFxAccounts) {
    cachedFxAccounts = new FxAccounts();
    cachedFxAccounts._internal.loadAndPoll();
  }
  return cachedFxAccounts;
}
var EXPORTED_SYMBOLS = ["getOrCreateFxAccounts", ...];
XPCOMUtils.defineLazyGetter(this, "fxAccounts", () => {
  return ChromeUtils.import("resource://gre/modules/FxAccounts.jsm").getOrCreateFxAccounts();
});
...
fxAccounts.getSignedInUser()

That way, each consumer of fxAccounts doesn't need change
bug 1608279 will move the getter on const lazy = {}; object, including this.

Instead of exporting lazy getter, export a function that returns the FxAccount
singleton, lazily creating on the first call, and define the lazy getter on the
consumer side that calls the function.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/697ab99d1c61
Do not export lazy getter "fxAccounts" from services/fxaccounts/FxAccounts.jsm. r=markh,preferences-reviewers

Backed out for causing node newtab failures.

Push with failures: https://treeherder.mozilla.org/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception%2Cusercancel&revision=697ab99d1c612ce2f022e1350edfa183606a5adf&selectedTaskRun=YPe-EEKiQfi4NX4lhw113w.0

Failure log: https://treeherder.mozilla.org/logviewer?job_id=379703147&repo=autoland

Backout link: https://hg.mozilla.org/integration/autoland/rev/4209d36810f57440c976c654ec910900b0e0520a

[task 2022-05-31T03:50:06.967Z] TEST START | karma
[task 2022-05-31T03:50:57.518Z] webpack was not included as a framework in karma configuration, setting this automatically...
[task 2022-05-31T03:50:57.518Z] Browserslist: caniuse-lite is outdated. Please run:
[task 2022-05-31T03:50:57.518Z]   npx browserslist@latest --update-db
[task 2022-05-31T03:50:57.518Z]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[task 2022-05-31T03:50:57.518Z] npm ERR! code ELIFECYCLE
[task 2022-05-31T03:50:57.518Z] npm ERR! errno 1
[task 2022-05-31T03:50:57.518Z] npm ERR! activity-streams@1.14.3 testmc:unit: `karma start karma.mc.config.js`
[task 2022-05-31T03:50:57.518Z] npm ERR! Exit status 1
[task 2022-05-31T03:50:57.518Z] npm ERR! 
[task 2022-05-31T03:50:57.518Z] npm ERR! Failed at the activity-streams@1.14.3 testmc:unit script.
[task 2022-05-31T03:50:57.518Z] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[task 2022-05-31T03:50:57.518Z] 
[task 2022-05-31T03:50:57.518Z] npm ERR! A complete log of this run can be found in:
[task 2022-05-31T03:50:57.518Z] npm ERR!     /builds/worker/.npm/_logs/2022-05-31T03_50_57_505Z-debug.log
[task 2022-05-31T03:50:57.520Z] { checkBundles: true, karma: false }
[task 2022-05-31T03:50:57.521Z] CODE 1
[taskcluster 2022-05-31 03:50:57.896Z] === Task Finished ===
[taskcluster 2022-05-31 03:50:57.897Z] Unsuccessful task run with exit code: 1 completed in 775.341 seconds
Flags: needinfo?(arai.unmht)
Flags: needinfo?(markh)
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/3e7c962cca71
Do not export lazy getter "fxAccounts" from services/fxaccounts/FxAccounts.jsm. r=markh,preferences-reviewers,Mardak
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 103 Branch
Flags: needinfo?(arai.unmht)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: