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

Unified Diff: test/mjsunit/harmony/array-iterator.js

Issue 338323003: Add @@iterator to Array.prototype (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix @@iterator property attributes, add tests Created 6 years, 6 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 | « src/array-iterator.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/array-iterator.js
diff --git a/test/mjsunit/harmony/array-iterator.js b/test/mjsunit/harmony/array-iterator.js
index 2642d7b2318e3355ccd0a547207fbe089c1217f8..f6addebd01c4c0c0590a99d0ec364965f4bb4ab9 100644
--- a/test/mjsunit/harmony/array-iterator.js
+++ b/test/mjsunit/harmony/array-iterator.js
@@ -28,14 +28,28 @@
// Flags: --harmony-iteration --allow-natives-syntax
+var NONE = 0;
+var READ_ONLY = 1;
+var DONT_ENUM = 2;
+var DONT_DELETE = 4;
+
+
+function assertHasOwnProperty(object, name, attrs) {
+ assertTrue(object.hasOwnProperty(name));
+ var desc = Object.getOwnPropertyDescriptor(object, name);
+ assertEquals(desc.writable, !(attrs & READ_ONLY));
+ assertEquals(desc.enumerable, !(attrs & DONT_ENUM));
+ assertEquals(desc.configurable, !(attrs & DONT_DELETE));
+}
+
+
function TestArrayPrototype() {
- assertTrue(Array.prototype.hasOwnProperty('entries'));
- assertTrue(Array.prototype.hasOwnProperty('values'));
- assertTrue(Array.prototype.hasOwnProperty('keys'));
+ assertHasOwnProperty(Array.prototype, 'entries', DONT_ENUM);
+ assertHasOwnProperty(Array.prototype, 'values', DONT_ENUM);
+ assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM);
+ assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM);
- assertFalse(Array.prototype.propertyIsEnumerable('entries'));
- assertFalse(Array.prototype.propertyIsEnumerable('values'));
- assertFalse(Array.prototype.propertyIsEnumerable('keys'));
+ assertEquals(Array.prototype.values, Array.prototype[Symbol.iterator]);
}
TestArrayPrototype();
@@ -127,16 +141,6 @@ TestEntriesMutate();
function TestArrayIteratorPrototype() {
- var ArrayIteratorPrototype = [].values().__proto__;
- assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor'));
- assertEquals(ArrayIteratorPrototype.__proto__, Object.prototype);
- assertArrayEquals(['next'],
- Object.getOwnPropertyNames(ArrayIteratorPrototype));
-}
-TestArrayIteratorPrototype();
-
-
-function TestArrayIteratorPrototype() {
var array = [];
var iterator = array.values();
@@ -155,6 +159,8 @@ function TestArrayIteratorPrototype() {
assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor'));
assertArrayEquals(['next'],
Object.getOwnPropertyNames(ArrayIteratorPrototype));
+ assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM);
+ assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM);
}
TestArrayIteratorPrototype();
@@ -216,6 +222,24 @@ function TestForArrayEntries() {
TestForArrayEntries();
+function TestForArray() {
+ var buffer = [];
+ var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
+ var i = 0;
+ for (var value of array) {
+ buffer[i++] = value;
+ }
+
+ assertEquals(8, buffer.length);
+
+ for (var i = 0; i < buffer.length - 1; i++) {
+ assertEquals(array[i], buffer[i]);
rossberg 2014/06/18 09:25:45 Use assertSame to avoid the special case for NaN.
rossberg 2014/06/25 07:52:39 Just saw that you changed this to assertSame, but
+ }
+ assertTrue(isNaN(buffer[buffer.length - 1]));
+}
+TestForArrayValues();
+
+
function TestNonOwnSlots() {
var array = [0];
var iterator = array.values();
« no previous file with comments | « src/array-iterator.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698