Bug 1349470 - Use OS locale for unicode conversions for Date.toLocaleFormat. r=m_kato
authorZibi Braniecki <gandalf@mozilla.com>
Wed, 22 Mar 2017 09:10:18 -0700
changeset 348990 1038d1c502befc9217de56f92665bdd536cdd30e
parent 348989 5a84ab13274ad2bcda1e80b4b11fd57f9952c070
child 348991 0c15ca7e1ba72121fddcca37e24ba5270d38a399
push id39370
push userzbraniecki@mozilla.com
push dateThu, 23 Mar 2017 03:41:42 +0000
treeherderautoland@1038d1c502be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1349470
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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)) {