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() {
return CreateIteratorResultObject(void 0, true);
}
var elementKey = ToString(index);
iterator[arrayIteratorNextIndexSymbol] = index + 1;
if (itemKind == ARRAY_ITERATOR_KIND_VALUES)
return CreateIteratorResultObject(array[elementKey], false);
return CreateIteratorResultObject(array[index], false);
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() {
......
......@@ -39,7 +39,7 @@ function TestArrayPrototype() {
TestArrayPrototype();
function assertIteratorResult(value, done, result) {
assertEquals({ value: value, done: done}, result);
assertEquals({value: value, done: done}, result);
}
function TestValues() {
......@@ -70,9 +70,9 @@ TestValuesMutate();
function TestKeys() {
var array = ['a', 'b', 'c'];
var iterator = array.keys();
assertIteratorResult('0', false, iterator.next());
assertIteratorResult('1', false, iterator.next());
assertIteratorResult('2', false, iterator.next());
assertIteratorResult(0, false, iterator.next());
assertIteratorResult(1, false, iterator.next());
assertIteratorResult(2, false, iterator.next());
assertIteratorResult(void 0, true, iterator.next());
array.push('d');
......@@ -83,11 +83,11 @@ TestKeys();
function TestKeysMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.keys();
assertIteratorResult('0', false, iterator.next());
assertIteratorResult('1', false, iterator.next());
assertIteratorResult('2', false, iterator.next());
assertIteratorResult(0, false, iterator.next());
assertIteratorResult(1, false, iterator.next());
assertIteratorResult(2, false, iterator.next());
array.push('d');
assertIteratorResult('3', false, iterator.next());
assertIteratorResult(3, false, iterator.next());
assertIteratorResult(void 0, true, iterator.next());
}
TestKeysMutate();
......@@ -95,9 +95,9 @@ TestKeysMutate();
function TestEntries() {
var array = ['a', 'b', 'c'];
var iterator = array.entries();
assertIteratorResult(['0', 'a'], false, iterator.next());
assertIteratorResult(['1', 'b'], false, iterator.next());
assertIteratorResult(['2', 'c'], false, iterator.next());
assertIteratorResult([0, 'a'], false, iterator.next());
assertIteratorResult([1, 'b'], false, iterator.next());
assertIteratorResult([2, 'c'], false, iterator.next());
assertIteratorResult(void 0, true, iterator.next());
array.push('d');
......@@ -108,11 +108,11 @@ TestEntries();
function TestEntriesMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.entries();
assertIteratorResult(['0', 'a'], false, iterator.next());
assertIteratorResult(['1', 'b'], false, iterator.next());
assertIteratorResult(['2', 'c'], false, iterator.next());
assertIteratorResult([0, 'a'], false, iterator.next());
assertIteratorResult([1, 'b'], false, iterator.next());
assertIteratorResult([2, 'c'], false, iterator.next());
array.push('d');
assertIteratorResult(['3', 'd'], false, iterator.next());
assertIteratorResult([3, 'd'], false, iterator.next());
assertIteratorResult(void 0, true, iterator.next());
}
TestEntriesMutate();
......@@ -168,7 +168,7 @@ function TestForArrayKeys() {
assertEquals(8, buffer.length);
for (var i = 0; i < buffer.length; i++) {
assertEquals(String(i), buffer[i]);
assertEquals(i, buffer[i]);
}
}
TestForArrayKeys();
......@@ -189,7 +189,7 @@ function TestForArrayEntries() {
assertTrue(isNaN(buffer[buffer.length - 1][1]));
for (var i = 0; i < buffer.length; i++) {
assertEquals(String(i), buffer[i][0]);
assertEquals(i, buffer[i][0]);
}
}
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