Bug 1573720 - Convert dom.forms.number.grouping to a static pref. r=m_kato
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 15 Aug 2019 05:29:16 +0000
changeset 488184 a35f22f9d97ab8052dc49f378d0deb345c0276c9
parent 488183 be174ffafb1d907a290e5838cca043ead0cd9443
child 488185 0bef6c2195bc758dffd7265b06c0502d1612918f
push id113904
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:41:00 +0000
treeherdermozilla-inbound@b283a7ef186c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1573720
milestone70.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 1573720 - Convert dom.forms.number.grouping to a static pref. r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D41911
intl/unicharutil/util/ICUUtils.cpp
modules/libpref/init/StaticPrefList.yaml
--- a/intl/unicharutil/util/ICUUtils.cpp
+++ b/intl/unicharutil/util/ICUUtils.cpp
@@ -3,17 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifdef MOZILLA_INTERNAL_API
 
 #  include "mozilla/Assertions.h"
 #  include "mozilla/UniquePtr.h"
 
 #  include "ICUUtils.h"
-#  include "mozilla/Preferences.h"
+#  include "mozilla/StaticPrefs_dom.h"
 #  include "mozilla/intl/LocaleService.h"
 #  include "nsIContent.h"
 #  include "mozilla/dom/Document.h"
 #  include "nsString.h"
 #  include "unicode/uloc.h"
 #  include "unicode/unum.h"
 
 using namespace mozilla;
@@ -25,38 +25,16 @@ class NumberFormatDeleter {
     MOZ_ASSERT(aPtr != nullptr,
                "UniquePtr deleter shouldn't be called for nullptr");
     unum_close(aPtr);
   }
 };
 
 using UniqueUNumberFormat = UniquePtr<UNumberFormat, NumberFormatDeleter>;
 
-/**
- * This pref just controls whether we format the number with grouping separator
- * characters when the internal value is set or updated. It does not stop the
- * user from typing in a number and using grouping separators.
- */
-static bool gLocaleNumberGroupingEnabled;
-static const char LOCALE_NUMBER_GROUPING_PREF_STR[] =
-    "dom.forms.number.grouping";
-
-static bool LocaleNumberGroupingIsEnabled() {
-  static bool sInitialized = false;
-
-  if (!sInitialized) {
-    /* check and register ourselves with the pref */
-    Preferences::AddBoolVarCache(&gLocaleNumberGroupingEnabled,
-                                 LOCALE_NUMBER_GROUPING_PREF_STR, false);
-    sInitialized = true;
-  }
-
-  return gLocaleNumberGroupingEnabled;
-}
-
 void ICUUtils::LanguageTagIterForContent::GetNext(nsACString& aBCP47LangTag) {
   if (mCurrentFallbackIndex < 0) {
     mCurrentFallbackIndex = 0;
     // Try the language specified by a 'lang'/'xml:lang' attribute on mContent
     // or any ancestor, if such an attribute is specified:
     nsAutoString lang;
     mContent->GetLang(lang);
     if (!lang.IsEmpty()) {
@@ -110,17 +88,17 @@ bool ICUUtils::LocalizeNumber(double aVa
         unum_open(UNUM_DECIMAL, nullptr, 0, langTag.get(), nullptr, &status));
     // Since unum_setAttribute have no UErrorCode parameter, we have to
     // check error status.
     if (U_FAILURE(status)) {
       aLangTags.GetNext(langTag);
       continue;
     }
     unum_setAttribute(format.get(), UNUM_GROUPING_USED,
-                      LocaleNumberGroupingIsEnabled());
+                      StaticPrefs::dom_forms_number_grouping());
     // ICU default is a maximum of 3 significant fractional digits. We don't
     // want that limit, so we set it to the maximum that a double can represent
     // (14-16 decimal fractional digits).
     unum_setAttribute(format.get(), UNUM_MAX_FRACTION_DIGITS, 16);
     int32_t length = unum_formatDouble(format.get(), aValue, buffer,
                                        kBufferSize, nullptr, &status);
     NS_ASSERTION(length < kBufferSize && status != U_BUFFER_OVERFLOW_ERROR &&
                      status != U_STRING_NOT_TERMINATED_WARNING,
@@ -146,17 +124,17 @@ double ICUUtils::ParseNumber(nsAString& 
   uint32_t length = aValue.Length();
 
   nsAutoCString langTag;
   aLangTags.GetNext(langTag);
   while (!langTag.IsEmpty()) {
     UErrorCode status = U_ZERO_ERROR;
     UniqueUNumberFormat format(
         unum_open(UNUM_DECIMAL, nullptr, 0, langTag.get(), nullptr, &status));
-    if (!LocaleNumberGroupingIsEnabled()) {
+    if (!StaticPrefs::dom_forms_number_grouping()) {
       unum_setAttribute(format.get(), UNUM_GROUPING_USED, UBool(0));
     }
     int32_t parsePos = 0;
     static_assert(sizeof(UChar) == 2 && sizeof(nsAString::char_type) == 2,
                   "Unexpected character size - the following cast is unsafe");
     double val = unum_parseDouble(format.get(),
                                   (const UChar*)PromiseFlatString(aValue).get(),
                                   length, &parsePos, &status);
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -1392,16 +1392,24 @@
   mirror: always
 
 # Support @autocomplete values for form autofill feature.
 - name: dom.forms.autocomplete.formautofill
   type: bool
   value: false
   mirror: always
 
+# This pref just controls whether we format the number with grouping separator
+# characters when the internal value is set or updated. It does not stop the
+# user from typing in a number and using grouping separators.
+- name: dom.forms.number.grouping
+  type: bool
+  value: false
+  mirror: always
+
 # Whether the Gamepad API is enabled
 - name: dom.gamepad.enabled
   type: bool
   value: true
   mirror: always
 
 # Is Gamepad Extension API enabled?
 - name: dom.gamepad.extensions.enabled