Commit b3acdf53 authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Rename String.prototype.contains to 'includes'. (patchset #1 id:1 of...

Revert of Rename String.prototype.contains to 'includes'. (patchset #1 id:1 of https://codereview.chromium.org/742963002/)

Reason for revert:
Breaks test262-es6:
http://build.chromium.org/p/client.v8/builders/V8%20Linux/builds/1289

Original issue's description:
> Rename String.prototype.contains to 'includes'.
>
> Per TC39 Nov 2014 decison.
>
> R=arv@chromium.org,yangguo@chromium.org
> LOG=Y
>
> Committed: https://chromium.googlesource.com/v8/v8/+/b5379216e23ff0ec734e70361dd07057c2421c96

TBR=arv@chromium.org,yangguo@chromium.org,dslomov@chromium.org
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/745543002

Cr-Commit-Position: refs/heads/master@{#25432}
parent 821736a6
...@@ -95,14 +95,14 @@ function StringEndsWith(searchString /* position */) { // length == 1 ...@@ -95,14 +95,14 @@ function StringEndsWith(searchString /* position */) { // length == 1
// ES6 draft 04-05-14, section 21.1.3.6 // ES6 draft 04-05-14, section 21.1.3.6
function StringIncludes(searchString /* position */) { // length == 1 function StringContains(searchString /* position */) { // length == 1
CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); CHECK_OBJECT_COERCIBLE(this, "String.prototype.contains");
var s = TO_STRING_INLINE(this); var s = TO_STRING_INLINE(this);
if (IS_REGEXP(searchString)) { if (IS_REGEXP(searchString)) {
throw MakeTypeError("first_argument_not_regexp", throw MakeTypeError("first_argument_not_regexp",
["String.prototype.includes"]); ["String.prototype.contains"]);
} }
var ss = TO_STRING_INLINE(searchString); var ss = TO_STRING_INLINE(searchString);
...@@ -184,7 +184,7 @@ function ExtendStringPrototype() { ...@@ -184,7 +184,7 @@ function ExtendStringPrototype() {
// Set up the non-enumerable functions on the String prototype object. // Set up the non-enumerable functions on the String prototype object.
InstallFunctions($String.prototype, DONT_ENUM, $Array( InstallFunctions($String.prototype, DONT_ENUM, $Array(
"codePointAt", StringCodePointAt, "codePointAt", StringCodePointAt,
"includes", StringIncludes, "contains", StringContains,
"endsWith", StringEndsWith, "endsWith", StringEndsWith,
"repeat", StringRepeat, "repeat", StringRepeat,
"startsWith", StringStartsWith "startsWith", StringStartsWith
......
...@@ -9,8 +9,8 @@ new BenchmarkSuite('StringFunctions', [1000], [ ...@@ -9,8 +9,8 @@ new BenchmarkSuite('StringFunctions', [1000], [
StartsWith, WithSetup, WithTearDown), StartsWith, WithSetup, WithTearDown),
new Benchmark('StringEndsWith', false, false, 0, new Benchmark('StringEndsWith', false, false, 0,
EndsWith, WithSetup, WithTearDown), EndsWith, WithSetup, WithTearDown),
new Benchmark('StringIncludes', false, false, 0, new Benchmark('StringContains', false, false, 0,
Includes, IncludesSetup, WithTearDown), Contains, ContainsSetup, WithTearDown),
new Benchmark('StringFromCodePoint', false, false, 0, new Benchmark('StringFromCodePoint', false, false, 0,
FromCodePoint, FromCodePointSetup, FromCodePointTearDown), FromCodePoint, FromCodePointSetup, FromCodePointTearDown),
new Benchmark('StringCodePointAt', false, false, 0, new Benchmark('StringCodePointAt', false, false, 0,
...@@ -60,13 +60,13 @@ function EndsWith() { ...@@ -60,13 +60,13 @@ function EndsWith() {
result = str.endsWith(substr); result = str.endsWith(substr);
} }
function IncludesSetup() { function ContainsSetup() {
str = "def".repeat(100) + "abc".repeat(100) + "qqq".repeat(100); str = "def".repeat(100) + "abc".repeat(100) + "qqq".repeat(100);
substr = "abc".repeat(100); substr = "abc".repeat(100);
} }
function Includes() { function Contains() {
result = str.includes(substr); result = str.contains(substr);
} }
var MAX_CODE_POINT = 0xFFFFF; var MAX_CODE_POINT = 0xFFFFF;
......
...@@ -27,42 +27,42 @@ ...@@ -27,42 +27,42 @@
// Flags: --harmony-strings // Flags: --harmony-strings
assertEquals(1, String.prototype.includes.length); assertEquals(1, String.prototype.contains.length);
var reString = "asdf[a-z]+(asdf)?"; var reString = "asdf[a-z]+(asdf)?";
assertTrue(reString.includes("[a-z]+")); assertTrue(reString.contains("[a-z]+"));
assertTrue(reString.includes("(asdf)?")); assertTrue(reString.contains("(asdf)?"));
// Random greek letters // Random greek letters
var twoByteString = "\u039a\u0391\u03a3\u03a3\u0395"; var twoByteString = "\u039a\u0391\u03a3\u03a3\u0395";
// Test single char pattern // Test single char pattern
assertTrue(twoByteString.includes("\u039a"), "Lamda"); assertTrue(twoByteString.contains("\u039a"), "Lamda");
assertTrue(twoByteString.includes("\u0391"), "Alpha"); assertTrue(twoByteString.contains("\u0391"), "Alpha");
assertTrue(twoByteString.includes("\u03a3"), "First Sigma"); assertTrue(twoByteString.contains("\u03a3"), "First Sigma");
assertTrue(twoByteString.includes("\u03a3",3), "Second Sigma"); assertTrue(twoByteString.contains("\u03a3",3), "Second Sigma");
assertTrue(twoByteString.includes("\u0395"), "Epsilon"); assertTrue(twoByteString.contains("\u0395"), "Epsilon");
assertFalse(twoByteString.includes("\u0392"), "Not beta"); assertFalse(twoByteString.contains("\u0392"), "Not beta");
// Test multi-char pattern // Test multi-char pattern
assertTrue(twoByteString.includes("\u039a\u0391"), "lambda Alpha"); assertTrue(twoByteString.contains("\u039a\u0391"), "lambda Alpha");
assertTrue(twoByteString.includes("\u0391\u03a3"), "Alpha Sigma"); assertTrue(twoByteString.contains("\u0391\u03a3"), "Alpha Sigma");
assertTrue(twoByteString.includes("\u03a3\u03a3"), "Sigma Sigma"); assertTrue(twoByteString.contains("\u03a3\u03a3"), "Sigma Sigma");
assertTrue(twoByteString.includes("\u03a3\u0395"), "Sigma Epsilon"); assertTrue(twoByteString.contains("\u03a3\u0395"), "Sigma Epsilon");
assertFalse(twoByteString.includes("\u0391\u03a3\u0395"), assertFalse(twoByteString.contains("\u0391\u03a3\u0395"),
"Not Alpha Sigma Epsilon"); "Not Alpha Sigma Epsilon");
//single char pattern //single char pattern
assertTrue(twoByteString.includes("\u0395")); assertTrue(twoByteString.contains("\u0395"));
assertThrows("String.prototype.includes.call(null, 'test')", TypeError); assertThrows("String.prototype.contains.call(null, 'test')", TypeError);
assertThrows("String.prototype.includes.call(null, null)", TypeError); assertThrows("String.prototype.contains.call(null, null)", TypeError);
assertThrows("String.prototype.includes.call(undefined, undefined)", TypeError); assertThrows("String.prototype.contains.call(undefined, undefined)", TypeError);
assertThrows("String.prototype.includes.apply(null, ['test'])", TypeError); assertThrows("String.prototype.contains.apply(null, ['test'])", TypeError);
assertThrows("String.prototype.includes.apply(null, [null])", TypeError); assertThrows("String.prototype.contains.apply(null, [null])", TypeError);
assertThrows("String.prototype.includes.apply(undefined, [undefined])", TypeError); assertThrows("String.prototype.contains.apply(undefined, [undefined])", TypeError);
var TEST_INPUT = [{ var TEST_INPUT = [{
msg: "Empty string", val: "" msg: "Empty string", val: ""
...@@ -91,51 +91,51 @@ for (; i < l; i++) { ...@@ -91,51 +91,51 @@ for (; i < l; i++) {
var e = TEST_INPUT[i]; var e = TEST_INPUT[i];
var v = e.val; var v = e.val;
var s = String(v); var s = String(v);
assertTrue(s.includes(v), e.msg); assertTrue(s.contains(v), e.msg);
assertTrue(String.prototype.includes.call(v, v), e.msg); assertTrue(String.prototype.contains.call(v, v), e.msg);
assertTrue(String.prototype.includes.apply(v, [v]), e.msg); assertTrue(String.prototype.contains.apply(v, [v]), e.msg);
} }
// Test cases found in FF // Test cases found in FF
assertTrue("abc".includes("a")); assertTrue("abc".contains("a"));
assertTrue("abc".includes("b")); assertTrue("abc".contains("b"));
assertTrue("abc".includes("abc")); assertTrue("abc".contains("abc"));
assertTrue("abc".includes("bc")); assertTrue("abc".contains("bc"));
assertFalse("abc".includes("d")); assertFalse("abc".contains("d"));
assertFalse("abc".includes("abcd")); assertFalse("abc".contains("abcd"));
assertFalse("abc".includes("ac")); assertFalse("abc".contains("ac"));
assertTrue("abc".includes("abc", 0)); assertTrue("abc".contains("abc", 0));
assertTrue("abc".includes("bc", 0)); assertTrue("abc".contains("bc", 0));
assertFalse("abc".includes("de", 0)); assertFalse("abc".contains("de", 0));
assertTrue("abc".includes("bc", 1)); assertTrue("abc".contains("bc", 1));
assertTrue("abc".includes("c", 1)); assertTrue("abc".contains("c", 1));
assertFalse("abc".includes("a", 1)); assertFalse("abc".contains("a", 1));
assertFalse("abc".includes("abc", 1)); assertFalse("abc".contains("abc", 1));
assertTrue("abc".includes("c", 2)); assertTrue("abc".contains("c", 2));
assertFalse("abc".includes("d", 2)); assertFalse("abc".contains("d", 2));
assertFalse("abc".includes("dcd", 2)); assertFalse("abc".contains("dcd", 2));
assertFalse("abc".includes("a", 42)); assertFalse("abc".contains("a", 42));
assertFalse("abc".includes("a", Infinity)); assertFalse("abc".contains("a", Infinity));
assertTrue("abc".includes("ab", -43)); assertTrue("abc".contains("ab", -43));
assertFalse("abc".includes("cd", -42)); assertFalse("abc".contains("cd", -42));
assertTrue("abc".includes("ab", -Infinity)); assertTrue("abc".contains("ab", -Infinity));
assertFalse("abc".includes("cd", -Infinity)); assertFalse("abc".contains("cd", -Infinity));
assertTrue("abc".includes("ab", NaN)); assertTrue("abc".contains("ab", NaN));
assertFalse("abc".includes("cd", NaN)); assertFalse("abc".contains("cd", NaN));
assertFalse("xyzzy".includes("zy\0", 2)); assertFalse("xyzzy".contains("zy\0", 2));
var dots = Array(10000).join("."); var dots = Array(10000).join(".");
assertFalse(dots.includes("\x01", 10000)); assertFalse(dots.contains("\x01", 10000));
assertFalse(dots.includes("\0", 10000)); assertFalse(dots.contains("\0", 10000));
var myobj = { var myobj = {
toString: function () { toString: function () {
return "abc"; return "abc";
}, },
includes: String.prototype.includes contains: String.prototype.contains
}; };
assertTrue(myobj.includes("abc")); assertTrue(myobj.contains("abc"));
assertFalse(myobj.includes("cd")); assertFalse(myobj.contains("cd"));
var gotStr = false; var gotStr = false;
var gotPos = false; var gotPos = false;
...@@ -145,22 +145,22 @@ myobj = { ...@@ -145,22 +145,22 @@ myobj = {
gotStr = true; gotStr = true;
return "xyz"; return "xyz";
}, },
includes: String.prototype.includes contains: String.prototype.contains
}; };
assertEquals("foo[a-z]+(bar)?".includes("[a-z]+"), true); assertEquals("foo[a-z]+(bar)?".contains("[a-z]+"), true);
assertThrows("'foo[a-z]+(bar)?'.includes(/[a-z]+/)", TypeError); assertThrows("'foo[a-z]+(bar)?'.contains(/[a-z]+/)", TypeError);
assertThrows("'foo/[a-z]+/(bar)?'.includes(/[a-z]+/)", TypeError); assertThrows("'foo/[a-z]+/(bar)?'.contains(/[a-z]+/)", TypeError);
assertEquals("foo[a-z]+(bar)?".includes("(bar)?"), true); assertEquals("foo[a-z]+(bar)?".contains("(bar)?"), true);
assertThrows("'foo[a-z]+(bar)?'.includes(/(bar)?/)", TypeError); assertThrows("'foo[a-z]+(bar)?'.contains(/(bar)?/)", TypeError);
assertThrows("'foo[a-z]+/(bar)?/'.includes(/(bar)?/)", TypeError); assertThrows("'foo[a-z]+/(bar)?/'.contains(/(bar)?/)", TypeError);
assertThrows("String.prototype.includes.call({ 'toString': function() { " + assertThrows("String.prototype.contains.call({ 'toString': function() { " +
"throw RangeError(); } }, /./)", RangeError); "throw RangeError(); } }, /./)", RangeError);
assertThrows("String.prototype.includes.call({ 'toString': function() { " + assertThrows("String.prototype.contains.call({ 'toString': function() { " +
"return 'abc'; } }, /./)", TypeError); "return 'abc'; } }, /./)", TypeError);
assertThrows("String.prototype.includes.apply({ 'toString': function() { " + assertThrows("String.prototype.contains.apply({ 'toString': function() { " +
"throw RangeError(); } }, [/./])", RangeError); "throw RangeError(); } }, [/./])", RangeError);
assertThrows("String.prototype.includes.apply({ 'toString': function() { " + assertThrows("String.prototype.contains.apply({ 'toString': function() { " +
"return 'abc'; } }, [/./])", TypeError); "return 'abc'; } }, [/./])", TypeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment