Skip to content

Commit f00df01

Browse files
committed
Bug 1975980 - clear observed prefs when uninitializing SelectableProfileService to avoid uncaught exception when some observed prefs are automatically reset at the end of tests, r=profiles-reviewers,niklas.
Differential Revision: https://phabricator.services.mozilla.com/D256284
1 parent c523c77 commit f00df01

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

browser/components/profiles/SelectableProfileService.sys.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ class SelectableProfileServiceClass extends EventEmitter {
438438
this.#badge = null;
439439
this.#connection = null;
440440

441+
this.clearPrefObservers();
442+
441443
lazy.EveryWindow.unregisterCallback(this.#everyWindowCallbackId);
442444

443445
Services.obs.removeObserver(this, "pds-datastore-changed");
@@ -861,16 +863,20 @@ class SelectableProfileServiceClass extends EventEmitter {
861863
await this.#setDBPref(prefName, value);
862864
}
863865

866+
clearPrefObservers() {
867+
for (let prefName of this.#observedPrefs) {
868+
Services.prefs.removeObserver(prefName, this.prefObserver);
869+
}
870+
this.#observedPrefs.clear();
871+
}
872+
864873
/**
865874
* Fetch all prefs from the DB and write to the current instance.
866875
*/
867876
async loadSharedPrefsFromDatabase() {
868877
// This stops us from observing the change during the load and means we stop observing any prefs
869878
// no longer in the database.
870-
for (let prefName of this.#observedPrefs) {
871-
Services.prefs.removeObserver(prefName, this.prefObserver);
872-
}
873-
this.#observedPrefs.clear();
879+
this.clearPrefObservers();
874880

875881
for (let { name, value, type } of await this.getAllDBPrefs()) {
876882
if (SelectableProfileServiceClass.ignoredSharedPrefs.includes(name)) {

0 commit comments

Comments
 (0)