Bug 1349470 - Use OS locale for unicode conversions for Date.toLocaleFormat. r?m_kato
MozReview-Commit-ID: KGYGRqtHOvJ
--- a/js/xpconnect/src/XPCLocale.cpp
+++ b/js/xpconnect/src/XPCLocale.cpp
@@ -12,24 +12,26 @@
#include "nsJSUtils.h"
#include "nsIPlatformCharset.h"
#include "nsICollation.h"
#include "nsUnicharUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/intl/LocaleService.h"
+#include "mozilla/intl/OSPreferences.h"
#include "mozilla/Preferences.h"
#include "nsIUnicodeDecoder.h"
#include "xpcpublic.h"
using namespace JS;
using mozilla::dom::EncodingUtils;
using mozilla::intl::LocaleService;
+using mozilla::intl::OSPreferences;
/**
* JS locale callbacks implemented by XPCOM modules. These are theoretically
* safe for use on multiple threads. Unfortunately, the intl code underlying
* these XPCOM modules doesn't yet support this, so in practice
* XPCLocaleCallbacks are limited to the main thread.
*/
struct XPCLocaleCallbacks : public JSLocaleCallbacks
@@ -159,20 +161,25 @@ private:
}
bool
ToUnicode(JSContext* cx, const char* src, MutableHandleValue rval)
{
nsresult rv;
if (!mDecoder) {
- // use app default locale
- nsAutoCString appLocale;
- LocaleService::GetInstance()->GetAppLocaleAsLangTag(appLocale);
- NS_ConvertUTF8toUTF16 localeStr(appLocale);
+ // This code is only used by our prioprietary toLocaleFormat method
+ // and should be removed once we get rid of it.
+ // toLocaleFormat is used in non-ICU scenarios where we don't have
+ // access to any other date/time than the OS one, so we have to also
+ // use the OS locale for unicode conversions.
+ // See bug 1349470 for more details.
+ nsAutoCString osLocale;
+ OSPreferences::GetInstance()->GetSystemLocale(osLocale);
+ NS_ConvertUTF8toUTF16 localeStr(osLocale);
nsCOMPtr<nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoCString charset;
rv = platformCharset->GetDefaultCharsetForLocale(localeStr, charset);
if (NS_SUCCEEDED(rv)) {