mirror of https://github.com/tc39/test262.git
Update tests for Array.prototype.entries
This commit is contained in:
parent
8f14f236b8
commit
bab81c5fca
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Property type and descriptor.
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof Array.prototype.entries,
|
||||||
|
'function',
|
||||||
|
'`typeof Array.prototype.entries` is `function`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Array.prototype, 'entries');
|
||||||
|
verifyWritable(Array.prototype, 'entries');
|
||||||
|
verifyConfigurable(Array.prototype, 'entries');
|
|
@ -1,13 +1,14 @@
|
||||||
// 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.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
|
es6id: 22.1.3.4
|
||||||
description: >
|
description: >
|
||||||
|
New items in the array are accessible via iteration until iterator is "done".
|
||||||
|
info: >
|
||||||
The method should return a valid iterator with the context as the
|
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
|
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
|
created but before the iterator is "done" (as defined by 22.1.5.2.1) the
|
||||||
new item should be accessible via iteration.
|
new item should be accessible via iteration.
|
||||||
es6id: 22.1.3.4
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var array = [];
|
var array = [];
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
// 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.
|
// 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
|
es6id: 22.1.3.4
|
||||||
|
description: >
|
||||||
|
The return is a valid iterator with the array's numeric properties.
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
1. Let O be ToObject(this value).
|
||||||
|
2. ReturnIfAbrupt(O).
|
||||||
|
3. Return CreateArrayIterator(O, "key+value").
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var ArrayIteratorPrototype = Object.getPrototypeOf(Array.prototype[Symbol.iterator]());
|
|
||||||
var array = ['a', 'b', 'c'];
|
var array = ['a', 'b', 'c'];
|
||||||
var iterator = array.entries();
|
var iterator = array.entries();
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
assert.sameValue(ArrayIteratorPrototype, Object.getPrototypeOf(array.entries()));
|
|
||||||
|
|
||||||
result = iterator.next();
|
result = iterator.next();
|
||||||
assert.sameValue(result.done, false, 'First result `done` flag');
|
assert.sameValue(result.done, false, 'First result `done` flag');
|
||||||
assert.sameValue(result.value[0], 0, 'First result `value` (array key)');
|
assert.sameValue(result.value[0], 0, 'First result `value` (array key)');
|
||||||
|
|
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Array.prototype.entries.length value and descriptor.
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Array.prototype.entries.length, 0,
|
||||||
|
'The value of `Array.prototype.entries.length` is `0`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Array.prototype.entries, 'length');
|
||||||
|
verifyNotWritable(Array.prototype.entries, 'length');
|
||||||
|
verifyConfigurable(Array.prototype.entries, 'length');
|
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Array.prototype.entries.name value and descriptor.
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Array.prototype.entries.name, 'entries',
|
||||||
|
'The value of `Array.prototype.entries.name` is `"entries"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(Array.prototype.entries, 'name');
|
||||||
|
verifyNotWritable(Array.prototype.entries, 'name');
|
||||||
|
verifyConfigurable(Array.prototype.entries, 'name');
|
|
@ -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: 17
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype, 'entries');
|
|
||||||
verifyWritable(Array.prototype, 'entries');
|
|
||||||
verifyConfigurable(Array.prototype, 'entries');
|
|
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Return abrupt from ToObject(this value).
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
1. Let O be ToObject(this value).
|
||||||
|
2. ReturnIfAbrupt(O).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Array.prototype.entries.call(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Array.prototype.entries.call(null);
|
||||||
|
});
|
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Creates an iterator from a custom object.
|
||||||
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
1. Let O be ToObject(this value).
|
||||||
|
2. ReturnIfAbrupt(O).
|
||||||
|
3. Return CreateArrayIterator(O, "key+value").
|
||||||
|
features: [Symbol.iterator]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
length: 2
|
||||||
|
};
|
||||||
|
var iter = Array.prototype.entries.call(obj);
|
||||||
|
var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]());
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(iter), ArrayIteratorProto,
|
||||||
|
'The prototype of [].entries() is %ArrayIteratorPrototype%'
|
||||||
|
);
|
|
@ -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.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
/*---
|
/*---
|
||||||
|
es6id: 22.1.3.4
|
||||||
description: >
|
description: >
|
||||||
The method should return an Iterator instance.
|
The method should return an Iterator instance.
|
||||||
es6id: 22.1.3.4
|
info: >
|
||||||
|
22.1.3.4 Array.prototype.entries ( )
|
||||||
|
|
||||||
|
1. Let O be ToObject(this value).
|
||||||
|
2. ReturnIfAbrupt(O).
|
||||||
|
3. Return CreateArrayIterator(O, "key+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 ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]());
|
||||||
var iter = [].entries();
|
var iter = [].entries();
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto);
|
assert.sameValue(
|
||||||
|
Object.getPrototypeOf(iter), ArrayIteratorProto,
|
||||||
|
'The prototype of [].entries() is %ArrayIteratorPrototype%'
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue