diff --git a/test/built-ins/Array/prototype/keys/iteration-mutable.js b/test/built-ins/Array/prototype/keys/iteration-mutable.js index 4f77993b6a..6b20255cb9 100644 --- a/test/built-ins/Array/prototype/keys/iteration-mutable.js +++ b/test/built-ins/Array/prototype/keys/iteration-mutable.js @@ -1,15 +1,16 @@ -// Copyright (C) 2013 the V8 project authors. All rights reserved. +// Copyright (C) 2015 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 "done", the new item's key should not be - accessible via iteration. - es6id: 22.1.3.13 - ---*/ +es6id: 22.1.3.13 +description: > + New items in the array are accessible via iteration until iterator is "done". +info: > + 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 "done", the new item's key should not be + accessible via iteration. +---*/ var array = []; var iterator = array.keys(); @@ -28,5 +29,11 @@ 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)'); +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 index 7e964bbe55..e9a71fb57a 100644 --- a/test/built-ins/Array/prototype/keys/iteration.js +++ b/test/built-ins/Array/prototype/keys/iteration.js @@ -1,12 +1,16 @@ -// Copyright (C) 2013 the V8 project authors. All rights reserved. +// Copyright (C) 2015 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 - ---*/ +es6id: 22.1.3.13 +description: > + The return is a valid iterator with the array's numeric properties. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +---*/ var array = ['a', 'b', 'c']; var iterator = array.keys(); diff --git a/test/built-ins/Array/prototype/keys/keys.js b/test/built-ins/Array/prototype/keys/keys.js new file mode 100644 index 0000000000..502e66f636 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/keys.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.13 +description: > + Property type and descriptor. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof Array.prototype.keys, + 'function', + '`typeof Array.prototype.keys` is `function`' +); + +verifyNotEnumerable(Array.prototype, 'keys'); +verifyWritable(Array.prototype, 'keys'); +verifyConfigurable(Array.prototype, 'keys'); diff --git a/test/built-ins/Array/prototype/keys/length.js b/test/built-ins/Array/prototype/keys/length.js new file mode 100644 index 0000000000..0ebabd6fb9 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/length.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.13 +description: > + Array.prototype.keys.length value and descriptor. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.keys.length, 0, + 'The value of `Array.prototype.keys.length` is `0`' +); + +verifyNotEnumerable(Array.prototype.keys, 'length'); +verifyNotWritable(Array.prototype.keys, 'length'); +verifyConfigurable(Array.prototype.keys, 'length'); diff --git a/test/built-ins/Array/prototype/keys/name.js b/test/built-ins/Array/prototype/keys/name.js new file mode 100644 index 0000000000..2d036f7f7a --- /dev/null +++ b/test/built-ins/Array/prototype/keys/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.13 +description: > + Array.prototype.keys.name value and descriptor. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Array.prototype.keys.name, 'keys', + 'The value of `Array.prototype.keys.name` is `"keys"`' +); + +verifyNotEnumerable(Array.prototype.keys, 'name'); +verifyNotWritable(Array.prototype.keys, 'name'); +verifyConfigurable(Array.prototype.keys, 'name'); diff --git a/test/built-ins/Array/prototype/keys/property-descriptor.js b/test/built-ins/Array/prototype/keys/property-descriptor.js deleted file mode 100644 index b9d5af2b82..0000000000 --- a/test/built-ins/Array/prototype/keys/property-descriptor.js +++ /dev/null @@ -1,14 +0,0 @@ -// 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/return-abrupt-from-this.js b/test/built-ins/Array/prototype/keys/return-abrupt-from-this.js new file mode 100644 index 0000000000..9905e8e4ac --- /dev/null +++ b/test/built-ins/Array/prototype/keys/return-abrupt-from-this.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.13 +description: > + Return abrupt from ToObject(this value). +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + Array.prototype.keys.call(undefined); +}); + +assert.throws(TypeError, function() { + Array.prototype.keys.call(null); +}); diff --git a/test/built-ins/Array/prototype/keys/returns-iterator-from-object.js b/test/built-ins/Array/prototype/keys/returns-iterator-from-object.js new file mode 100644 index 0000000000..d28554bdf9 --- /dev/null +++ b/test/built-ins/Array/prototype/keys/returns-iterator-from-object.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.3.13 +description: > + Creates an iterator from a custom object. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = Array.prototype.keys.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +); diff --git a/test/built-ins/Array/prototype/keys/returns-iterator.js b/test/built-ins/Array/prototype/keys/returns-iterator.js index b5a8adee78..10ce2a580b 100644 --- a/test/built-ins/Array/prototype/keys/returns-iterator.js +++ b/test/built-ins/Array/prototype/keys/returns-iterator.js @@ -1,13 +1,30 @@ -// Copyright (C) 2013 the V8 project authors. All rights reserved. +// Copyright (C) 2015 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 - ---*/ +es6id: 22.1.3.13 +description: > + The method should return an Iterator instance. +info: > + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). + + 22.1.5.1 CreateArrayIterator Abstract Operation + + ... + 2. Let iterator be ObjectCreate(%ArrayIteratorPrototype%, «‍[[IteratedObject]], + [[ArrayIteratorNextIndex]], [[ArrayIterationKind]]»). + ... + 6. Return iterator. +features: [Symbol.iterator] +---*/ var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); var iter = [].keys(); -assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +);