diff --git a/test/built-ins/Array/prototype/Symbol.iterator/property-descriptor.js b/test/built-ins/Array/prototype/Symbol.iterator/property-descriptor.js new file mode 100644 index 0000000000..f309b02ac4 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/property-descriptor.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should exist on the Array prototype, and it should be writable + and configurable, but not enumerable. + includes: [propertyHelper.js] + es6id: 22.1.3.4 + ---*/ + +verifyNotEnumerable(Array.prototype, Symbol.iterator); +verifyWritable(Array.prototype, Symbol.iterator); +verifyConfigurable(Array.prototype, Symbol.iterator); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/property-descriptor.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/property-descriptor.js new file mode 100644 index 0000000000..a146fe49de --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/property-descriptor.js @@ -0,0 +1,18 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `Object.prototype.getOwnPropertyDescriptor` should reflect the value and + writability of the @@toStringTag attribute. + includes: [propertyHelper.js] + es6id: 22.1.5.2.2 + ---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +assert.sameValue("Array Iterator", ArrayIteratorProto[Symbol.toStringTag]); + +verifyNotEnumerable(ArrayIteratorProto, Symbol.toStringTag); +verifyNotWritable(ArrayIteratorProto, Symbol.toStringTag); +verifyConfigurable(ArrayIteratorProto, Symbol.toStringTag); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-direct.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-direct.js new file mode 100644 index 0000000000..649b15bf24 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-direct.js @@ -0,0 +1,12 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The @@toStringTag attribute should be defined directly on the prototype. + es6id: 22.1.5.2.2 + ---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +assert.sameValue("Array Iterator", ArrayIteratorProto[Symbol.toStringTag]); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-from-to-string.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-from-to-string.js new file mode 100644 index 0000000000..1f0a63c411 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/Symbol.toStringTag/value-from-to-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `Object.prototype.toString` should honor the value of the @@toStringTag + attribute. + es6id: 22.1.5.2.2 + ---*/ + +var iter = [][Symbol.iterator](); + +assert.sameValue("[object Array Iterator]", Object.prototype.toString.call(iter)); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration-mutable.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration-mutable.js new file mode 100644 index 0000000000..51db927d80 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration-mutable.js @@ -0,0 +1,32 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + When an item is added to the array after the iterator is created but + before the iterator is "done" (as defined by 22.1.5.2.1), the new item + should be accessible via iteration. When an item is added to the array + after the iterator is is "done", the new item should not be accessible + via iteration. + es6id: 22.1.3.30 + ---*/ + +var array = []; +var iterator = array[Symbol.iterator](); +var result; + +array.push('a'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value, 'a', 'First result `value`'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); + +array.push('b'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag (after push)'); +assert.sameValue(result.value, undefined, 'Exhausted result `value (after push)'); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration.js new file mode 100644 index 0000000000..b31f19ca01 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/iteration.js @@ -0,0 +1,29 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator with the context as the + IteratedObject. + es6id: 22.1.3.30 + ---*/ + +var array = ['a', 'b', 'c']; +var iterator = array[Symbol.iterator](); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'a', 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 'b', 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 'c', 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag`'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/non-own-slots.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/non-own-slots.js new file mode 100644 index 0000000000..822dfe908a --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/non-own-slots.js @@ -0,0 +1,17 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + If the `this` value does not have all of the internal slots of an Array + Iterator Instance (22.1.5.3), throw a TypeError exception. + es6id: 22.1.5.2.1 + ---*/ + +var array = [0]; +var iterator = array[Symbol.iterator](); +var object = Object.create(iterator); + +assert.throws(TypeError, function() { + object.next(); +}); diff --git a/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/property-descriptor.js b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/property-descriptor.js new file mode 100644 index 0000000000..f04d40fce1 --- /dev/null +++ b/test/built-ins/Array/prototype/Symbol.iterator/prototype/next/property-descriptor.js @@ -0,0 +1,16 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should exist on the ArrayIterator prototype, and it should be + writable and configurable, but not enumerable. + includes: [propertyHelper.js] + es6id: 17 + ---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +verifyNotEnumerable(ArrayIteratorProto, 'next'); +verifyWritable(ArrayIteratorProto, 'next'); +verifyConfigurable(ArrayIteratorProto, 'next'); diff --git a/test/built-ins/Array/prototype/entries/iteration-mutable.js b/test/built-ins/Array/prototype/entries/iteration-mutable.js new file mode 100644 index 0000000000..e5df017cf4 --- /dev/null +++ b/test/built-ins/Array/prototype/entries/iteration-mutable.js @@ -0,0 +1,33 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator with the context as the + IteratedObject. When an item is added to the array after the iterator is + created but before the iterator is "done" (as defined by 22.1.5.2.1) the + new item should be accessible via iteration. + es6id: 22.1.3.4 + ---*/ + +var array = []; +var iterator = array.entries(); +var result; + +array.push('a'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value[0], 0, 'First result `value` (array key)'); +assert.sameValue(result.value[1], 'a', 'First result `value (array value)'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); + +array.push('b'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag (after push)'); +assert.sameValue(result.value, undefined, 'Exhausted result `value` (after push)'); diff --git a/test/built-ins/Array/prototype/entries/iteration.js b/test/built-ins/Array/prototype/entries/iteration.js new file mode 100644 index 0000000000..f15a26e78b --- /dev/null +++ b/test/built-ins/Array/prototype/entries/iteration.js @@ -0,0 +1,38 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator with the context as the + IteratedObject. + es6id: 22.1.3.4 + ---*/ + +var ArrayIteratorPrototype = Object.getPrototypeOf(Array.prototype[Symbol.iterator]()); +var array = ['a', 'b', 'c']; +var iterator = array.entries(); +var result; + +assert.sameValue(ArrayIteratorPrototype, Object.getPrototypeOf(array.entries())); + +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value[0], 0, 'First result `value` (array key)'); +assert.sameValue(result.value[1], 'a', 'First result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'Second result `done` flag'); +assert.sameValue(result.value[0], 1, 'Second result `value` (array key)'); +assert.sameValue(result.value[1], 'b', 'Second result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); + +result = iterator.next(); +assert.sameValue(result.done, false, 'Third result `done` flag'); +assert.sameValue(result.value[0], 2, 'Third result `value` (array key)'); +assert.sameValue(result.value[1], 'c', 'Third result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); diff --git a/test/built-ins/Array/prototype/entries/property-descriptor.js b/test/built-ins/Array/prototype/entries/property-descriptor.js new file mode 100644 index 0000000000..888ab3173e --- /dev/null +++ b/test/built-ins/Array/prototype/entries/property-descriptor.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should exist on the Array prototype, and it should be writable + and configurable, but not enumerable. + includes: [propertyHelper.js] + es6id: 17 + ---*/ + +verifyNotEnumerable(Array.prototype, 'entries'); +verifyWritable(Array.prototype, 'entries'); +verifyConfigurable(Array.prototype, 'entries'); diff --git a/test/built-ins/Array/prototype/entries/returns-iterator.js b/test/built-ins/Array/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000..22b8aa9c53 --- /dev/null +++ b/test/built-ins/Array/prototype/entries/returns-iterator.js @@ -0,0 +1,13 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return an Iterator instance. + es6id: 22.1.3.4 + ---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].entries(); + +assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); diff --git a/test/built-ins/Array/prototype/keys/iteration-mutable.js b/test/built-ins/Array/prototype/keys/iteration-mutable.js new file mode 100644 index 0000000000..cdf84c8683 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/iteration-mutable.js @@ -0,0 +1,32 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + When an item is added to the array after the iterator is created but + before the iterator is "done" (as defined by 22.1.5.2.1), the new item's + key should be accessible via iteration. When an item is added to the + array after the iterator is is "done", the new item's key should not be + accessible via iteration. + es6id: 22.1.3.13 + ---*/ + +var array = []; +var iterator = array.keys(); +var result; + +array.push('a'); + +result = iterator.next(); +assert.sameValue(result.done, false , 'First result `done` flag'); +assert.sameValue(result.value, 0, 'First result `value`'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); + +array.push('b'); + +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag (after push)'); +assert.sameValue(result.value, undefined, 'Exhausted result `value` (after push)'); diff --git a/test/built-ins/Array/prototype/keys/iteration.js b/test/built-ins/Array/prototype/keys/iteration.js new file mode 100644 index 0000000000..7e964bbe55 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/iteration.js @@ -0,0 +1,29 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator with the array's numeric + properties as the IteratedObject. + es6id: 22.1.3.13 + ---*/ + +var array = ['a', 'b', 'c']; +var iterator = array.keys(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 0, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 1, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 2, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); diff --git a/test/built-ins/Array/prototype/keys/property-descriptor.js b/test/built-ins/Array/prototype/keys/property-descriptor.js new file mode 100644 index 0000000000..b9d5af2b82 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/property-descriptor.js @@ -0,0 +1,14 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should exist on the Array prototype, and it should be writable + and configurable, but not enumerable. + includes: [propertyHelper.js] + es6id: 22.1.3.13 + ---*/ + +verifyNotEnumerable(Array.prototype, 'keys'); +verifyWritable(Array.prototype, 'keys'); +verifyConfigurable(Array.prototype, 'keys'); diff --git a/test/built-ins/Array/prototype/keys/returns-iterator.js b/test/built-ins/Array/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000..b5a8adee78 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/returns-iterator.js @@ -0,0 +1,13 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return an Iterator instance. + es6id: 22.1.3.13 + ---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].keys(); + +assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); diff --git a/test/language/for-of/Array.prototype.Symbol.iterator.js b/test/language/for-of/Array.prototype.Symbol.iterator.js new file mode 100644 index 0000000000..9667acac6c --- /dev/null +++ b/test/language/for-of/Array.prototype.Symbol.iterator.js @@ -0,0 +1,19 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator that can be traversed using a + `for...of` loop. + es6id: 22.1.3.30 + ---*/ + +var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; +var i = 0; + +for (var value of array[Symbol.iterator]()) { + assert.sameValue(value, array[i], 'element at index ' + i); + i++; +} + +assert.sameValue(i, 8, 'Visits all elements'); diff --git a/test/language/for-of/Array.prototype.entries.js b/test/language/for-of/Array.prototype.entries.js new file mode 100644 index 0000000000..487d19ed0c --- /dev/null +++ b/test/language/for-of/Array.prototype.entries.js @@ -0,0 +1,27 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator that can be traversed using a + `for...of` loop. + es6id: 22.1.3.4 + ---*/ + +var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; +var i = 0; + +for (var value of array.entries()) { + assert.sameValue( + value[0], i, 'element at index ' + i + ': value (array key)' + ); + assert.sameValue( + value[1], array[i], 'element at index ' + i + ': value (array value)' + ); + assert.sameValue( + value.length, 2, 'element at index ' + i + ': value (array length)' + ); + i++; +} + +assert.sameValue(i, 8, 'Visits all elements'); diff --git a/test/language/for-of/Array.prototype.keys.js b/test/language/for-of/Array.prototype.keys.js new file mode 100644 index 0000000000..ea05bbf67f --- /dev/null +++ b/test/language/for-of/Array.prototype.keys.js @@ -0,0 +1,19 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The method should return a valid iterator that can be traversed using a + `for...of` loop. + es6id: 22.1.3.13 + ---*/ + +var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; +var i = 0; + +for (var value of array.keys()) { + assert.sameValue(value, i, 'element at index ' + i); + i++; +} + +assert.sameValue(i, 8, 'Visits all elements'); diff --git a/test/language/for-of/array.js b/test/language/for-of/array.js new file mode 100644 index 0000000000..628d70e2db --- /dev/null +++ b/test/language/for-of/array.js @@ -0,0 +1,18 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Array instances should be able to be traversed using a `for...of` loop. + es6id: 13.6.4 + ---*/ + +var array = [0, 'a', true, false, null, /* hole */, undefined, NaN]; +var i = 0; + +for (var value of array) { + assert.sameValue(value, array[i], 'element at index ' + i); + i++; +} + +assert.sameValue(i, 8, 'Visits all elements');