Bug 1493955 - Store floating-point preferences in a locale-independent way r=njn

Differential Revision: https://phabricator.services.mozilla.com/D6796
This commit is contained in:
Gabriele Svelto
2018-09-28 20:54:09 +00:00
parent 78e956be32
commit 665dc4ae79
8 changed files with 15 additions and 6 deletions

View File

@@ -2394,6 +2394,7 @@ nsPrefBranch::GetFloatPref(const char* aPrefName, float* aRetVal)
nsAutoCString stringVal; nsAutoCString stringVal;
nsresult rv = GetCharPref(aPrefName, stringVal); nsresult rv = GetCharPref(aPrefName, stringVal);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// ToFloat() does a locale-independent conversion.
*aRetVal = stringVal.ToFloat(&rv); *aRetVal = stringVal.ToFloat(&rv);
} }
@@ -5035,6 +5036,7 @@ Preferences::GetFloat(const char* aPrefName,
nsAutoCString result; nsAutoCString result;
nsresult rv = Preferences::GetCString(aPrefName, result, aKind); nsresult rv = Preferences::GetCString(aPrefName, result, aKind);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
// ToFloat() does a locale-independent conversion.
*aResult = result.ToFloat(&rv); *aResult = result.ToFloat(&rv);
} }
return rv; return rv;
@@ -5845,7 +5847,9 @@ static void
SetPref_float(const char* aName, float aDefaultValue) SetPref_float(const char* aName, float aDefaultValue)
{ {
PrefValue value; PrefValue value;
nsPrintfCString defaultValue("%f", aDefaultValue); // Convert the value in a locale-independent way.
nsAutoCString defaultValue;
defaultValue.AppendFloat(aDefaultValue);
value.mStringVal = defaultValue.get(); value.mStringVal = defaultValue.get();
pref_SetPref(aName, pref_SetPref(aName,
PrefType::String, PrefType::String,
@@ -5973,8 +5977,7 @@ InitVarCachePref(const nsACString& aName,
} }
} }
// XXX: this will eventually become used static void
MOZ_MAYBE_UNUSED static void
InitVarCachePref(const nsACString& aName, InitVarCachePref(const nsACString& aName,
float* aCache, float* aCache,
float aDefaultValue, float aDefaultValue,

View File

@@ -19,7 +19,6 @@
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsPrintfCString.h"
#include "nsString.h" #include "nsString.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
@@ -309,7 +308,9 @@ public:
float aValue, float aValue,
PrefValueKind aKind = PrefValueKind::User) PrefValueKind aKind = PrefValueKind::User)
{ {
return SetCString(aPrefName, nsPrintfCString("%f", aValue), aKind); nsAutoCString value;
value.AppendFloat(aValue);
return SetCString(aPrefName, value, aKind);
} }
static nsresult SetCString(const char* aPrefName, static nsresult SetCString(const char* aPrefName,

View File

@@ -30,6 +30,7 @@
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsPrintfCString.h"
#include "nsScriptSecurityManager.h" #include "nsScriptSecurityManager.h"
#include "nsSandboxFlags.h" #include "nsSandboxFlags.h"
#include "prtime.h" #include "prtime.h"

View File

@@ -29,6 +29,7 @@
#include "nsILoadInfo.h" #include "nsILoadInfo.h"
#include "nsIXULRuntime.h" #include "nsIXULRuntime.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsPrintfCString.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"

View File

@@ -4,6 +4,8 @@
#include "other/CombinedStacks.h" #include "other/CombinedStacks.h"
#include "other/ProcessedStack.h" #include "other/ProcessedStack.h"
#include "nsPrintfCString.h"
using namespace mozilla::Telemetry; using namespace mozilla::Telemetry;
using namespace TelemetryTestHelpers; using namespace TelemetryTestHelpers;

View File

@@ -23,6 +23,7 @@
#include "InfallibleVector.h" #include "InfallibleVector.h"
#include "MemorySnapshot.h" #include "MemorySnapshot.h"
#include "nsPrintfCString.h"
#include "ParentInternal.h" #include "ParentInternal.h"
#include "ProcessRecordReplay.h" #include "ProcessRecordReplay.h"
#include "ProcessRedirect.h" #include "ProcessRedirect.h"

View File

@@ -16,7 +16,6 @@
#include "mozilla/SchedulerGroup.h" #include "mozilla/SchedulerGroup.h"
#include "nsCycleCollector.h" #include "nsCycleCollector.h"
#include "nsIThread.h" #include "nsIThread.h"
#include "nsPrintfCString.h"
#include "nsThread.h" #include "nsThread.h"
#include "nsThreadManager.h" #include "nsThreadManager.h"
#include "PrioritizedEventQueue.h" #include "PrioritizedEventQueue.h"

View File

@@ -14,6 +14,7 @@
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsILabelableRunnable.h" #include "nsILabelableRunnable.h"
#include "nsPrintfCString.h"
// Windows silliness. winbase.h defines an empty no-argument Yield macro. // Windows silliness. winbase.h defines an empty no-argument Yield macro.
#undef Yield #undef Yield