Reviewers: arv, Dmitry Lomov (chromium),
Message:
For tests I would like guidance as to how we should proceed. The existing
test262-format tests are at
https://github.com/tc39/Array.prototype.includes/tree/master/test.
1) Port the tests to mjsunit and commit them.
2) Add the ability to pull test262-format tests from arbitrary repos (in a
sibling folder, e.g. test262-other) and have it pull from
tc39/Array.prototype.includes
3) Add the ability to run checked-in test262 tests (in a sibling folder,
e.g.
test262-not-upstreamed-yet) and check in the tests. Doing so will probably
mean
modifying the copyright header of the tests to make the presubmit happy.
4) Get the tests merged into tc39/test262 proper, and add some way of
running a
subset of test262 tests during development. This will probably be blocked on
other test262-related changes, e.g. the fact that we are using the old
deprecated Python runner and not the new Node.js-based runner.
I am happy to do any of these, and I have a spike of 3) at
https://github.com/domenic/v8-git-mirror/tree/test262-not-upstreamed-yet
but ran
into the copyright header issue and thought I'd better ask before moving
further.
Description:
Add Array.prototype.includes
Requires adding a SameValueZero implementation.
LOG=Y
BUG=v8:3575
[email protected], [email protected]
TEST=added to test262
Please review this at https://codereview.chromium.org/771863002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+47, -0 lines):
M src/harmony-array.js
M src/runtime.js
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) {
+ 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
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index
4d15d205a495b6623cf399ccd0dd36973cac22c4..30063bd4e9ff8fd167e9c442daa861d83b8a2f01
100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -598,6 +598,15 @@ function SameValue(x, y) {
return x === y;
}
+// ES6, section 7.2.4
+function SameValueZero(x, y) {
+ if (typeof x != typeof y) return false;
+ if (IS_NUMBER(x)) {
+ if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
+ }
+ return x === y;
+}
+
/* ---------------------------------
- - - U t i l i t i e s - - -
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.