Chromium Code Reviews| Index: src/harmony-array.js | 
| diff --git a/src/harmony-array.js b/src/harmony-array.js | 
| index 88b878f0a76ef594f64f7905d61459c05749724b..286265b9b91cba4cf40a7b5cf5fac2e53240109f 100644 | 
| --- a/src/harmony-array.js | 
| +++ b/src/harmony-array.js | 
| @@ -123,6 +123,45 @@ function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 | 
| return array; | 
| } | 
| +// Proposed for ES7 | 
| +// https://github.com/domenic/Array.prototype.contains/ | 
| +// 3fb531d074eddf5d23e0a46b57ea48932e1fac69 | 
| +function ArrayContains(searchElement /*, fromIndex */) { // length == 1 | 
| 
 
caitp (gmail)
2014/09/18 01:28:31
arv@ has suggested using `%FunctionSetLength(funct
 
mathias
2014/09/18 06:13:07
Needs an extra space before `//`.
 
Dmitry Lomov (no reviews)
2014/09/18 06:26:45
Needs COERCIBLE check. (No strong preference on ho
 
domenic_domenicdenicola.com
2014/09/18 15:16:13
There is no COERCIBLE check in the spec for any of
 
Dmitry Lomov (no reviews)
2014/09/18 15:37:29
Hmm, I see. Could you file a bug?
 
 | 
| + var O = ToObject(this); | 
| + var len = ToLength(O.length); | 
| + | 
| + if (len === 0) { | 
| 
 
Dmitry Lomov (no reviews)
2014/09/18 06:26:45
Do you need this check? The below will work just f
 
domenic_domenicdenicola.com
2014/09/18 15:16:13
Yes, as otherwise we will trigger ToInteger on fro
 
Dmitry Lomov (no reviews)
2014/09/18 15:37:29
Got it.
 
 | 
| + return false; | 
| + } | 
| + | 
| + var n = ToInteger(%_Arguments(1)); | 
| + | 
| + if (n >= len) { | 
| 
 
Dmitry Lomov (no reviews)
2014/09/18 06:26:45
Do you need this check? 'while' below has a check
 
domenic_domenicdenicola.com
2014/09/18 15:16:13
Removed, tests still pass.
 
 | 
| + return false; | 
| + } | 
| + | 
| + var k; | 
| + if (n >= 0) { | 
| + k = n; | 
| + } else { | 
| + k = len - MathAbs(n); | 
| 
 
Dmitry Lomov (no reviews)
2014/09/18 06:26:45
Simply len + n?
 
domenic_domenicdenicola.com
2014/09/18 15:16:13
Weird, I wonder why the spec used abs for indexOf
 
 | 
| + if (k < 0) { | 
| + k = 0; | 
| + } | 
| + } | 
| + | 
| + while (k < len) { | 
| + var elementK = O[k]; | 
| + if (SameValueZero(searchElement, elementK) === true) { | 
| 
 
Dmitry Lomov (no reviews)
2014/09/18 06:26:45
=== true? Why not "if (SameValueZero(...))"
 
domenic_domenicdenicola.com
2014/09/18 15:16:13
Just going for spec-verbatimness. Will change.
 
 | 
| + return true; | 
| + } | 
| + | 
| + ++k; | 
| + } | 
| + | 
| + return false; | 
| +} | 
| + | 
| // ES6, draft 05-22-14, section 22.1.2.3 | 
| function ArrayOf() { | 
| var length = %_ArgumentsLength(); | 
| @@ -148,6 +187,7 @@ function HarmonyArrayExtendArrayPrototype() { | 
| // Set up the non-enumerable functions on the Array prototype object. | 
| InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 
| + "contains", ArrayContains, | 
| "find", ArrayFind, | 
| "findIndex", ArrayFindIndex, | 
| "fill", ArrayFill |