Skip to content
Snippets Groups Projects
Commit f4e17963 authored by Brian Terlson's avatar Brian Terlson
Browse files

Merge pull request #343 from bocoup/MapIteratorPrototype

Fix, update and improve coverage of MapIteratorPrototype
parents 668219cd 7cbf7654
No related branches found
No related tags found
No related merge requests found
Showing
with 291 additions and 34 deletions
// 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]());
......
// 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);
});
// 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]());
// 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);
......
// 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();
......
// 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({});
});
// 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]());
// 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]());
// 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]());
// 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]());
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment