Bug 1358543 - Only set new locale callbacks in xpc_LocalizeContext if they're not set. r=smaug
authorZibi Braniecki <gandalf@mozilla.com>
Fri, 21 Apr 2017 09:49:42 -0700
changeset 566671 c8cc3f9c8d5d9fff2d7b53cc8a545cc3a31eed12
parent 566670 a4746985e0ba9060bc7b64fd7d7355c24d88dd1e
child 566672 28b8c2b9e9fa1f97e2bc3b22d76513a50c1ec4a0
push id55296
push userzbraniecki@mozilla.com
push dateFri, 21 Apr 2017 23:53:52 +0000
reviewerssmaug
bugs1358543, 1356066
milestone55.0a1
Bug 1358543 - Only set new locale callbacks in xpc_LocalizeContext if they're not set. r=smaug With changes introduced in bug 1356066 I made the xpc_LocalizeContext be called on each app locale change to update the default locale in each context. Unfortunately, this function is also assigning the locale callbacks and with my change it started doing it on each language change. In this patch I'm first checking if we do have XPCLocaleCallbacks for the given context and only if we don't, I assign them. MozReview-Commit-ID: 7AiCsJfKBID
js/xpconnect/src/XPCLocale.cpp
--- a/js/xpconnect/src/XPCLocale.cpp
+++ b/js/xpconnect/src/XPCLocale.cpp
@@ -231,17 +231,24 @@ private:
 #ifdef DEBUG
   PRThread* mThread;
 #endif
 };
 
 bool
 xpc_LocalizeContext(JSContext* cx)
 {
-  JS_SetLocaleCallbacks(cx, new XPCLocaleCallbacks());
+  // We want to assign the locale callbacks only the first time we
+  // localize the context.
+  // All consequent calls to this function are result of language changes
+  // and should not assign it again.
+  const JSLocaleCallbacks* lc = JS_GetLocaleCallbacks(cx);
+  if (!lc) {
+    JS_SetLocaleCallbacks(cx, new XPCLocaleCallbacks());
+  }
 
   // Set the default locale.
 
   // Check a pref to see if we should use US English locale regardless
   // of the system locale.
   if (Preferences::GetBool("javascript.use_us_english_locale", false)) {
     return JS_SetDefaultLocale(cx, "en-US");
   }