Bug 1349470 - Use OS locale for unicode conversions for Date.toLocaleFormat. r?m_kato draft
authorZibi Braniecki <gandalf@mozilla.com>
Wed, 22 Mar 2017 09:10:18 -0700
changeset 502996 d4d2ec32243e415878691cd7934d456e75cebf5f
parent 502661 201231223cd4354a450c3e5d80959f35b8e4cf0c
child 550302 f2c13d0c4116c224a763a5b923606199da8588a0
push id50443
push userzbraniecki@mozilla.com
push dateWed, 22 Mar 2017 16:11:18 +0000
reviewersm_kato
bugs1349470
milestone55.0a1
Bug 1349470 - Use OS locale for unicode conversions for Date.toLocaleFormat. r?m_kato MozReview-Commit-ID: KGYGRqtHOvJ
js/xpconnect/src/XPCLocale.cpp
--- 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)) {