Commit 45f4b685 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Update Array Iterator to use numeric indexes

At the last face-to-face meeting it was decided that we should use
numeric indexes for the Array Iterator values.

https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-07/july-24.md#514-keys-entries-return-numbers-for-array-index-properties

BUG=v8:2818
R=dslomov@chromium.org

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

Patch from Erik Arvidsson <arv@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16072 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 665c45c9
...@@ -77,16 +77,15 @@ function ArrayIteratorNext() { ...@@ -77,16 +77,15 @@ function ArrayIteratorNext() {
return CreateIteratorResultObject(void 0, true); return CreateIteratorResultObject(void 0, true);
} }
var elementKey = ToString(index);
iterator[arrayIteratorNextIndexSymbol] = index + 1; iterator[arrayIteratorNextIndexSymbol] = index + 1;
if (itemKind == ARRAY_ITERATOR_KIND_VALUES) if (itemKind == ARRAY_ITERATOR_KIND_VALUES)
return CreateIteratorResultObject(array[elementKey], false); return CreateIteratorResultObject(array[index], false);
if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES)
return CreateIteratorResultObject([elementKey, array[elementKey]], false); return CreateIteratorResultObject([index, array[index]], false);
return CreateIteratorResultObject(elementKey, false); return CreateIteratorResultObject(index, false);
} }
function ArrayEntries() { function ArrayEntries() {
......
...@@ -39,7 +39,7 @@ function TestArrayPrototype() { ...@@ -39,7 +39,7 @@ function TestArrayPrototype() {
TestArrayPrototype(); TestArrayPrototype();
function assertIteratorResult(value, done, result) { function assertIteratorResult(value, done, result) {
assertEquals({ value: value, done: done}, result); assertEquals({value: value, done: done}, result);
} }
function TestValues() { function TestValues() {
...@@ -70,9 +70,9 @@ TestValuesMutate(); ...@@ -70,9 +70,9 @@ TestValuesMutate();
function TestKeys() { function TestKeys() {
var array = ['a', 'b', 'c']; var array = ['a', 'b', 'c'];
var iterator = array.keys(); var iterator = array.keys();
assertIteratorResult('0', false, iterator.next()); assertIteratorResult(0, false, iterator.next());
assertIteratorResult('1', false, iterator.next()); assertIteratorResult(1, false, iterator.next());
assertIteratorResult('2', false, iterator.next()); assertIteratorResult(2, false, iterator.next());
assertIteratorResult(void 0, true, iterator.next()); assertIteratorResult(void 0, true, iterator.next());
array.push('d'); array.push('d');
...@@ -83,11 +83,11 @@ TestKeys(); ...@@ -83,11 +83,11 @@ TestKeys();
function TestKeysMutate() { function TestKeysMutate() {
var array = ['a', 'b', 'c']; var array = ['a', 'b', 'c'];
var iterator = array.keys(); var iterator = array.keys();
assertIteratorResult('0', false, iterator.next()); assertIteratorResult(0, false, iterator.next());
assertIteratorResult('1', false, iterator.next()); assertIteratorResult(1, false, iterator.next());
assertIteratorResult('2', false, iterator.next()); assertIteratorResult(2, false, iterator.next());
array.push('d'); array.push('d');
assertIteratorResult('3', false, iterator.next()); assertIteratorResult(3, false, iterator.next());
assertIteratorResult(void 0, true, iterator.next()); assertIteratorResult(void 0, true, iterator.next());
} }
TestKeysMutate(); TestKeysMutate();
...@@ -95,9 +95,9 @@ TestKeysMutate(); ...@@ -95,9 +95,9 @@ TestKeysMutate();
function TestEntries() { function TestEntries() {
var array = ['a', 'b', 'c']; var array = ['a', 'b', 'c'];
var iterator = array.entries(); var iterator = array.entries();
assertIteratorResult(['0', 'a'], false, iterator.next()); assertIteratorResult([0, 'a'], false, iterator.next());
assertIteratorResult(['1', 'b'], false, iterator.next()); assertIteratorResult([1, 'b'], false, iterator.next());
assertIteratorResult(['2', 'c'], false, iterator.next()); assertIteratorResult([2, 'c'], false, iterator.next());
assertIteratorResult(void 0, true, iterator.next()); assertIteratorResult(void 0, true, iterator.next());
array.push('d'); array.push('d');
...@@ -108,11 +108,11 @@ TestEntries(); ...@@ -108,11 +108,11 @@ TestEntries();
function TestEntriesMutate() { function TestEntriesMutate() {
var array = ['a', 'b', 'c']; var array = ['a', 'b', 'c'];
var iterator = array.entries(); var iterator = array.entries();
assertIteratorResult(['0', 'a'], false, iterator.next()); assertIteratorResult([0, 'a'], false, iterator.next());
assertIteratorResult(['1', 'b'], false, iterator.next()); assertIteratorResult([1, 'b'], false, iterator.next());
assertIteratorResult(['2', 'c'], false, iterator.next()); assertIteratorResult([2, 'c'], false, iterator.next());
array.push('d'); array.push('d');
assertIteratorResult(['3', 'd'], false, iterator.next()); assertIteratorResult([3, 'd'], false, iterator.next());
assertIteratorResult(void 0, true, iterator.next()); assertIteratorResult(void 0, true, iterator.next());
} }
TestEntriesMutate(); TestEntriesMutate();
...@@ -168,7 +168,7 @@ function TestForArrayKeys() { ...@@ -168,7 +168,7 @@ function TestForArrayKeys() {
assertEquals(8, buffer.length); assertEquals(8, buffer.length);
for (var i = 0; i < buffer.length; i++) { for (var i = 0; i < buffer.length; i++) {
assertEquals(String(i), buffer[i]); assertEquals(i, buffer[i]);
} }
} }
TestForArrayKeys(); TestForArrayKeys();
...@@ -189,7 +189,7 @@ function TestForArrayEntries() { ...@@ -189,7 +189,7 @@ function TestForArrayEntries() {
assertTrue(isNaN(buffer[buffer.length - 1][1])); assertTrue(isNaN(buffer[buffer.length - 1][1]));
for (var i = 0; i < buffer.length; i++) { for (var i = 0; i < buffer.length; i++) {
assertEquals(String(i), buffer[i][0]); assertEquals(i, buffer[i][0]);
} }
} }
TestForArrayEntries(); TestForArrayEntries();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment