Bug 1667493 - Locale service shouldn't shutdown during normal shutting down phase. r=jfkthame

Although ICUUtils uses LocaleService, LocaleService will be shut down before
shut down observer.

DOM might use Locale Service by UnbindFromTree. So LocaleService should be
shut down by ShutdownPhase::ShutdownPostLastCycleCollection.

Differential Revision: https://phabricator.services.mozilla.com/D94944
This commit is contained in:
Makoto Kato 2020-11-11 03:33:04 +00:00
parent 0c4a7d9835
commit 350116618e
5 changed files with 32 additions and 3 deletions

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html class="reftest-wait">
<script>
function runTest() {
let win = window.open("1667493_1.html");
win.finish = function() {
document.documentElement.removeAttribute("class");
};
}
</script>
<body onload="runTest()">
</body>
</html>

View File

@ -0,0 +1,7 @@
<script>
window.requestIdleCallback(() => {
window.close();
finish();
});
</script>
<input required="" value="r" type="number">

View File

@ -88,3 +88,4 @@ load 1547057.html
load 1550524.html
load 1550881-1.html
load 1550881-2.html
skip-if(Android) pref(dom.disable_open_during_load,false) load 1667493.html

View File

@ -147,20 +147,24 @@ LocaleService* LocaleService::GetInstance() {
mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(sInstance, INTL_SYSTEM_LOCALES_CHANGED, true);
obs->AddObserver(sInstance, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
}
}
ClearOnShutdown(&sInstance, ShutdownPhase::Shutdown);
// DOM might use ICUUtils and LocaleService during UnbindFromTree by
// final cycle collection.
ClearOnShutdown(&sInstance, ShutdownPhase::ShutdownPostLastCycleCollection);
}
return sInstance;
}
LocaleService::~LocaleService() {
void LocaleService::RemoveObservers() {
if (mIsServer) {
Preferences::RemoveObservers(this, kObservedPrefs);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, INTL_SYSTEM_LOCALES_CHANGED);
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
}
}
}
@ -270,6 +274,8 @@ LocaleService::Observe(nsISupports* aSubject, const char* aTopic,
if (!strcmp(aTopic, INTL_SYSTEM_LOCALES_CHANGED)) {
RequestedLocalesChanged();
WebExposedLocalesChanged();
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
RemoveObservers();
} else {
NS_ConvertUTF16toUTF8 pref(aData);
// At the moment the only thing we're observing are settings indicating

View File

@ -179,7 +179,9 @@ class LocaleService final : public mozILocaleService,
void InitPackagedLocales();
virtual ~LocaleService();
void RemoveObservers();
virtual ~LocaleService() = default;
nsAutoCStringN<16> mDefaultLocale;
nsTArray<nsCString> mAppLocales;