зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1533481 - Part 1: Use ICU to retrieve the system default locale. r=jwalden!
Summary: We're setting LC_ALL to "en_US.UTF-8" in js/src/tests/lib/tests.py, but somehow this doesn't always work, for example on the Try-servers the default locale is set to "und", but this effect wasn't reproducible locally. Switch to ICU's default locale function which contains multiple fallbacks to ensure LC_ALL is honoured as expected. Reviewers: jwalden Reviewed By: jwalden Subscribers: jandem Bug #: 1533481 Differential Revision: https://phabricator.services.mozilla.com/D25261 --HG-- extra : rebase_source : a85c87c142f56753d95d519da109773d30f7db95
This commit is contained in:
Родитель
216f9c90e5
Коммит
f008d21b46
|
@ -0,0 +1,16 @@
|
|||
// |reftest| skip-if(!this.hasOwnProperty("Intl")||!xulRuntime.shell)
|
||||
|
||||
// js/src/tests/lib/tests.py sets the default locale to "en-US" for shell tests.
|
||||
// Ensure it's correctly set in the runtime and for the Intl service constructors.
|
||||
const defaultLocale = "en-US";
|
||||
|
||||
assertEq(getDefaultLocale(), defaultLocale);
|
||||
|
||||
assertEq(new Intl.Collator().resolvedOptions().locale, defaultLocale);
|
||||
assertEq(new Intl.DateTimeFormat().resolvedOptions().locale, defaultLocale);
|
||||
assertEq(new Intl.NumberFormat().resolvedOptions().locale, defaultLocale);
|
||||
assertEq(new Intl.PluralRules().resolvedOptions().locale, defaultLocale);
|
||||
assertEq(new Intl.RelativeTimeFormat().resolvedOptions().locale, defaultLocale);
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
|
@ -40,6 +40,9 @@
|
|||
#include "js/SliceBudget.h"
|
||||
#include "js/StableStringChars.h"
|
||||
#include "js/Wrapper.h"
|
||||
#if EXPOSE_INTL_API
|
||||
# include "unicode/uloc.h"
|
||||
#endif
|
||||
#include "util/Windows.h"
|
||||
#include "vm/DateTime.h"
|
||||
#include "vm/Debugger.h"
|
||||
|
@ -536,7 +539,13 @@ const char* JSRuntime::getDefaultLocale() {
|
|||
return defaultLocale.ref().get();
|
||||
}
|
||||
|
||||
// Use ICU if available to retrieve the default locale, this ensures ICU's
|
||||
// default locale matches our default locale.
|
||||
#if EXPOSE_INTL_API
|
||||
const char* locale = uloc_getDefault();
|
||||
#else
|
||||
const char* locale = setlocale(LC_ALL, nullptr);
|
||||
#endif
|
||||
|
||||
// convert to a well-formed BCP 47 language tag
|
||||
if (!locale || !strcmp(locale, "C")) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче