Bug 1406311 - sprintfjs: stop using spread arguments when calling sprintf() draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 06 Oct 2017 21:53:18 +0200
changeset 676184 79364b6f3ddb7474335c08c2fdfaf632198f2b38
parent 676174 0beba2692be2ed4d15df14399ffcc4876ea03f7a
child 676185 5531d37dda1fad46e5d39afa52c86bb15700f5ed
push id83417
push userjdescottes@mozilla.com
push dateFri, 06 Oct 2017 19:56:14 +0000
bugs1406311
milestone58.0a1
Bug 1406311 - sprintfjs: stop using spread arguments when calling sprintf() MozReview-Commit-ID: 5t2LRYWtuei
devtools/shared/l10n.js
devtools/shared/sprintfjs/sprintf.js
--- a/devtools/shared/l10n.js
+++ b/devtools/shared/l10n.js
@@ -113,18 +113,18 @@ LocalizationHelper.prototype = {
 
   /**
    * L10N shortcut function.
    *
    * @param string name
    * @param array args
    * @return string
    */
-  getFormatStr: function (name, ...args) {
-    return sprintf(this.getStr(name), ...args);
+  getFormatStr: function (name) {
+    return sprintf(this.getStr(name), arguments);
   },
 
   /**
    * L10N shortcut function for numeric arguments that need to be formatted.
    * All numeric arguments will be fixed to 2 decimals and given a localized
    * decimal separator. Other arguments will be left alone.
    *
    * @param string name
--- a/devtools/shared/sprintfjs/sprintf.js
+++ b/devtools/shared/sprintfjs/sprintf.js
@@ -46,27 +46,27 @@
         modulo: /^\x25{2}/,
         placeholder: /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosStTuvxX])/,
         key: /^([a-z_][a-z_\d]*)/i,
         key_access: /^\.([a-z_][a-z_\d]*)/i,
         index_access: /^\[(\d+)\]/,
         sign: /^[\+\-]/
     }
 
-    function sprintf() {
-        var key = arguments[0], cache = sprintf.cache
+    function sprintf(key, args) {
+        var cache = sprintf.cache
         if (!(cache[key] && cache.hasOwnProperty(key))) {
             cache[key] = sprintf.parse(key)
         }
-        return sprintf.format.call(null, cache[key], arguments)
+        return sprintf.format.call(null, cache[key], key, args)
     }
 
-    sprintf.format = function(parse_tree, argv) {
+    sprintf.format = function(parse_tree, key, argv) {
         if (parse_tree === SIMPLE_PATTERN) {
-            return argv[0].replace("%S", argv[1]);
+            return key.replace("%S", argv[1]);
         }
 
         var cursor = 1, tree_length = parse_tree.length, arg, output = [], i, k, match, pad, pad_character, pad_length, is_positive = true, sign = ''
         for (i = 0; i < tree_length; i++) {
             // parse tree contains either substrings or match results (array)
             if (typeof parse_tree[i] === 'string') {
                 output[output.length] = parse_tree[i]
             } else  {