Revision: 21234
Author:   [email protected]
Date:     Fri May  9 16:37:04 2014 UTC
Log:      Array Iterator prototype should not have a constructor.

BUG=v8:3293
LOG=Y
[email protected]

Review URL: https://codereview.chromium.org/258793005

Patch from Erik Arvidsson <[email protected]>.
http://code.google.com/p/v8/source/detail?r=21234

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 Apr 17 17:45:32 2014 UTC +++ /branches/bleeding_edge/src/array-iterator.js Fri May 9 16:37:04 2014 UTC
@@ -27,15 +27,19 @@

 'use strict';

+
// This file relies on the fact that the following declaration has been made
 // in runtime.js:
 // var $Array = global.Array;

+
 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object");
 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next");
 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind");

+
 function ArrayIterator() {}
+

 // 15.4.5.1 CreateArrayIterator Abstract Operation
 function CreateArrayIterator(array, kind) {
@@ -46,11 +50,13 @@
   SET_PRIVATE(iterator, arrayIterationKindSymbol, kind);
   return iterator;
 }
+

 // 15.19.4.3.4 CreateItrResultObject
 function CreateIteratorResultObject(value, done) {
   return {value: value, done: done};
 }
+

 // 15.4.5.2.2 ArrayIterator.prototype.next( )
 function ArrayIteratorNext() {
@@ -82,31 +88,35 @@

   return CreateIteratorResultObject(index, false);
 }
+

 function ArrayEntries() {
   return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES);
 }
+

 function ArrayValues() {
   return CreateArrayIterator(this, ITERATOR_KIND_VALUES);
 }
+

 function ArrayKeys() {
   return CreateArrayIterator(this, ITERATOR_KIND_KEYS);
 }
+

 function SetUpArrayIterator() {
   %CheckIsBootstrapping();

+  %FunctionSetPrototype(ArrayIterator, new $Object());
   %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator');
-  %FunctionSetReadOnlyPrototype(ArrayIterator);

   InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array(
     'next', ArrayIteratorNext
   ));
 }
+SetUpArrayIterator();

-SetUpArrayIterator();

 function ExtendArrayPrototype() {
   %CheckIsBootstrapping();
@@ -117,5 +127,4 @@
     'keys', ArrayKeys
   ));
 }
-
 ExtendArrayPrototype();
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/array-iterator.js Tue Aug 6 13:10:07 2013 UTC +++ /branches/bleeding_edge/test/mjsunit/harmony/array-iterator.js Fri May 9 16:37:04 2014 UTC
@@ -27,6 +27,7 @@

 // Flags: --harmony-iteration --allow-natives-syntax

+
 function TestArrayPrototype() {
   assertTrue(Array.prototype.hasOwnProperty('entries'));
   assertTrue(Array.prototype.hasOwnProperty('values'));
@@ -38,9 +39,11 @@
 }
 TestArrayPrototype();

+
 function assertIteratorResult(value, done, result) {
   assertEquals({value: value, done: done}, result);
 }
+

 function TestValues() {
   var array = ['a', 'b', 'c'];
@@ -55,6 +58,7 @@
 }
 TestValues();

+
 function TestValuesMutate() {
   var array = ['a', 'b', 'c'];
   var iterator = array.values();
@@ -67,6 +71,7 @@
 }
 TestValuesMutate();

+
 function TestKeys() {
   var array = ['a', 'b', 'c'];
   var iterator = array.keys();
@@ -80,6 +85,7 @@
 }
 TestKeys();

+
 function TestKeysMutate() {
   var array = ['a', 'b', 'c'];
   var iterator = array.keys();
@@ -92,6 +98,7 @@
 }
 TestKeysMutate();

+
 function TestEntries() {
   var array = ['a', 'b', 'c'];
   var iterator = array.entries();
@@ -105,6 +112,7 @@
 }
 TestEntries();

+
 function TestEntriesMutate() {
   var array = ['a', 'b', 'c'];
   var iterator = array.entries();
@@ -117,29 +125,40 @@
 }
 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();

-  var ArrayIterator = iterator.constructor;
-  assertEquals(ArrayIterator.prototype, array.values().__proto__);
-  assertEquals(ArrayIterator.prototype, array.keys().__proto__);
-  assertEquals(ArrayIterator.prototype, array.entries().__proto__);
+  var ArrayIteratorPrototype = iterator.__proto__;
+
+  assertEquals(ArrayIteratorPrototype, array.values().__proto__);
+  assertEquals(ArrayIteratorPrototype, array.keys().__proto__);
+  assertEquals(ArrayIteratorPrototype, array.entries().__proto__);

-  assertEquals(Object.prototype, ArrayIterator.prototype.__proto__);
+  assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__);

   assertEquals('Array Iterator', %_ClassOf(array.values()));
   assertEquals('Array Iterator', %_ClassOf(array.keys()));
   assertEquals('Array Iterator', %_ClassOf(array.entries()));

-  var prototypeDescriptor =
-      Object.getOwnPropertyDescriptor(ArrayIterator, 'prototype');
-  assertFalse(prototypeDescriptor.configurable);
-  assertFalse(prototypeDescriptor.enumerable);
-  assertFalse(prototypeDescriptor.writable);
+  assertFalse(ArrayIteratorPrototype.hasOwnProperty('constructor'));
+  assertArrayEquals(['next'],
+      Object.getOwnPropertyNames(ArrayIteratorPrototype));
 }
 TestArrayIteratorPrototype();

+
 function TestForArrayValues() {
   var buffer = [];
   var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
@@ -157,6 +176,7 @@
 }
 TestForArrayValues();

+
 function TestForArrayKeys() {
   var buffer = [];
   var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
@@ -173,6 +193,7 @@
 }
 TestForArrayKeys();

+
 function TestForArrayEntries() {
   var buffer = [];
   var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];

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