Commit f6dfa63c authored by wingo@igalia.com's avatar wingo@igalia.com

Add @@iterator to Array.prototype

R=rossberg@chromium.org
BUG=

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21993 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 31ab363c
......@@ -111,7 +111,7 @@ function SetUpArrayIterator() {
));
%FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
%SetProperty(ArrayIterator.prototype, symbolIterator, ArrayIteratorIterator,
DONT_ENUM | DONT_DELETE | READ_ONLY);
DONT_ENUM);
}
SetUpArrayIterator();
......@@ -124,5 +124,7 @@ function ExtendArrayPrototype() {
'values', ArrayValues,
'keys', ArrayKeys
));
%SetProperty($Array.prototype, symbolIterator, ArrayValues, DONT_ENUM);
}
ExtendArrayPrototype();
......@@ -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();
......@@ -126,16 +140,6 @@ function TestEntriesMutate() {
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();
......@@ -170,7 +176,7 @@ function TestForArrayValues() {
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 @@ function TestForArrayEntries() {
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 @@ 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++) {
assertSame(array[i], buffer[i]);
}
assertTrue(isNaN(buffer[buffer.length - 1]));
}
TestForArrayValues();
function TestNonOwnSlots() {
var array = [0];
var iterator = array.values();
......
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