'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) {
var object = ToObject(array);
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() {
var iterator = ToObject(this);
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();
+
function ExtendArrayPrototype() {
%CheckIsBootstrapping();
'keys', ArrayKeys
));
}
-
ExtendArrayPrototype();
// Flags: --harmony-iteration --allow-natives-syntax
+
function TestArrayPrototype() {
assertTrue(Array.prototype.hasOwnProperty('entries'));
assertTrue(Array.prototype.hasOwnProperty('values'));
}
TestArrayPrototype();
+
function assertIteratorResult(value, done, result) {
assertEquals({value: value, done: done}, result);
}
+
function TestValues() {
var array = ['a', 'b', 'c'];
var iterator = array.values();
}
TestValues();
+
function TestValuesMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.values();
}
TestValuesMutate();
+
function TestKeys() {
var array = ['a', 'b', 'c'];
var iterator = array.keys();
}
TestKeys();
+
function TestKeysMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.keys();
}
TestKeysMutate();
+
function TestEntries() {
var array = ['a', 'b', 'c'];
var iterator = array.entries();
}
TestEntries();
+
function TestEntriesMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.entries();
}
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(Object.prototype, ArrayIterator.prototype.__proto__);
+ assertEquals(ArrayIteratorPrototype, array.values().__proto__);
+ assertEquals(ArrayIteratorPrototype, array.keys().__proto__);
+ assertEquals(ArrayIteratorPrototype, array.entries().__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];
}
TestForArrayValues();
+
function TestForArrayKeys() {
var buffer = [];
var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
}
TestForArrayKeys();
+
function TestForArrayEntries() {
var buffer = [];
var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];