Merge pull request #344 from bocoup/SetIteratorPrototype

Improve coverage of SetIteratorPrototype
This commit is contained in:
Brian Terlson 2015-07-10 14:26:37 -07:00
commit 53be57f9e8
10 changed files with 298 additions and 37 deletions

View File

@ -1,12 +1,14 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved. // Copyright (C) 2014 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: > es6id: 23.2.3.12
description: >
`Object.prototype.getOwnPropertyDescriptor` should reflect the value and `Object.prototype.getOwnPropertyDescriptor` should reflect the value and
writability of the @@toStringTag attribute. writability of the @@toStringTag attribute.
includes: [propertyHelper.js] includes: [propertyHelper.js]
es6id: 23.2.3.12 features:
- Symbol.toStringTag
- Symbol.iterator
---*/ ---*/
var SetIteratorProto = Object.getPrototypeOf(new Set()[Symbol.iterator]()); var SetIteratorProto = Object.getPrototypeOf(new Set()[Symbol.iterator]());
@ -14,7 +16,7 @@ var SetIteratorProto = Object.getPrototypeOf(new Set()[Symbol.iterator]());
assert.sameValue( assert.sameValue(
'Set Iterator', 'Set Iterator',
SetIteratorProto[Symbol.toStringTag], SetIteratorProto[Symbol.toStringTag],
"`'Set Iterator'` is `SetIteratorProto[Symbol.toStringTag]`" '`Set Iterator` is `SetIteratorProto[Symbol.toStringTag]`'
); );
verifyNotEnumerable(SetIteratorProto, Symbol.toStringTag); verifyNotEnumerable(SetIteratorProto, Symbol.toStringTag);

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.2.5.2.1
description: >
Throws a TypeError if `this` does not have all of the internal slots of a Set
Iterator Instance.
info: >
%SetIteratorPrototype%.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 Set Iterator Instance
(23.2.5.3), throw a TypeError exception.
...
features: [Symbol.iterator]
---*/
var set = new Set([1, 2]);
var iterator = set[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call(set);
});
iterator = set.entries();
assert.throws(TypeError, function() {
iterator.next.call(set);
});
iterator = set.keys();
assert.throws(TypeError, function() {
iterator.next.call(set);
});
iterator = set.values();
assert.throws(TypeError, function() {
iterator.next.call(set);
});

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.2.5.2.1
description: >
Throws a TypeError if `this` does not have all of the internal slots of a Set
Iterator Instance.
info: >
%SetIteratorPrototype%.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 Set Iterator Instance
(23.2.5.3), throw a TypeError exception.
...
features: [Symbol.iterator]
---*/
var set = new Set([1, 2]);
var iterator = set[Symbol.iterator]();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = set.entries();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = set.keys();
assert.throws(TypeError, function() {
iterator.next.call({});
});
iterator = set.values();
assert.throws(TypeError, function() {
iterator.next.call({});
});
// does not throw an Error
iterator.next.call(set[Symbol.iterator]());

View File

@ -1,14 +1,14 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved. // Copyright (C) 2014 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: > es6id: 23.2.3.11
description: >
When an item is added to the set after the iterator is created but before When an item is added to the set after the iterator is created but before
the iterator is "done" (as defined by 23.2.5.2.1), the new item should be the iterator is "done" (as defined by 23.2.5.2.1), the new item should be
accessible via iteration. When an item is added to the set after the accessible via iteration. When an item is added to the set after the
iterator is "done", the new item should not be accessible via iteration. iterator is "done", the new item should not be accessible via iteration.
es6id: 23.2.3.11 features: [Symbol.iterator]
---*/ ---*/
var set = new Set(); var set = new Set();
set.add(1); set.add(1);

View File

@ -1,11 +1,12 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved. // Copyright (C) 2014 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: > es6id: 23.2.3.11
description: >
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. IteratedObject.
es6id: 23.2.3.11 features:
- Symbol.iterator
---*/ ---*/
var set = new Set(); var set = new Set();

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 [[SetData]] internal slot, throw a
TypeError exception as per 23.2.5.1.
es6id: 23.2.3.11
---*/
var iterator = new Set()[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.2.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Set.prototype.entries()
%SetIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var set = new Set([1, 2]);
var iterator = set.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(set[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.2.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Set.prototype.keys()
%SetIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var set = new Set([[1, 11], [2, 22]]);
var iterator = set.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(set[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.2.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
Using Set.prototype[Symbol.iterator]()
%SetIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var set = new Set([[1, 11], [2, 22]]);
var iterator = set[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(set[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.2.5.2.1
description: >
Throws a TypeError if `this` value is not an Object.
info: >
From Set.prototype.values()
%SetIteratorPrototype%.next ( )
1. Let O be the this value.
2. If Type(O) is not Object, throw a TypeError exception.
...
features:
- Symbol
- Symbol.iterator
---*/
var set = new Set([[1, 11], [2, 22]]);
var iterator = set.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(set[Symbol.iterator]());