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

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: Add v8 bug to commit message 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..05fb65dd8fa18a72bee0d06a95cc44a0bd7fd626 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 */) { // length == 1
+ var O = ToObject(this);
arv (Not doing code reviews) 2014/09/18 15:28:02 Rename this to object or array.
+ var len = ToLength(O.length);
+
+ if (len === 0) {
+ return false;
+ }
+
+ var n = ToInteger(%_Arguments(1));
+
+ var k;
+ if (n >= 0) {
+ k = n;
+ } else {
+ k = len + n;
+ if (k < 0) {
+ k = 0;
+ }
+ }
+
+ while (k < len) {
+ var elementK = O[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();
@@ -148,6 +183,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
« 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