Revision: 21993
Author:   [email protected]
Date:     Wed Jun 25 07:32:57 2014 UTC
Log:      Add @@iterator to Array.prototype

[email protected]
BUG=

Review URL: https://codereview.chromium.org/338323003
http://code.google.com/p/v8/source/detail?r=21993

Modified:
 /branches/bleeding_edge/src/array-iterator.js
 /branches/bleeding_edge/test/mjsunit/harmony/array-iterator.js

=======================================
--- /branches/bleeding_edge/src/array-iterator.js Thu Jun 12 17:31:54 2014 UTC +++ /branches/bleeding_edge/src/array-iterator.js Wed Jun 25 07:32:57 2014 UTC
@@ -111,7 +111,7 @@
   ));
   %FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
%SetProperty(ArrayIterator.prototype, symbolIterator, ArrayIteratorIterator,
-      DONT_ENUM | DONT_DELETE | READ_ONLY);
+      DONT_ENUM);
 }
 SetUpArrayIterator();

@@ -124,5 +124,7 @@
     'values', ArrayValues,
     'keys', ArrayKeys
   ));
+
+  %SetProperty($Array.prototype, symbolIterator, ArrayValues, DONT_ENUM);
 }
 ExtendArrayPrototype();
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/array-iterator.js Wed May 21 08:05:11 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/harmony/array-iterator.js Wed Jun 25 07:32:57 2014 UTC
@@ -26,16 +26,30 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 // 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();

@@ -126,16 +140,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 @@
   assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor'));
   assertArrayEquals(['next'],
       Object.getOwnPropertyNames(ArrayIteratorPrototype));
+  assertHasOwnProperty(ArrayIteratorPrototype, 'next', DONT_ENUM);
+  assertHasOwnProperty(ArrayIteratorPrototype, Symbol.iterator, DONT_ENUM);
 }
 TestArrayIteratorPrototype();

@@ -170,7 +176,7 @@
   assertEquals(8, buffer.length);

   for (var i = 0; i < buffer.length - 1; i++) {
-    assertEquals(array[i], buffer[i]);
+    assertSame(array[i], buffer[i]);
   }
   assertTrue(isNaN(buffer[buffer.length - 1]));
 }
@@ -205,7 +211,7 @@
   assertEquals(8, buffer.length);

   for (var i = 0; i < buffer.length - 1; i++) {
-    assertEquals(array[i], buffer[i][1]);
+    assertSame(array[i], buffer[i][1]);
   }
   assertTrue(isNaN(buffer[buffer.length - 1][1]));

@@ -216,6 +222,24 @@
 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++) {
+    assertSame(array[i], buffer[i]);
+  }
+  assertTrue(isNaN(buffer[buffer.length - 1]));
+}
+TestForArrayValues();
+
+
 function TestNonOwnSlots() {
   var array = [0];
   var iterator = array.values();

--
--
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.

Reply via email to