Do not export lazy getter "fxAccounts" from FxAccounts.jsm
Categories
(Firefox :: Firefox Accounts, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox103 | --- | fixed |
People
(Reporter: arai, Assigned: arai)
References
Details
Attachments
(1 file)
// 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
Assignee | ||
Comment 1•2 years ago
•
|
||
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()
Assignee | ||
Comment 2•2 years ago
|
||
:markh, can I have your opinion?
Which of the above (or yet another?) fits here?
Assignee | ||
Comment 3•2 years ago
|
||
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.
Assignee | ||
Comment 4•2 years ago
|
||
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.
Updated•2 years ago
|
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
Comment 6•2 years ago
|
||
Backed out for causing node newtab failures.
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
Assignee | ||
Updated•2 years ago
|
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
Comment 8•2 years ago
|
||
bugherder |
Assignee | ||
Updated•2 years ago
|
Description
•