Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: src/harmony-array.js

Issue 579973002: Add Array.prototype.contains (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use `array` instead of `O` Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/runtime.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-array.js
diff --git a/src/harmony-array.js b/src/harmony-array.js
index 88b878f0a76ef594f64f7905d61459c05749724b..f2f709794b7b69fac0b2b7c36eaf59c404e67b0b 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -123,6 +123,41 @@ function ArrayFill(value /* [, start [, end ] ] */) { // length == 1
return array;
}
+// Proposed for ES7
+// https://github.com/domenic/Array.prototype.contains/
+// 3fb531d074eddf5d23e0a46b57ea48932e1fac69
+function ArrayContains(searchElement, fromIndex) {
+ var array = ToObject(this);
+ var len = ToLength(array.length);
+
+ if (len === 0) {
+ return false;
+ }
+
+ var n = ToInteger(fromIndex);
+
+ var k;
+ if (n >= 0) {
+ k = n;
+ } else {
+ k = len + n;
+ if (k < 0) {
+ k = 0;
+ }
+ }
+
+ while (k < len) {
+ var elementK = array[k];
+ if (SameValueZero(searchElement, elementK)) {
+ return true;
+ }
+
+ ++k;
+ }
+
+ return false;
+}
+
// ES6, draft 05-22-14, section 22.1.2.3
function ArrayOf() {
var length = %_ArgumentsLength();
@@ -146,8 +181,11 @@ function HarmonyArrayExtendArrayPrototype() {
"of", ArrayOf
));
+ %FunctionSetLength(ArrayContains, 1);
+
// 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
« no previous file with comments | « no previous file | src/runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698