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 0000000000000000000000000000000000000000..f309b02ac4c8cb641c0654c8a1a52447b1601bc9 --- /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 0000000000000000000000000000000000000000..a146fe49de986bdc5f34603c2a8e6c8fbf7fbe89 --- /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 0000000000000000000000000000000000000000..649b15bf24592529087dc6127156458800cd03f8 --- /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 0000000000000000000000000000000000000000..1f0a63c411786b6bee1d4b741c7fb94b26a723de --- /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 0000000000000000000000000000000000000000..51db927d804e200dac161431244de8a5bd54594a --- /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 0000000000000000000000000000000000000000..b31f19ca01b421bdebcd23db5c29f0f5eafb1555 --- /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 0000000000000000000000000000000000000000..822dfe908a3615b076ce24fbe88cc7f3a552f072 --- /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 0000000000000000000000000000000000000000..f04d40fce145b699f5fd1724b59fe706dedccd2f --- /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 0000000000000000000000000000000000000000..e5df017cf4f19a9bfc7bbe64c3b75f1692e3982a --- /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 0000000000000000000000000000000000000000..f15a26e78b1aa1f09796a42038a88b7a9a56a22c --- /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 0000000000000000000000000000000000000000..888ab3173e8fdd62ac2b9393041451bac4be5af6 --- /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 0000000000000000000000000000000000000000..22b8aa9c53b0c6fcda52abf31989de5e3a6456f2 --- /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 0000000000000000000000000000000000000000..cdf84c8683a644c78d106e584b2f87219c0a62c6 --- /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 0000000000000000000000000000000000000000..7e964bbe553e1b8ce4f25b632720f8d876d7a065 --- /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 0000000000000000000000000000000000000000..b9d5af2b8205400e6529350b2902700ebd9e1c77 --- /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 0000000000000000000000000000000000000000..b5a8adee780ee3d0dfd6a0f09e2211bc2b9c53d7 --- /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 0000000000000000000000000000000000000000..9667acac6cef4e14b9d9f71e8ecbf189ba0cec49 --- /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 0000000000000000000000000000000000000000..487d19ed0ccf505c28bde6857a403fbb7bc2f8db --- /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 0000000000000000000000000000000000000000..ea05bbf67f43fabc03b4d4f216d59ae84c7d3a53 --- /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 0000000000000000000000000000000000000000..628d70e2db982ca3788dd8a57d382ca49fec443e --- /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');