Improve coverage of MapIteratorPrototype

This commit is contained in:
Leonardo Balter 2015-06-30 17:03:14 -04:00
parent 1e80bf22f6
commit 7cbf7654e5
10 changed files with 291 additions and 34 deletions

View File

@ -1,12 +1,11 @@
// Copyright (C) 2014 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: 23.1.3.13
es6id: 23.1.5.2.2
description: >
`Object.prototype.getOwnPropertyDescriptor` should reflect the value and
writability of the @@toStringTag attribute.
includes: [propertyHelper.js]
---*/
var MapIteratorProto = Object.getPrototypeOf(new Map()[Symbol.iterator]());

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: 23.1.5.2.1
description: >
Throws a TypeError if `this` does not have all of the internal slots of a Map
Iterator Instance.
info: >
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
3. If O does not have all of the internal slots of a Map Iterator Instance
(23.1.5.3), throw a TypeError exception.
...
features: [Symbol.iterator]
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call(map);
});
iterator = map.entries();
assert.throws(TypeError, function() {
iterator.next.call(map);
});
iterator = map.keys();
assert.throws(TypeError, function() {
iterator.next.call(map);
});
iterator = map.values();
assert.throws(TypeError, function() {
iterator.next.call(map);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.5.2.1
description: >
Throws a TypeError if `this` does not have all of the internal slots of a Map
Iterator Instance.
info: >
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
3. If O does not have all of the internal slots of a Map Iterator Instance
(23.1.5.3), throw a TypeError exception.
...
features: [Symbol.iterator]
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = map.entries();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = map.keys();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = map.values();
assert.throws(TypeError, function() {
iterator.next.call({});
});
// does not throw an Error
iterator.next.call(map[Symbol.iterator]());

View File

@ -1,14 +1,14 @@
// Copyright (C) 2014 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 map after the iterator is created but before
the iterator is "done" (as defined by 23.1.5.2.1), the new item should be
accessible via iteration. When an item is added to the map after the
iterator is "done", the new item should not be accessible via iteration.
es6id: 23.1.3.12
---*/
es6id: 23.1.3.12
description: >
When an item is added to the map after the iterator is created but before
the iterator is "done" (as defined by 23.1.5.2.1), the new item should be
accessible via iteration. When an item is added to the map after the
iterator is "done", the new item should not be accessible via iteration.
features: [Symbol.iterator]
---*/
var map = new Map();
map.set(1, 11);

View File

@ -1,11 +1,11 @@
// Copyright (C) 2014 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: 23.2.3.11
es6id: 23.1.3.12
description: >
The method should return a valid iterator with the context as the
IteratedObject.
features: [Symbol.iterator]
---*/
var map = new Map();

View File

@ -1,15 +0,0 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the context does not have a [[MapData]] internal slot, throw a
TypeError exception as per 23.1.5.1.
es6id: 23.1.3.12
---*/
var iterator = new Map()[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call({});
});

View File

@ -0,0 +1,48 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Map.prototype.entries()
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map.entries();
assert.throws(TypeError, function() {
iterator.next.call(false);
});
assert.throws(TypeError, function() {
iterator.next.call(1);
});
assert.throws(TypeError, function() {
iterator.next.call('');
});
assert.throws(TypeError, function() {
iterator.next.call(undefined);
});
assert.throws(TypeError, function() {
iterator.next.call(null);
});
assert.throws(TypeError, function() {
iterator.next.call(Symbol());
});
// does not throw an Error
iterator.next.call(map[Symbol.iterator]());

View File

@ -0,0 +1,48 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Map.prototype.keys()
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map.keys();
assert.throws(TypeError, function() {
iterator.next.call(false);
});
assert.throws(TypeError, function() {
iterator.next.call(1);
});
assert.throws(TypeError, function() {
iterator.next.call('');
});
assert.throws(TypeError, function() {
iterator.next.call(undefined);
});
assert.throws(TypeError, function() {
iterator.next.call(null);
});
assert.throws(TypeError, function() {
iterator.next.call(Symbol());
});
// does not throw an Error
iterator.next.call(map[Symbol.iterator]());

View File

@ -0,0 +1,48 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
Using Map.prototype[Symbol.iterator]()
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call(false);
});
assert.throws(TypeError, function() {
iterator.next.call(1);
});
assert.throws(TypeError, function() {
iterator.next.call('');
});
assert.throws(TypeError, function() {
iterator.next.call(undefined);
});
assert.throws(TypeError, function() {
iterator.next.call(null);
});
assert.throws(TypeError, function() {
iterator.next.call(Symbol());
});
// does not throw an Error
iterator.next.call(map[Symbol.iterator]());

View File

@ -0,0 +1,48 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Map.prototype.values()
%MapIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var map = new Map([[1, 11], [2, 22]]);
var iterator = map.values();
assert.throws(TypeError, function() {
iterator.next.call(false);
});
assert.throws(TypeError, function() {
iterator.next.call(1);
});
assert.throws(TypeError, function() {
iterator.next.call('');
});
assert.throws(TypeError, function() {
iterator.next.call(undefined);
});
assert.throws(TypeError, function() {
iterator.next.call(null);
});
assert.throws(TypeError, function() {
iterator.next.call(Symbol());
});
// does not throw an Error
iterator.next.call(map[Symbol.iterator]());