Bug 1381410 (part 4) - Add missing monitor enter in nsStringBundle::Format*() functions. r=emk.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 17 Jul 2017 18:36:16 +1000
changeset 418095 3756382ef3b77ecfbd89d142c21e0ed202dfbf6b
parent 418094 c528ff7eb1174dfc33d3d30b9da4b176fbacb5ff
child 418096 8cd4bd9ec8ae107a4c6a178c53aae56668804fbe
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1381410
milestone56.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 1381410 (part 4) - Add missing monitor enter in nsStringBundle::Format*() functions. r=emk. GetStringFromName() enters mReentrantMonitor(), and the other Get*() functions go through GetStringFromName(). But none of the Format*() functions enter the monitor. This patch moves some repeated code from GetStringFromName() and FormatStringFromName() into GetStringFromNameHelper(), including the monitor entry. All the Get*() and Format*() functions now use GetStringFromNameHelper(), which means they now all enter the monitor.
intl/strres/nsStringBundle.cpp
--- a/intl/strres/nsStringBundle.cpp
+++ b/intl/strres/nsStringBundle.cpp
@@ -111,17 +111,22 @@ nsStringBundle::LoadProperties()
   mLoaded = NS_SUCCEEDED(rv);
 
   return rv;
 }
 
 nsresult
 nsStringBundle::GetStringFromNameHelper(const char* aName, nsAString& aResult)
 {
-  nsresult rv;
+  NS_ENSURE_ARG_POINTER(aName);
+
+  nsresult rv = LoadProperties();
+  if (NS_FAILED(rv)) return rv;
+
+  ReentrantMonitorAutoEnter automon(mReentrantMonitor);
 
   // try override first
   if (mOverrideStrings) {
     rv = mOverrideStrings->GetStringFromName(mPropertiesURL,
                                              nsDependentCString(aName),
                                              aResult);
     if (NS_SUCCEEDED(rv)) return rv;
   }
@@ -154,26 +159,23 @@ nsStringBundle::FormatStringFromAUTF8Nam
 
 // this function supports at most 10 parameters.. see below for why
 NS_IMETHODIMP
 nsStringBundle::FormatStringFromName(const char* aName,
                                      const char16_t** aParams,
                                      uint32_t aLength,
                                      char16_t** aResult)
 {
-  NS_ENSURE_ARG_POINTER(aName);
+  NS_ENSURE_ARG_POINTER(aResult);
   NS_ASSERTION(aParams && aLength, "FormatStringFromName() without format parameters: use GetStringFromName() instead");
-  NS_ENSURE_ARG_POINTER(aResult);
 
-  nsresult rv;
-  rv = LoadProperties();
-  if (NS_FAILED(rv)) return rv;
+  *aResult = nullptr;
 
   nsAutoString formatStr;
-  rv = GetStringFromNameHelper(aName, formatStr);
+  nsresult rv = GetStringFromNameHelper(aName, formatStr);
   if (NS_FAILED(rv)) return rv;
 
   return FormatString(formatStr.get(), aParams, aLength, aResult);
 }
 
 NS_IMPL_ISUPPORTS(nsStringBundle, nsIStringBundle)
 
 NS_IMETHODIMP
@@ -189,27 +191,22 @@ nsStringBundle::GetStringFromAUTF8Name(c
                                        char16_t **aResult)
 {
   return GetStringFromName(PromiseFlatCString(aName).get(), aResult);
 }
 
 NS_IMETHODIMP
 nsStringBundle::GetStringFromName(const char* aName, char16_t** aResult)
 {
-  NS_ENSURE_ARG_POINTER(aName);
   NS_ENSURE_ARG_POINTER(aResult);
 
-  nsresult rv;
-  rv = LoadProperties();
-  if (NS_FAILED(rv)) return rv;
+  *aResult = nullptr;
 
-  ReentrantMonitorAutoEnter automon(mReentrantMonitor);
-  *aResult = nullptr;
   nsAutoString tmpstr;
-  rv = GetStringFromNameHelper(aName, tmpstr);
+  nsresult rv = GetStringFromNameHelper(aName, tmpstr);
   if (NS_FAILED(rv)) return rv;
 
   *aResult = ToNewUnicode(tmpstr);
   NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
 
   return NS_OK;
 }