Bug 1103588 - Part 4: Replace deprecated String#contains in js tests. r=till
authorChris Peterson <cpeterson@mozilla.com>
Sat, 09 Apr 2016 16:03:00 -0700
changeset 292936 6891e4414ffaa50352ffdbab21997a6c431e0cae
parent 292935 a4cd474335e4f6b4e6a299e20f9b27fc164caa4a
child 292937 47162e3a9e0262b29af5dbb43ce1fa51dc3a31a5
push id75034
push usercpeterson@mozilla.com
push dateWed, 13 Apr 2016 04:16:49 +0000
treeherdermozilla-inbound@47162e3a9e02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1103588
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1103588 - Part 4: Replace deprecated String#contains in js tests. r=till - Remove sudoku.js test's unnecessary String#contains and Array#contains polyfill functions. - Replace warning.js test's String#contains warning with an expression closure warning.
js/src/tests/ecma_6/Comprehensions/sudoku.js
js/src/tests/shell/warning.js
--- a/js/src/tests/ecma_6/Comprehensions/sudoku.js
+++ b/js/src/tests/ecma_6/Comprehensions/sudoku.js
@@ -6,24 +6,17 @@
 
 function copy(obj) {
   var o = {};
   for (var i in obj)
     o[i] = obj[i];
   return o;
 }
 
-Array.prototype.contains = String.prototype.contains = function (e) {
-  for (var elt of this)
-    if (elt == e)
-      return true;
-  return false;
-}
-
-Array.prototype.repeat = String.prototype.repeat = function (n) {
+Array.prototype.repeat = function (n) {
   var s = this.constructor();
   for (var i = 0; i < n; i++)
     s = s.concat(this);
   return s;
 }
 
 String.prototype.center = function (w) {
   var n = this.length;
@@ -59,17 +52,17 @@ function dict(A) {
   for (var e of A)
     d[e[0]] = e[1];
   return d;
 }
 
 function set(A) {
   var s = [];
   for (var e of A)
-    if (!s.contains(e))
+    if (!s.includes(e))
       s.push(e);
   return s;
 }
 
 function zip(A, B) {
   var z = [];
   var n = Math.min(A.length, B.length);
   for (var i = 0; i < n; i++)
@@ -80,75 +73,75 @@ function zip(A, B) {
 rows = 'ABCDEFGHI';
 cols = '123456789';
 digits   = '123456789';
 squares  = cross(rows, cols);
 unitlist = [for (c of cols) cross(rows, c)]
   .concat([for (r of rows) cross(r, cols)])
   .concat([for (rs of ['ABC','DEF','GHI']) for (cs of ['123','456','789']) cross(rs, cs)]);
 units = dict((for (s of squares)
-                [s, [for (u of unitlist) if (u.contains(s)) u]]));
+                [s, [for (u of unitlist) if (u.includes(s)) u]]));
 
 peers = dict((for (s of squares)
                 [s, set([for (u of units[s]) for (s2 of u) if (s2 != s) s2])]));
 
 // Given a string of 81 digits (or . or 0 or -), return a dict of {cell:values}.
 function parse_grid(grid) {
-  grid = [for (c of grid) if ('0.-123456789'.contains(c)) c];
+  grid = [for (c of grid) if ('0.-123456789'.includes(c)) c];
   var values = dict((for (s of squares) [s, digits]));
 
   for (var pair of zip(squares, grid)) {
     var s = pair[0], d = pair[1];
-    if (digits.contains(d) && !assign(values, s, d))
+    if (digits.includes(d) && !assign(values, s, d))
       return false;
   }
   return values;
 }
 
 // Eliminate all the other values (except d) from values[s] and propagate.
 function assign(values, s, d) {
   if (all((for (d2 of values[s]) if (d2 != d) eliminate(values, s, d2))))
     return values;
   return false;
 }
 
 // Eliminate d from values[s]; propagate when values or places <= 2.
 function eliminate(values, s, d) {
-  if (!values[s].contains(d))
+  if (!values[s].includes(d))
     return values; // Already eliminated
   values[s] = values[s].replace(d, '');
   if (values[s].length == 0)
     return false;  // Contradiction: removed last value
   if (values[s].length == 1) {
     // If there is only one value (d2) left in square, remove it from peers
     var d2 = values[s][0];
     if (!all((for (s2 of peers[s]) eliminate(values, s2, d2))))
       return false;
   }
   // Now check the places where d appears in the units of s
   for (var u of units[s]) {
-    var dplaces = [for (s of u) if (values[s].contains(d)) s];
+    var dplaces = [for (s of u) if (values[s].includes(d)) s];
     if (dplaces.length == 0)
       return false;
     if (dplaces.length == 1)
 	    // d can only be in one place in unit; assign it there
       if (!assign(values, dplaces[0], d))
         return false;
   }
   return values;
 }
 
 // Used for debugging.
 function print_board(values) {
   var width = 1 + Math.max.apply(Math, [for (s of squares) values[s].length]);
   var line = '\n' + ['-'.repeat(width*3)].repeat(3).join('+');
   for (var r of rows)
     print([for (c of cols)
-              values[r+c].center(width) + ('36'.contains(c) && '|' || '')]
-          .join('') + ('CF'.contains(r) && line || ''));
+              values[r+c].center(width) + ('36'.includes(c) && '|' || '')]
+          .join('') + ('CF'.includes(r) && line || ''));
   print('\n');
 }
 
 easy = "..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..";
 
 print_board(parse_grid(easy));
 
 // Using depth-first search and constraint propagation, try all possible values.
--- a/js/src/tests/shell/warning.js
+++ b/js/src/tests/shell/warning.js
@@ -4,25 +4,24 @@ var BUGNUMBER = 1170716;
 var summary = 'Add js shell functions to get last warning';
 
 print(BUGNUMBER + ": " + summary);
 
 // Warning with JSEXN_NONE.
 
 enableLastWarning();
 
-let line0 = new Error().lineNumber;
-assertEq("foo".contains("bar"), false);
+eval(`(function() "This is an expression closure.")`);
 
 var warning = getLastWarning();
 assertEq(warning !== null, true);
 assertEq(warning.name, "None");
-assertEq(warning.message.includes("deprecated"), true);
-assertEq(warning.lineNumber, line0 + 1);
-assertEq(warning.columnNumber, 10);
+assertEq(warning.message.includes("expression closures are deprecated"), true);
+assertEq(warning.lineNumber, 1);
+assertEq(warning.columnNumber, 12);
 
 // Clear last warning.
 
 clearLastWarning();
 warning = getLastWarning();
 assertEq(warning, null);
 
 // Warning with JSEXN_SYNTAXERR.