Add tests for Array.prototype.values

This commit is contained in:
Leonardo Balter 2015-07-16 18:35:28 -04:00
parent bab81c5fca
commit d6a96506f5
4 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// 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.29
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
value should be accessible via iteration. When an item is added to the
array after the iterator is "done", the new item should not be
accessible via iteration.
---*/
var array = [];
var iterator = array.values();
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)'
);

View File

@ -0,0 +1,33 @@
// 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.29
description: >
The return is a valid iterator with the array's numeric properties.
info: >
22.1.3.29 Array.prototype.values ( )
1. Let O be ToObject(this value).
2. ReturnIfAbrupt(O).
3. Return CreateArrayIterator(O, "value").
---*/
var array = ['a', 'b', 'c'];
var iterator = array.values();
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');

View File

@ -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.29
description: >
Creates an iterator from a custom object.
info: >
22.1.3.29 Array.prototype.values ( )
1. Let O be ToObject(this value).
2. ReturnIfAbrupt(O).
3. Return CreateArrayIterator(O, "value").
features: [Symbol.iterator]
---*/
var obj = {
length: 2
};
var iter = Array.prototype.values.call(obj);
var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]());
assert.sameValue(
Object.getPrototypeOf(iter), ArrayIteratorProto,
'The prototype of [].values() is %ArrayIteratorPrototype%'
);

View File

@ -0,0 +1,30 @@
// 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.29
description: >
The method should return an Iterator instance.
info: >
22.1.3.29 Array.prototype.values ( )
1. Let O be ToObject(this value).
2. ReturnIfAbrupt(O).
3. Return CreateArrayIterator(O, "value").
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 = [].values();
assert.sameValue(
Object.getPrototypeOf(iter), ArrayIteratorProto,
'The prototype of [].values() is %ArrayIteratorPrototype%'
);