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.

--HG--
extra : rebase_source : 5d4c1931fb374d7aa10d6851f5ad8c0c774ffa79
This commit is contained in:
Nicholas Nethercote 2017-07-17 18:36:16 +10:00
Родитель cd092e2d5d
Коммит 5ea6cc2798
1 изменённых файлов: 11 добавлений и 14 удалений

Просмотреть файл

@ -116,7 +116,12 @@ nsStringBundle::LoadProperties()
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) {
@ -159,16 +164,13 @@ nsStringBundle::FormatStringFromName(const char* aName,
uint32_t aLength,
char16_t** aResult)
{
NS_ENSURE_ARG_POINTER(aName);
NS_ASSERTION(aParams && aLength, "FormatStringFromName() without format parameters: use GetStringFromName() instead");
NS_ENSURE_ARG_POINTER(aResult);
NS_ASSERTION(aParams && aLength, "FormatStringFromName() without format parameters: use GetStringFromName() instead");
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);
@ -194,17 +196,12 @@ nsStringBundle::GetStringFromAUTF8Name(const nsACString& aName,
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;
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);