From 096b31a05b7fd9efc40694c096899b2febc21748 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 15 Jul 2015 16:37:49 -0400 Subject: [PATCH] String.prototype.includes --- .../includes/coerced-values-of-position.js | 39 +++++++++++++++++ .../String/prototype/includes/includes.js | 22 ++++++++++ .../String/prototype/includes/length.js | 22 ++++++++++ .../String/prototype/includes/name.js | 22 ++++++++++ .../return-abrupt-from-position-as-symbol.js | 22 ++++++++++ .../includes/return-abrupt-from-position.js | 25 +++++++++++ ...turn-abrupt-from-searchstring-as-symbol.js | 21 ++++++++++ ...rn-abrupt-from-searchstring-regexp-test.js | 42 +++++++++++++++++++ .../return-abrupt-from-searchstring.js | 24 +++++++++++ .../return-abrupt-from-this-as-symbol.js | 20 +++++++++ .../includes/return-abrupt-from-this.js | 23 ++++++++++ ...eturn-false-with-out-of-bounds-position.js | 42 +++++++++++++++++++ .../return-true-if-searchstring-is-empty.js | 37 ++++++++++++++++ .../searchstring-found-with-position.js | 30 +++++++++++++ .../searchstring-found-without-position.js | 29 +++++++++++++ .../includes/searchstring-is-regexp-throws.js | 21 ++++++++++ .../searchstring-not-found-with-position.js | 32 ++++++++++++++ ...searchstring-not-found-without-position.js | 28 +++++++++++++ .../prototype/includes/this-is-null-throws.js | 16 +++++++ .../includes/this-is-undefined-throws.js | 16 +++++++ 20 files changed, 533 insertions(+) create mode 100644 test/built-ins/String/prototype/includes/coerced-values-of-position.js create mode 100644 test/built-ins/String/prototype/includes/includes.js create mode 100644 test/built-ins/String/prototype/includes/length.js create mode 100644 test/built-ins/String/prototype/includes/name.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-position.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js create mode 100644 test/built-ins/String/prototype/includes/return-abrupt-from-this.js create mode 100644 test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js create mode 100644 test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js create mode 100644 test/built-ins/String/prototype/includes/searchstring-found-with-position.js create mode 100644 test/built-ins/String/prototype/includes/searchstring-found-without-position.js create mode 100644 test/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js create mode 100644 test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js create mode 100644 test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js create mode 100644 test/built-ins/String/prototype/includes/this-is-null-throws.js create mode 100644 test/built-ins/String/prototype/includes/this-is-undefined-throws.js diff --git a/test/built-ins/String/prototype/includes/coerced-values-of-position.js b/test/built-ins/String/prototype/includes/coerced-values-of-position.js new file mode 100644 index 0000000000..90f6a19aab --- /dev/null +++ b/test/built-ins/String/prototype/includes/coerced-values-of-position.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns based on coerced values of position. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert(str.includes('The future', NaN), 'NaN coerced to 0'); +assert(str.includes('The future', null), 'null coerced to 0'); +assert(str.includes('The future', false), 'false coerced to 0'); +assert(str.includes('The future', ''), '"" coerced to 0'); +assert(str.includes('The future', '0'), '"0" coerced to 0'); +assert(str.includes('The future', undefined), 'undefined coerced to 0'); +assert(str.includes('The future', 0.4), '0.4 coerced to 0'); + +assert(str.includes('The future', -1)); + +assert.sameValue(str.includes('The future', true), false, 'true coerced to 1'); +assert.sameValue(str.includes('The future', '1'), false, '"1" coerced to 1'); +assert.sameValue(str.includes('The future', 1.4), false, '1.4 coerced to 1'); diff --git a/test/built-ins/String/prototype/includes/includes.js b/test/built-ins/String/prototype/includes/includes.js new file mode 100644 index 0000000000..54315a919f --- /dev/null +++ b/test/built-ins/String/prototype/includes/includes.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Property type and descriptor. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof String.prototype.includes, + 'function', + '`typeof String.prototype.includes` is `function`' +); + +verifyNotEnumerable(String.prototype, 'includes'); +verifyWritable(String.prototype, 'includes'); +verifyConfigurable(String.prototype, 'includes'); diff --git a/test/built-ins/String/prototype/includes/length.js b/test/built-ins/String/prototype/includes/length.js new file mode 100644 index 0000000000..7b627a78cf --- /dev/null +++ b/test/built-ins/String/prototype/includes/length.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + String.prototype.includes.length value and descriptor. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.includes.length, 1, + 'The value of `String.prototype.includes.length` is `1`' +); + +verifyNotEnumerable(String.prototype.includes, 'length'); +verifyNotWritable(String.prototype.includes, 'length'); +verifyConfigurable(String.prototype.includes, 'length'); diff --git a/test/built-ins/String/prototype/includes/name.js b/test/built-ins/String/prototype/includes/name.js new file mode 100644 index 0000000000..58e815d0ad --- /dev/null +++ b/test/built-ins/String/prototype/includes/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + String.prototype.includes.name value and descriptor. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.includes.name, 'includes', + 'The value of `String.prototype.includes.name` is `"includes"`' +); + +verifyNotEnumerable(String.prototype.includes, 'name'); +verifyNotWritable(String.prototype.includes, 'name'); +verifyConfigurable(String.prototype.includes, 'name'); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js b/test/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js new file mode 100644 index 0000000000..fc60a16e31 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToInteger(position) as a Symbol. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + ... +features: [Symbol] +---*/ + +var position = Symbol(); + +assert.throws(TypeError, function() { + ''.includes('', position); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-position.js b/test/built-ins/String/prototype/includes/return-abrupt-from-position.js new file mode 100644 index 0000000000..33f497000e --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-position.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToInteger(position). +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + ... +---*/ + +var position = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.includes('', position); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js new file mode 100644 index 0000000000..2b21ffda44 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToString(searchString) as a Symbol +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +features: [Symbol] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + ''.includes(s); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js new file mode 100644 index 0000000000..0df2c2d0a6 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from IsRegExp(searchString). +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 4. Let isRegExp be IsRegExp(searchString). + 5. ReturnIfAbrupt(isRegExp). + ... + + 7.2.8 IsRegExp ( argument ) + + 2. Let isRegExp be Get(argument, @@match). + 3. ReturnIfAbrupt(isRegExp). +features: [Symbol.match] +---*/ + +var obj = {}; +Object.defineProperty(obj, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.includes(obj); +}); + +var regexp = /./; +Object.defineProperty(regexp, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.includes(regexp); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js new file mode 100644 index 0000000000..3ac10db28a --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToString(searchString) +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.includes(obj); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js b/test/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000..b773808767 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToString(this) where this is a Symbol +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +features: [Symbol] +---*/ + +var s = Symbol(''); + +assert.throws(TypeError, function() { + String.prototype.includes.call(s, ''); +}); diff --git a/test/built-ins/String/prototype/includes/return-abrupt-from-this.js b/test/built-ins/String/prototype/includes/return-abrupt-from-this.js new file mode 100644 index 0000000000..612dd799c3 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-abrupt-from-this.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns abrupt from ToString(this) +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +---*/ + +var o = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.includes.call(o, ''); +}); diff --git a/test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js b/test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js new file mode 100644 index 0000000000..f3405807c0 --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns false if position is >= this.length and searchString.length > 0. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('!', str.length + 1), false, + 'str.includes("!", str.length + 1) returns false' +); + +assert.sameValue( + str.includes('!', 100), false, + 'str.includes("!", 100) returns false' +); + +assert.sameValue( + str.includes('!', Infinity), false, + 'str.includes("!", Infinity) returns false' +); + +assert.sameValue( + str.includes('!', str.length), false, + 'str.includes("!", str.length) returns false' +); diff --git a/test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js b/test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js new file mode 100644 index 0000000000..d8b56e9ddf --- /dev/null +++ b/test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns true if searchString.length == 0. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('', str.length), + 'str.includes("", str.length) returns true' +); + +assert( + str.includes(''), + 'str.includes("") returns true' +); + +assert( + str.includes('', Infinity), + 'str.includes("", Infinity) returns true' +); \ No newline at end of file diff --git a/test/built-ins/String/prototype/includes/searchstring-found-with-position.js b/test/built-ins/String/prototype/includes/searchstring-found-with-position.js new file mode 100644 index 0000000000..979e1407bb --- /dev/null +++ b/test/built-ins/String/prototype/includes/searchstring-found-with-position.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns true if searchString appears as a substring of the given string with a + given position. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('The future', 0), + 'Returns true for str.includes("The future", 0)' +); +assert(str.includes(' is ', 1), 'Returns true for str.includes(" is ", 1)'); +assert(str.includes('cool!', 10), 'Returns true for str.includes("cool!", 10)'); diff --git a/test/built-ins/String/prototype/includes/searchstring-found-without-position.js b/test/built-ins/String/prototype/includes/searchstring-found-without-position.js new file mode 100644 index 0000000000..f12e6f4650 --- /dev/null +++ b/test/built-ins/String/prototype/includes/searchstring-found-without-position.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns true if searchString appears as a substring of the given string. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('The future'), + 'Returns true for str.includes("The future")' +); +assert(str.includes('is cool!'), 'Returns true for str.includes("is cool!")'); +assert(str.includes(str), 'Returns true for str.includes(str)'); diff --git a/test/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js b/test/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js new file mode 100644 index 0000000000..dc4db6d8fe --- /dev/null +++ b/test/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Throws a TypeError if searchString is a RegExp. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 4. Let isRegExp be IsRegExp(searchString). + 5. ReturnIfAbrupt(isRegExp). + 6. If isRegExp is true, throw a TypeError exception. + ... +---*/ + +var searchString = /./; + +assert.throws(TypeError, function() { + ''.includes(searchString); +}); diff --git a/test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js b/test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js new file mode 100644 index 0000000000..6df6e5379d --- /dev/null +++ b/test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns false if searchString is not found with a given position. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('The future', 1), false, + 'Returns false on str.includes("The future", 1)' +); + +assert.sameValue( + str.includes(str, 1), false, + 'Returns false on str.includes(str, 1)' +); diff --git a/test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js b/test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js new file mode 100644 index 0000000000..f6286a6c07 --- /dev/null +++ b/test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Returns false if searchString is not found. +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('Flash'), false, + 'Flash if not included' +); +assert.sameValue(str.includes('FUTURE'), false, 'includes is case sensitive'); diff --git a/test/built-ins/String/prototype/includes/this-is-null-throws.js b/test/built-ins/String/prototype/includes/this-is-null-throws.js new file mode 100644 index 0000000000..5a1bd93c8b --- /dev/null +++ b/test/built-ins/String/prototype/includes/this-is-null-throws.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Throws TypeError when `this` is null +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.includes.call(null, ''); +}); diff --git a/test/built-ins/String/prototype/includes/this-is-undefined-throws.js b/test/built-ins/String/prototype/includes/this-is-undefined-throws.js new file mode 100644 index 0000000000..5ec1e02dcd --- /dev/null +++ b/test/built-ins/String/prototype/includes/this-is-undefined-throws.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.7 +description: > + Throws TypeError when `this` is undefined +info: > + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.includes.call(undefined, ''); +});