Bug 1406311 - sprintfjs: move String case to the top of the sprintf format switch draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 06 Oct 2017 19:49:49 +0200
changeset 676180 e4c355aec80b5559798d6bfc5d872a68d26c0a90
parent 676179 df8cdbe75cd97ff34966653e69bb32987159bec6
child 676181 d8d7716bddfdb012f7203420a5b0441a173bfdac
push id83414
push userjdescottes@mozilla.com
push dateFri, 06 Oct 2017 19:50:13 +0000
bugs1406311
milestone58.0a1
Bug 1406311 - sprintfjs: move String case to the top of the sprintf format switch MozReview-Commit-ID: ENcQJEG4Axm
devtools/shared/sprintfjs/sprintf.js
--- a/devtools/shared/sprintfjs/sprintf.js
+++ b/devtools/shared/sprintfjs/sprintf.js
@@ -95,16 +95,21 @@
                     throw new TypeError(sprintf("[sprintf] expecting number but found %s", get_type(arg)))
                 }
 
                 if (re.number.test(match[8])) {
                     is_positive = arg >= 0
                 }
 
                 switch (match[8]) {
+                    case 'S':
+                    case 's':
+                        arg = String(arg)
+                        arg = (match[7] ? arg.substring(0, match[7]) : arg)
+                    break
                     case 'b':
                         arg = parseInt(arg, 10).toString(2)
                     break
                     case 'c':
                         arg = String.fromCharCode(parseInt(arg, 10))
                     break
                     case 'd':
                     case 'i':
@@ -120,21 +125,16 @@
                         arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg)
                     break
                     case 'g':
                         arg = match[7] ? parseFloat(arg).toPrecision(match[7]) : parseFloat(arg)
                     break
                     case 'o':
                         arg = arg.toString(8)
                     break
-                    case 's':
-                    case 'S':
-                        arg = String(arg)
-                        arg = (match[7] ? arg.substring(0, match[7]) : arg)
-                    break
                     case 't':
                         arg = String(!!arg)
                         arg = (match[7] ? arg.substring(0, match[7]) : arg)
                     break
                     case 'T':
                         arg = get_type(arg)
                         arg = (match[7] ? arg.substring(0, match[7]) : arg)
                     break