зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1102219 - Part 2: Replace String.prototype.contains with String.prototype.includes in JS code. r=till
This commit is contained in:
Родитель
a239fb194d
Коммит
fa6d464d58
|
@ -21,5 +21,5 @@ try {
|
|||
g.f();
|
||||
assertEq(0, 2);
|
||||
} catch(e) {
|
||||
assertEq(e.toString().contains("555"), true);
|
||||
assertEq(e.toString().includes("555"), true);
|
||||
}
|
||||
|
|
|
@ -20,5 +20,5 @@ try {
|
|||
g.f();
|
||||
assertEq(0, 1);
|
||||
} catch(e) {
|
||||
assertEq(e.toString().contains("321"), true);
|
||||
assertEq(e.toString().includes("321"), true);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ function g() {
|
|||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
assertEq(e.message.contains("is not a constructor"), true);
|
||||
assertEq(e.message.includes("is not a constructor"), true);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ function g() {
|
|||
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++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@ try {
|
|||
assertEq(0, 1);
|
||||
} catch(e) {
|
||||
assertEq(e instanceof ReferenceError, true);
|
||||
assertEq(e.message.contains("XY"), true);
|
||||
assertEq(e.message.includes("XY"), true);
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ function f() {
|
|||
[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();
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
|
@ -42,5 +42,5 @@ try {
|
|||
assertEq(true, false);
|
||||
} catch(e) {
|
||||
assertEq(e.name, "TypeError");
|
||||
assertEq(e.message.contains("displayURL"), true);
|
||||
assertEq(e.message.includes("displayURL"), true);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,6 @@ 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);
|
||||
|
|
|
@ -30,5 +30,5 @@ 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);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ function test() {
|
|||
try {
|
||||
arr.push(2);
|
||||
} catch(e) {
|
||||
assertEq(e.toString().contains("length"), true);
|
||||
assertEq(e.toString().includes("length"), true);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ 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);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ for (var i=0; i<3; i++) {
|
|||
assertEq(0, 1);
|
||||
} catch(e) {
|
||||
c++;
|
||||
assertEq(e.message.contains("undeclared variable"), true);
|
||||
assertEq(e.message.includes("undeclared variable"), true);
|
||||
}
|
||||
}
|
||||
assertEq(c, 3);
|
||||
|
|
|
@ -23,7 +23,7 @@ for (var n = 0; n < 4; ++n) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ function f(someName) {
|
|||
try {
|
||||
f(3);
|
||||
} catch(e) {
|
||||
assertEq(e.message.contains("someName"), true);
|
||||
assertEq(e.message.includes("someName"), true);
|
||||
}
|
||||
|
||||
// TwoByte
|
||||
|
@ -16,5 +16,5 @@ 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);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ function test() {
|
|||
|
||||
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();
|
||||
|
|
|
@ -62,35 +62,35 @@ function testIndexOf() {
|
|||
}
|
||||
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.
|
||||
|
|
|
@ -20,7 +20,7 @@ function testErrorPos() {
|
|||
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,';
|
||||
|
@ -29,7 +29,7 @@ function testErrorPos() {
|
|||
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();
|
||||
|
|
|
@ -6,15 +6,15 @@ const directEval = (function iife() {
|
|||
} + "())");
|
||||
}());
|
||||
|
||||
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);
|
||||
|
||||
|
@ -25,14 +25,14 @@ const indirectEval = (function iife() {
|
|||
} + "())");
|
||||
}());
|
||||
|
||||
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);
|
||||
|
|
|
@ -5,4 +5,4 @@ const map = (function () {
|
|||
return [3].map(n => saveStack()).pop();
|
||||
}());
|
||||
|
||||
assertEq(map.toString().contains("@self-hosted:"), false);
|
||||
assertEq(map.toString().includes("@self-hosted:"), false);
|
||||
|
|
|
@ -14,6 +14,6 @@ var test = (function () {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ function testRunOptionStrictMode(str, arg, result) {
|
|||
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче