Bug 1102219 - Part 2: Replace String.prototype.contains with String.prototype.includes in JS code. r=till
☠☠ backed out by 57725f8e7aa1 ☠ ☠
authorziyunfei <446240525@qq.com>
Sun, 23 Nov 2014 06:24:00 -0500
changeset 219198 32db3daa20fe
parent 219197 ac15ba8568c5
child 219199 34a66a625618
push id52780
push userryanvm@gmail.com
push dateThu, 11 Dec 2014 15:02:25 +0000
treeherdermozilla-inbound@cb926aa1e69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1102219
milestone37.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 1102219 - Part 2: Replace String.prototype.contains with String.prototype.includes in JS code. r=till
js/src/jit-test/tests/baseline/bug842431-2.js
js/src/jit-test/tests/baseline/bug842431-3.js
js/src/jit-test/tests/baseline/bug892787-1.js
js/src/jit-test/tests/baseline/bug892787-2.js
js/src/jit-test/tests/basic/bug1091757.js
js/src/jit-test/tests/basic/bug839420.js
js/src/jit-test/tests/basic/string-contains.js
js/src/jit-test/tests/basic/string-includes.js
js/src/jit-test/tests/debug/Debugger-findScripts-18.js
js/src/jit-test/tests/debug/Frame-eval-stack.js
js/src/jit-test/tests/generators/wrappers.js
js/src/jit-test/tests/ion/bug1060398.js
js/src/jit-test/tests/ion/bug870328.js
js/src/jit-test/tests/ion/bug906284.js
js/src/jit-test/tests/ion/bug909997.js
js/src/jit-test/tests/latin1/decompiler.js
js/src/jit-test/tests/latin1/function.js
js/src/jit-test/tests/latin1/indexOf.js
js/src/jit-test/tests/latin1/json.js
js/src/jit-test/tests/saved-stacks/evals.js
js/src/jit-test/tests/saved-stacks/stringify-with-self-hosted.js
js/src/jit-test/tests/xdr/asm.js
js/src/tests/ecma_5/extensions/strict-function-toSource.js
--- a/js/src/jit-test/tests/baseline/bug842431-2.js
+++ b/js/src/jit-test/tests/baseline/bug842431-2.js
@@ -16,10 +16,10 @@ dbg.onDebuggerStatement = function handl
 	return {throw: 555};
     }
 };
 
 try {
     g.f();
     assertEq(0, 2);
 } catch(e) {
-    assertEq(e.toString().contains("555"), true);
+    assertEq(e.toString().includes("555"), true);
 }
--- a/js/src/jit-test/tests/baseline/bug842431-3.js
+++ b/js/src/jit-test/tests/baseline/bug842431-3.js
@@ -15,10 +15,10 @@ dbg.onExceptionUnwind = function(frame) 
 
     return {return: 11};
 };
 
 try {
     g.f();
     assertEq(0, 1);
 } catch(e) {
-    assertEq(e.toString().contains("321"), true);
+    assertEq(e.toString().includes("321"), true);
 }
--- a/js/src/jit-test/tests/baseline/bug892787-1.js
+++ b/js/src/jit-test/tests/baseline/bug892787-1.js
@@ -4,15 +4,15 @@ function f() {
     new Function.prototype
 }
 function g() {
     var count = 0;
     for (var i=0; i<3; i++) {
 	try {
             f();
 	} catch (e) {
-	    assertEq(e.message.contains("is not a constructor"), true);
+	    assertEq(e.message.includes("is not a constructor"), true);
 	    count++;
 	}
     }
     assertEq(count, 3);
 }
 g();
--- a/js/src/jit-test/tests/baseline/bug892787-2.js
+++ b/js/src/jit-test/tests/baseline/bug892787-2.js
@@ -22,15 +22,15 @@ function f(callee) {
     new callee;
 }
 function g() {
     var c = 0;
     for (var i=0; i<50; i++) {
 	try {
 	    f(funs[i % funs.length]);
 	} catch (e) {
-	    assertEq(e.message.contains("not a constructor"), true);
+	    assertEq(e.message.includes("not a constructor"), true);
 	    c++;
 	}
     }
     assertEq(c, 4);
 }
 g();
--- a/js/src/jit-test/tests/basic/bug1091757.js
+++ b/js/src/jit-test/tests/basic/bug1091757.js
@@ -2,10 +2,10 @@ try {
     (function() {
 	let a = 3;
 	let XY = XY;
 	return function() { return a; };
     })();
     assertEq(0, 1);
 } catch(e) {
     assertEq(e instanceof ReferenceError, true);
-    assertEq(e.message.contains("XY"), true);
+    assertEq(e.message.includes("XY"), true);
 }
--- a/js/src/jit-test/tests/basic/bug839420.js
+++ b/js/src/jit-test/tests/basic/bug839420.js
@@ -1,17 +1,17 @@
 function f() {
     var x = undefined;
     try {
 	[1, 2, 3].map(x);
 	assertEq(0, 1);
     } catch(e) {
-	assertEq(e.toString().contains("x is not"), true);
+	assertEq(e.toString().includes("x is not"), true);
     }
 
     try {
 	[1, 2, 3].filter(x, 1, 2);
 	assertEq(0, 1);
     } catch(e) {
-	assertEq(e.toString().contains("x is not"), true);
+	assertEq(e.toString().includes("x is not"), true);
     }
 }
 f();
deleted file mode 100644
--- a/js/src/jit-test/tests/basic/string-contains.js
+++ /dev/null
@@ -1,46 +0,0 @@
-assertEq("abc".contains("a"), true);
-assertEq("abc".contains("b"), true);
-assertEq("abc".contains("abc"), true);
-assertEq("abc".contains("bc"), true);
-assertEq("abc".contains("d"), false);
-assertEq("abc".contains("abcd"), false);
-assertEq("abc".contains("ac"), false);
-assertEq("abc".contains("abc", 0), true);
-assertEq("abc".contains("bc", 0), true);
-assertEq("abc".contains("de", 0), false);
-assertEq("abc".contains("bc", 1), true);
-assertEq("abc".contains("c", 1), true);
-assertEq("abc".contains("a", 1), false);
-assertEq("abc".contains("abc", 1), false);
-assertEq("abc".contains("c", 2), true);
-assertEq("abc".contains("d", 2), false);
-assertEq("abc".contains("dcd", 2), false);
-assertEq("abc".contains("a", 42), false);
-assertEq("abc".contains("a", Infinity), false);
-assertEq("abc".contains("ab", -43), true);
-assertEq("abc".contains("cd", -42), false);
-assertEq("abc".contains("ab", -Infinity), true);
-assertEq("abc".contains("cd", -Infinity), false);
-assertEq("abc".contains("ab", NaN), true);
-assertEq("abc".contains("cd", NaN), false);
-var myobj = {toString : (function () "abc"), contains : String.prototype.contains};
-assertEq(myobj.contains("abc"), true);
-assertEq(myobj.contains("cd"), false);
-var gotStr = false, gotPos = false;
-myobj = {toString : (function () {
-    assertEq(gotPos, false);
-    gotStr = true;
-    return "xyz";
-}),
-contains : String.prototype.contains};
-var idx = {valueOf : (function () {
-    assertEq(gotStr, true);
-    gotPos = true;
-    return 42;
-})};
-myobj.contains("elephant", idx);
-assertEq(gotPos, true);
-assertEq("xyzzy".contains("zy\0", 2), false);
-var dots = Array(10000).join('.');
-assertEq(dots.contains("\x01", 10000), false);
-assertEq(dots.contains("\0", 10000), false);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/string-includes.js
@@ -0,0 +1,46 @@
+assertEq("abc".includes("a"), true);
+assertEq("abc".includes("b"), true);
+assertEq("abc".includes("abc"), true);
+assertEq("abc".includes("bc"), true);
+assertEq("abc".includes("d"), false);
+assertEq("abc".includes("abcd"), false);
+assertEq("abc".includes("ac"), false);
+assertEq("abc".includes("abc", 0), true);
+assertEq("abc".includes("bc", 0), true);
+assertEq("abc".includes("de", 0), false);
+assertEq("abc".includes("bc", 1), true);
+assertEq("abc".includes("c", 1), true);
+assertEq("abc".includes("a", 1), false);
+assertEq("abc".includes("abc", 1), false);
+assertEq("abc".includes("c", 2), true);
+assertEq("abc".includes("d", 2), false);
+assertEq("abc".includes("dcd", 2), false);
+assertEq("abc".includes("a", 42), false);
+assertEq("abc".includes("a", Infinity), false);
+assertEq("abc".includes("ab", -43), true);
+assertEq("abc".includes("cd", -42), false);
+assertEq("abc".includes("ab", -Infinity), true);
+assertEq("abc".includes("cd", -Infinity), false);
+assertEq("abc".includes("ab", NaN), true);
+assertEq("abc".includes("cd", NaN), false);
+var myobj = {toString : (function () "abc"), includes : String.prototype.includes};
+assertEq(myobj.includes("abc"), true);
+assertEq(myobj.includes("cd"), false);
+var gotStr = false, gotPos = false;
+myobj = {toString : (function () {
+    assertEq(gotPos, false);
+    gotStr = true;
+    return "xyz";
+}),
+includes : String.prototype.includes};
+var idx = {valueOf : (function () {
+    assertEq(gotStr, true);
+    gotPos = true;
+    return 42;
+})};
+myobj.includes("elephant", idx);
+assertEq(gotPos, true);
+assertEq("xyzzy".includes("zy\0", 2), false);
+var dots = Array(10000).join('.');
+assertEq(dots.includes("\x01", 10000), false);
+assertEq(dots.includes("\0", 10000), false);
--- a/js/src/jit-test/tests/debug/Debugger-findScripts-18.js
+++ b/js/src/jit-test/tests/debug/Debugger-findScripts-18.js
@@ -37,10 +37,10 @@ assertEq(allScripts.indexOf(hw.script) !
 
 try {
   dbg.findScripts({ displayURL: 3 });
   // Should never get here because the above line should throw
   // JSMSG_UNEXPECTED_TYPE.
   assertEq(true, false);
 } catch(e) {
   assertEq(e.name, "TypeError");
-  assertEq(e.message.contains("displayURL"), true);
+  assertEq(e.message.includes("displayURL"), true);
 }
--- a/js/src/jit-test/tests/debug/Frame-eval-stack.js
+++ b/js/src/jit-test/tests/debug/Frame-eval-stack.js
@@ -9,11 +9,11 @@ dbg.onDebuggerStatement = function(frame
     frame = frame.older;
     g.trace = frame.older.eval("(new Error()).stack;").return;
 }
 g.f();
 
 assertEq(typeof g.trace, "string");
 
 var frames = g.trace.split("\n");
-assertEq(frames[0].contains("eval code"), true);
+assertEq(frames[0].includes("eval code"), true);
 assertEq(frames[1].startsWith("f@"), true);
 assertEq(frames[2].startsWith("@"), true);
--- a/js/src/jit-test/tests/generators/wrappers.js
+++ b/js/src/jit-test/tests/generators/wrappers.js
@@ -25,10 +25,10 @@ assertIteratorResult(it.next.call(g.it4)
 // StarGenerator.throw
 assertThrowsValue(() => it.throw.call(g.it4, 8), 8);
 
 // Other objects should throw.
 try {
     it.next.call([]);
     assertEq(0, 1);
 } catch (e) {
-    assertEq(e.toString().contains("called on incompatible Array"), true);
+    assertEq(e.toString().includes("called on incompatible Array"), true);
 }
--- a/js/src/jit-test/tests/ion/bug1060398.js
+++ b/js/src/jit-test/tests/ion/bug1060398.js
@@ -2,15 +2,15 @@ function test() {
     var c = 0;
     for (var i=0; i<20; i++) {
 	var arr = [1];
 	if (i > 5)
 	    Object.defineProperty(arr, "length", { writable: false, value: 4 });
 	try {
 	    arr.push(2);
 	} catch(e) {
-	    assertEq(e.toString().contains("length"), true);
+	    assertEq(e.toString().includes("length"), true);
 	    c++;
 	}
     }
     assertEq(c, 14);
 }
 test();
--- a/js/src/jit-test/tests/ion/bug870328.js
+++ b/js/src/jit-test/tests/ion/bug870328.js
@@ -1,7 +1,7 @@
 var g = newGlobal("same-compartment");
 try {
     evalcx("'use strict'; (function() { x = 33; })()", g);
     assertEq(0, 1);
 } catch(e) {
-    assertEq(e.toString().contains("variable x"), true);
+    assertEq(e.toString().includes("variable x"), true);
 }
--- a/js/src/jit-test/tests/ion/bug906284.js
+++ b/js/src/jit-test/tests/ion/bug906284.js
@@ -4,12 +4,12 @@ function f() {
 }
 var c = 0;
 for (var i=0; i<3; i++) {
     try {
 	new f();
 	assertEq(0, 1);
     } catch(e) {
 	c++;
-	assertEq(e.message.contains("undeclared variable"), true);
+	assertEq(e.message.includes("undeclared variable"), true);
     }
 }
 assertEq(c, 3);
--- a/js/src/jit-test/tests/ion/bug909997.js
+++ b/js/src/jit-test/tests/ion/bug909997.js
@@ -18,17 +18,17 @@ var method_D = function() {
 
 var func = [method_A, method_B, method_C, method_D]
 
 for (var n = 0; n < 4; ++n) {
     try {
 	setJitCompilerOption("baseline.enable", n & 1);
 	setJitCompilerOption("ion.enable", n & 2 ? 1: 0);
     } catch(e) {
-	if (e.toString().contains("on the stack"))
+	if (e.toString().includes("on the stack"))
 	    continue;
 	throw e;
     }
     var opt = getJitCompilerOptions();
     assertEq(opt["baseline.enable"], n & 1);
     assertEq(opt["ion.enable"], n & 2 ? 1 : 0);
     for (var i = 0; i < 1001; ++i)
         func[n]();
--- a/js/src/jit-test/tests/latin1/decompiler.js
+++ b/js/src/jit-test/tests/latin1/decompiler.js
@@ -1,20 +1,20 @@
 // Latin1
 function f(someName) {
     someName();
 }
 try {
     f(3);
 } catch(e) {
-    assertEq(e.message.contains("someName"), true);
+    assertEq(e.message.includes("someName"), true);
 }
 
 // TwoByte
 function g(someName\u1200) {
     someName\u1200();
 }
 try {
     g(3);
 } catch(e) {
     // Note: string is deflated; don't check for the \u1200.
-    assertEq(e.message.contains("someName"), true);
+    assertEq(e.message.includes("someName"), true);
 }
--- a/js/src/jit-test/tests/latin1/function.js
+++ b/js/src/jit-test/tests/latin1/function.js
@@ -1,16 +1,16 @@
 function test() {
     var arg1TwoByte = "arg1\u1200";
     var arg2Latin1 = "arg2";
 
     var bodyLatin1 = "return arg2 * 3";
 
     var f = Function(arg1TwoByte, arg2Latin1, bodyLatin1);
     assertEq(f(10, 20), 60);
-    assertEq(f.toSource().contains("arg1\u1200, arg2"), true);
+    assertEq(f.toSource().includes("arg1\u1200, arg2"), true);
 
     var bodyTwoByte = "return arg1\u1200 + arg2;";
     f = Function(arg1TwoByte, arg2Latin1, bodyTwoByte);
     assertEq(f(30, 40), 70);
-    assertEq(f.toSource().contains("arg1\u1200, arg2"), true);
+    assertEq(f.toSource().includes("arg1\u1200, arg2"), true);
 }
 test();
--- a/js/src/jit-test/tests/latin1/indexOf.js
+++ b/js/src/jit-test/tests/latin1/indexOf.js
@@ -57,45 +57,45 @@ function testIndexOf() {
     // TwoByte + TwoByte
     assertEq(s3.indexOf("\u1123a4"), 11);
     assertEq(s3.indexOf("\u1123a4", 12), -1);
     assertEq(s3.indexOf("\u1123a\u1098"), -1);
     assertEq(s3.indexOf(s3), 0);
 }
 testIndexOf();
 
-function testContains() {
+function testincludes() {
     var s1 = toLatin1("abcdefgh123456defghi\u00EEj");
     var s2 = toLatin1("456defghi\u00EE");
 
     // Latin1 + Latin1
-    assertEq(s1.contains(s1), true);
-    assertEq(s1.contains(s2), true);
-    assertEq(s1.contains(s2, 12), false);
-    assertEq(s2.contains(s1), false);
+    assertEq(s1.includes(s1), true);
+    assertEq(s1.includes(s2), true);
+    assertEq(s1.includes(s2, 12), false);
+    assertEq(s2.includes(s1), false);
 
     // Latin1 + TwoByte
-    assertEq(s1.contains("abc\u1234"), false);
-    assertEq(s1.contains("def\u1234".substring(0, 3)), true);
-    assertEq(s1.contains("def\u1234".substring(0, 3), 9), true);
+    assertEq(s1.includes("abc\u1234"), false);
+    assertEq(s1.includes("def\u1234".substring(0, 3)), true);
+    assertEq(s1.includes("def\u1234".substring(0, 3), 9), true);
 
     // TwoByte + Latin1
     var s3 = "123456defg\u1123a456defghi\u00EEj";
     assertEq(isLatin1(s2), true);
-    assertEq(s3.contains(s2), true);
-    assertEq(s3.contains(s2, 13), false);
-    assertEq(s3.contains(toLatin1("defg8")), false);
+    assertEq(s3.includes(s2), true);
+    assertEq(s3.includes(s2, 13), false);
+    assertEq(s3.includes(toLatin1("defg8")), false);
 
     // TwoByte + TwoByte
-    assertEq(s3.contains("\u1123a4"), true);
-    assertEq(s3.contains("\u1123a4", 11), false);
-    assertEq(s3.contains("\u1123a\u1098"), false);
-    assertEq(s3.contains(s3), true);
+    assertEq(s3.includes("\u1123a4"), true);
+    assertEq(s3.includes("\u1123a4", 11), false);
+    assertEq(s3.includes("\u1123a\u1098"), false);
+    assertEq(s3.includes(s3), true);
 }
-testContains();
+testincludes();
 
 function testIndexOfBMH() {
     // BoyerMooreHorspool algorithm is used for large strings.
     var s = "012345678901234567890123456789".repeat(20);
     var text = s + "abcdefghijklmnopqrst\u00C1uvwxyz";
     text.indexOf("333");
 
     var textL1 = toLatin1(text);
--- a/js/src/jit-test/tests/latin1/json.js
+++ b/js/src/jit-test/tests/latin1/json.js
@@ -15,26 +15,26 @@ function testErrorPos() {
 
     // Latin1
     var s = '[1, \n2,';
     try {
 	JSON.parse(s);
 	assertEq(0, 1);
     } catch(e) {
 	assertEq(e instanceof SyntaxError, true);
-	assertEq(e.toString().contains("line 2 column 3"), true);
+	assertEq(e.toString().includes("line 2 column 3"), true);
     }
 
     s = '[1, "\u1300",\n2,';
     try {
 	JSON.parse(s);
 	assertEq(0, 1);
     } catch(e) {
 	assertEq(e instanceof SyntaxError, true);
-	assertEq(e.toString().contains("line 2 column 3"), true);
+	assertEq(e.toString().includes("line 2 column 3"), true);
     }
 }
 testErrorPos();
 
 function testEvalHack() {
     // Latin1
     var arr = eval("[1, 2, 3, \"abc\"]");
     assertEq(JSON.stringify(arr), '[1,2,3,"abc"]');
--- a/js/src/jit-test/tests/saved-stacks/evals.js
+++ b/js/src/jit-test/tests/saved-stacks/evals.js
@@ -1,38 +1,38 @@
 // Test that we can save stacks with direct and indirect eval calls.
 
 const directEval = (function iife() {
   return eval("(" + function evalFrame() {
     return saveStack();
   } + "())");
 }());
 
-assertEq(directEval.source.contains("> eval"), true);
+assertEq(directEval.source.includes("> eval"), true);
 assertEq(directEval.functionDisplayName, "evalFrame");
 
-assertEq(directEval.parent.source.contains("> eval"), true);
+assertEq(directEval.parent.source.includes("> eval"), true);
 
-assertEq(directEval.parent.parent.source.contains("> eval"), false);
+assertEq(directEval.parent.parent.source.includes("> eval"), false);
 assertEq(directEval.parent.parent.functionDisplayName, "iife");
 
-assertEq(directEval.parent.parent.parent.source.contains("> eval"), false);
+assertEq(directEval.parent.parent.parent.source.includes("> eval"), false);
 
 assertEq(directEval.parent.parent.parent.parent, null);
 
 const lave = eval;
 const indirectEval = (function iife() {
   return lave("(" + function evalFrame() {
     return saveStack();
   } + "())");
 }());
 
-assertEq(indirectEval.source.contains("> eval"), true);
+assertEq(indirectEval.source.includes("> eval"), true);
 assertEq(indirectEval.functionDisplayName, "evalFrame");
 
-assertEq(indirectEval.parent.source.contains("> eval"), true);
+assertEq(indirectEval.parent.source.includes("> eval"), true);
 
-assertEq(indirectEval.parent.parent.source.contains("> eval"), false);
+assertEq(indirectEval.parent.parent.source.includes("> eval"), false);
 assertEq(indirectEval.parent.parent.functionDisplayName, "iife");
 
-assertEq(indirectEval.parent.parent.parent.source.contains("> eval"), false);
+assertEq(indirectEval.parent.parent.parent.source.includes("> eval"), false);
 
 assertEq(indirectEval.parent.parent.parent.parent, null);
--- a/js/src/jit-test/tests/saved-stacks/stringify-with-self-hosted.js
+++ b/js/src/jit-test/tests/saved-stacks/stringify-with-self-hosted.js
@@ -1,8 +1,8 @@
 // Test that stringify'ing a saved frame with self-hosted parent frames doesn't
 // include the self-hosted parent frame in the output.
 
 const map = (function () {
   return [3].map(n => saveStack()).pop();
 }());
 
-assertEq(map.toString().contains("@self-hosted:"), false);
+assertEq(map.toString().includes("@self-hosted:"), false);
--- a/js/src/jit-test/tests/xdr/asm.js
+++ b/js/src/jit-test/tests/xdr/asm.js
@@ -9,11 +9,11 @@ var test = (function () {
     };
   };
   return f.toSource();
 })();
 
 try {
   evalWithCache(test, {});
 } catch (x) {
-  assertEq(x.message.contains("AsmJS"), true);
-  assertEq(x.message.contains("XDR"), true);
+  assertEq(x.message.includes("AsmJS"), true);
+  assertEq(x.message.includes("XDR"), true);
 }
--- a/js/src/tests/ecma_5/extensions/strict-function-toSource.js
+++ b/js/src/tests/ecma_5/extensions/strict-function-toSource.js
@@ -6,12 +6,12 @@
 options("strict_mode");
 function testRunOptionStrictMode(str, arg, result) {
     var strict_inner = new Function('return typeof this == "undefined";');
     return strict_inner;
 }
 assertEq(eval(uneval(testRunOptionStrictMode()))(), true);
 
 if (typeof decompileBody !== "undefined") {
-    assertEq(decompileBody(new Function('x', 'return x*2;')).contains('\n"use strict"'), true);
+    assertEq(decompileBody(new Function('x', 'return x*2;')).includes('\n"use strict"'), true);
 }
 
 reportCompare(true, true);