[gjs/wip/ptomato/mozjs38: 6/26] format: More fixes for standard String.replace()



commit 25b8595079f4af1285ee241d58f19f78cdb8a4a4
Author: Philip Chimento <philip endlessm com>
Date:   Thu Jan 19 18:33:13 2017 -0800

    format: More fixes for standard String.replace()
    
    This is a followup to commit 2cf42c598c0e43394b3fe1cb7d50d3ed716ca3c4
    where parameters to the callback given to String.replace() may be
    undefined, not '', for groups that are not matched. In SpiderMonkey 38,
    String.replace() was changed to have the standard behaviour.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776966

 modules/format.js |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/modules/format.js b/modules/format.js
index a3cb297..84a1d7b 100644
--- a/modules/format.js
+++ b/modules/format.js
@@ -6,10 +6,12 @@ function vprintf(str, args) {
     let i = 0;
     let usePos = false;
     return str.replace(/%(?:([1-9][0-9]*)\$)?(I+)?([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, posGroup, 
flagsGroup, widthGroup, precisionGroup, genericGroup) {
-        if (precisionGroup != '' && genericGroup != 'f')
+        if (precisionGroup !== '' && precisionGroup !== undefined &&
+            genericGroup != 'f')
             throw new Error("Precision can only be specified for 'f'");
 
-        let hasAlternativeIntFlag = (flagsGroup.indexOf('I') != -1);
+        let hasAlternativeIntFlag = (flagsGroup &&
+            flagsGroup.indexOf('I') != -1);
         if (hasAlternativeIntFlag && genericGroup != 'd')
             throw new Error("Alternative output digits can only be specfied for 'd'");
 
@@ -19,7 +21,7 @@ function vprintf(str, args) {
         if (usePos && pos == 0 || !usePos && pos > 0)
             throw new Error("Numbered and unnumbered conversion specifications cannot be mixed");
 
-        let fillChar = (widthGroup[0] == '0') ? '0' : ' ';
+        let fillChar = (widthGroup && widthGroup[0] == '0') ? '0' : ' ';
         let width = parseInt(widthGroup, 10) || 0;
 
         function fillWidth(s, c, w) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]