Bug 1009795 - Part 2: Revert to the old gDecimalSymbol hack if the Internationalization API is not available; r=mak a=sylvestre
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 31 Aug 2015 23:20:05 -0400
changeset 289160 93acdc6a833d738979e974d5ab78c750233c937d
parent 289159 99be82d7ce88487bd4ae6dcd6baa003b46d9e76b
child 289161 61696a11d20d1f70ac7cb43d673d9641a4e0129f
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, sylvestre
bugs1009795, 1200494
milestone42.0a2
Bug 1009795 - Part 2: Revert to the old gDecimalSymbol hack if the Internationalization API is not available; r=mak a=sylvestre This will be removed in bug 1200494.
toolkit/mozapps/downloads/DownloadUtils.jsm
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -41,16 +41,21 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
 
+this.__defineGetter__("gDecimalSymbol", function() {
+    delete this.gDecimalSymbol;
+      return this.gDecimalSymbol = Number(5.4).toLocaleString().match(/\D/);
+});
+
 let localeNumberFormatCache = new Map();
 function getLocaleNumberFormat(fractionDigits) {
   // Backward compatibility: don't use localized digits
   let locale = Intl.NumberFormat().resolvedOptions().locale +
                "-u-nu-latn";
   let key = locale + "_" + fractionDigits;
   if (!localeNumberFormatCache.has(key)) {
     localeNumberFormatCache.set(key,
@@ -473,18 +478,23 @@ this.DownloadUtils = {
     // 0 -> 0; 1.2 -> 1.2; 12.3 -> 12.3; 123.4 -> 123; 234.5 -> 235
     // added in bug 462064: (unitIndex != 0) makes sure that no decimal digit for bytes appears when aBytes < 100
     let fractionDigits = (aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? 1 : 0;
 
     // Don't try to format Infinity values using NumberFormat.
     if (aBytes === Infinity) {
       aBytes = "Infinity";
     } else {
-      aBytes = getLocaleNumberFormat(fractionDigits)
-                 .format(aBytes);
+      if (Intl) {
+        aBytes = getLocaleNumberFormat(fractionDigits)
+                   .format(aBytes);
+      } else if (gDecimalSymbol != ".") {
+        // FIXME: Fall back to the old hack, will be fixed in bug 1200494.
+        aBytes = aBytes.toFixed(fractionDigits).replace(".", gDecimalSymbol);
+      }
     }
 
     return [aBytes, gBundle.GetStringFromName(gStr.units[unitIndex])];
   },
 
   /**
    * Converts a number of seconds to the two largest units. Time values are
    * whole numbers, and units have the correct plural/singular form.