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

Unified Diff: src/harmony-array.js

Issue 771863002: Add Array.prototype.includes (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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 06fada7581db15aa7f576f9f9c615d8e1053e66c..488d6fd7887568a75380d6785dd63c78249e2cd7 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -127,6 +127,41 @@ function ArrayFill(value /* [, start [, end ] ] */) { // length == 1
return array;
}
+// Proposed for ES7
+// https://github.com/tc39/Array.prototype.includes
+// 6e3b78c927aeda20b9d40e81303f9d44596cd904
+function ArrayIncludes(searchElement, fromIndex) {
Dmitry Lomov (no reviews) 2014/12/02 12:25:25 Since it is not a ES6 feature, Array.prototype.inc
+ 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();
@@ -150,8 +185,11 @@ function HarmonyArrayExtendArrayPrototype() {
"of", ArrayOf
));
+ %FunctionSetLength(ArrayIncludes, 1);
+
// Set up the non-enumerable functions on the Array prototype object.
InstallFunctions($Array.prototype, DONT_ENUM, $Array(
+ "includes", ArrayIncludes,
"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