Bug 1108382 - Part 6: Do not use non-standard flag argument of String.prototype.replace in dom/. r=peterv
authorTooru Fujisawa <arai_a@mac.com>
Sun, 01 Mar 2015 09:51:33 +0900
changeset 246740 6619751c0bb5964241c1d16a6a57a41f08660425
parent 246739 2a7d96c1b3c653de9ef006eac13bbbd8d4cc4977
child 246741 ea8d2ec9cf941b8bba878f756131dbe318e1334b
push id879
push usercliu@mozilla.com
push dateTue, 03 Mar 2015 03:02:53 +0000
reviewerspeterv
bugs1108382
milestone39.0a1
Bug 1108382 - Part 6: Do not use non-standard flag argument of String.prototype.replace in dom/. r=peterv
dom/base/test/test_bug902847.html
dom/canvas/test/test_toDataURL_alpha.html
dom/html/test/forms/test_input_typing_sanitization.html
dom/html/test/test_documentAll.html
dom/html/test/test_formSubmission.html
--- a/dom/base/test/test_bug902847.html
+++ b/dom/base/test/test_bug902847.html
@@ -22,18 +22,18 @@ https://bugzilla.mozilla.org/show_bug.cg
                 de.OutputDontRemoveLineEndingSpaces;
     encoder.init(document, "text/plain", flags);
 
     function toPlaintext(id) {
       var element = document.getElementById(id);
       var range = document.createRange();
       range.selectNodeContents(element);
       encoder.setRange(range);
-      return encoder.encodeToString().replace('\n', '\\n', 'g')
-                                     .replace('\r', '\\r', 'g');
+      return encoder.encodeToString().replace(/\n/g, '\\n')
+                                     .replace(/\r/g, '\\r');
     }
 
     // Test cases.
     is(toPlaintext("case1"), "Hello \\nboy!", "Case 1 failed.");
     is(toPlaintext("case2"), "Hello \\nboy!", "Case 2 failed.");
     is(toPlaintext("case3"), "Hello \\nboy!", "Case 3 failed.");
     is(toPlaintext("case4"), "Hello  \\nboy!", "Case 4 failed.");
     SimpleTest.finish();
--- a/dom/canvas/test/test_toDataURL_alpha.html
+++ b/dom/canvas/test/test_toDataURL_alpha.html
@@ -154,17 +154,17 @@ function do_canvas(row, col, type, optio
     var data = canvas.toDataURL(type, options);
 
     ctx.fillStyle = '#000';
     ctx.fillRect(0, 0, 100, 50);
     var img = new Image();
 
     var color = document.getElementById('c' + row).textContent;
     color = color.substr(5, color.length - 6); // strip off the 'argb()'
-    var colors = color.replace(' ', '', 'g').split(',');
+    var colors = color.replace(/ /g, '').split(',');
     var r = colors[0]*colors[3],
         g = colors[1]*colors[3],
         b = colors[2]*colors[3];
 
     img.onload = function ()
     {
         ctx.drawImage(img, 0, 0);
         isPixel(ctx, 50,25, r,g,b,255, 8);
--- a/dom/html/test/forms/test_input_typing_sanitization.html
+++ b/dom/html/test/forms/test_input_typing_sanitization.html
@@ -39,17 +39,17 @@ function submitForm() {
   form.submit();
 }
 
 function sendKeyEventToSubmitForm() {
   sendKey("return");
 }
 
 function urlify(aStr) {
-  return aStr.replace(':', '%3A', 'g');
+  return aStr.replace(/:/g, '%3A');
 }
 
 function runTestsForNextInputType()
 {
   try {
     testRunner.next();
   } catch (e) {
     if (e.toString() == '[object StopIteration]') {
--- a/dom/html/test/test_documentAll.html
+++ b/dom/html/test/test_documentAll.html
@@ -37,17 +37,17 @@ function testNumSame() {
   is(document.all.id2[1], p.children[2], "two ids");
   is(document.all.id2.length, 2, "two length");
   is(document.all.id3[0], p.children[3], "three ids");
   is(document.all.id3[1], p.children[4], "three ids");
   is(document.all.id3[2], p.children[5], "three ids");
   is(document.all.id3.length, 3, "three length");
 }
 testNumSame();
-p.innerHTML = p.innerHTML.replace("id=", "name=", "g");
+p.innerHTML = p.innerHTML.replace(/id=/g, "name=");
 testNumSame();
 
 
 // Test that dynamic changes behave properly
 
 // Add two elements and check that they are added to the correct lists
 child = Array.prototype.slice.call(p.children);
 child[6] = document.createElement("a");
--- a/dom/html/test/test_formSubmission.html
+++ b/dom/html/test/test_formSubmission.html
@@ -575,20 +575,20 @@ expectedAugment = [
 
 function checkMPSubmission(sub, expected, test) {
   function getPropCount(o) {
     var x, l = 0;
     for (x in o) ++l;
     return l;
   }
   function mpquote(s) {
-    return s.replace("\r\n", " ", "g")
-            .replace("\r", " ", "g")
-            .replace("\n", " ", "g")
-            .replace("\"", "\\\"", "g");
+    return s.replace(/\r\n/g, " ")
+            .replace(/\r/g, " ")
+            .replace(/\n/g, " ")
+            .replace(/\"/g, "\\\"");
   }
 
   is(sub.length, expected.length,
      "Correct number of multipart items in " + test);
   
   if (sub.length != expected.length) {
     alert(JSON.stringify(sub));
   }
@@ -623,19 +623,19 @@ function checkMPSubmission(sub, expected
 }
 
 function utf8encode(s) {
   return unescape(encodeURIComponent(s));
 }
 
 function checkURLSubmission(sub, expected) {
   function urlEscape(s) {
-    return escape(utf8encode(s)).replace("%20", "+", "g")
-                                .replace("/", "%2F", "g")
-                                .replace("@", "%40", "g");
+    return escape(utf8encode(s)).replace(/%20/g, "+")
+                                .replace(/\//g, "%2F")
+                                .replace(/@/g, "%40");
   }
 
   subItems = sub.split("&");
   is(subItems.length, expected.length,
      "Correct number of url items");
   var i;
   for (i = 0; i < expected.length; ++i) {
     let expect = urlEscape(expected[i].name) + "=" +