From a330d0d979f6b0458162465e08ed31fa2be06cb8 Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Tue, 30 Jun 2015 17:12:50 -0400
Subject: [PATCH] Improve coverage of SetIteratorPrototype

---
 .../Symbol.toStringTag.js                     | 20 ++++----
 ...not-have-mapiterator-internal-slots-set.js | 39 +++++++++++++++
 ...oes-not-have-mapiterator-internal-slots.js | 42 ++++++++++++++++
 .../next/iteration-mutable.js                 | 16 +++----
 .../SetIteratorPrototype/next/iteration.js    | 11 +++--
 .../SetIteratorPrototype/next/no-set-data.js  | 15 ------
 .../next/this-not-object-throw-entries.js     | 48 +++++++++++++++++++
 .../next/this-not-object-throw-keys.js        | 48 +++++++++++++++++++
 ...his-not-object-throw-prototype-iterator.js | 48 +++++++++++++++++++
 .../next/this-not-object-throw-values.js      | 48 +++++++++++++++++++
 10 files changed, 298 insertions(+), 37 deletions(-)
 create mode 100644 test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots-set.js
 create mode 100644 test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots.js
 delete mode 100644 test/built-ins/SetIteratorPrototype/next/no-set-data.js
 create mode 100644 test/built-ins/SetIteratorPrototype/next/this-not-object-throw-entries.js
 create mode 100644 test/built-ins/SetIteratorPrototype/next/this-not-object-throw-keys.js
 create mode 100644 test/built-ins/SetIteratorPrototype/next/this-not-object-throw-prototype-iterator.js
 create mode 100644 test/built-ins/SetIteratorPrototype/next/this-not-object-throw-values.js

diff --git a/test/built-ins/SetIteratorPrototype/Symbol.toStringTag.js b/test/built-ins/SetIteratorPrototype/Symbol.toStringTag.js
index 871d73571b..83a389f86f 100644
--- a/test/built-ins/SetIteratorPrototype/Symbol.toStringTag.js
+++ b/test/built-ins/SetIteratorPrototype/Symbol.toStringTag.js
@@ -1,20 +1,22 @@
 // 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.2.3.12
+es6id: 23.2.3.12
+description: >
+  `Object.prototype.getOwnPropertyDescriptor` should reflect the value and
+  writability of the @@toStringTag attribute.
+includes: [propertyHelper.js]
+features:
+  - Symbol.toStringTag
+  - Symbol.iterator
  ---*/
 
 var SetIteratorProto = Object.getPrototypeOf(new Set()[Symbol.iterator]());
 
 assert.sameValue(
- 'Set Iterator',
- SetIteratorProto[Symbol.toStringTag],
- "`'Set Iterator'` is `SetIteratorProto[Symbol.toStringTag]`"
+  'Set Iterator',
+  SetIteratorProto[Symbol.toStringTag],
+  '`Set Iterator` is `SetIteratorProto[Symbol.toStringTag]`'
 );
 
 verifyNotEnumerable(SetIteratorProto, Symbol.toStringTag);
diff --git a/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots-set.js b/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots-set.js
new file mode 100644
index 0000000000..6b729eacc7
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots-set.js
@@ -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);
+});
diff --git a/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots.js b/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots.js
new file mode 100644
index 0000000000..631b641e96
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/does-not-have-mapiterator-internal-slots.js
@@ -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]());
diff --git a/test/built-ins/SetIteratorPrototype/next/iteration-mutable.js b/test/built-ins/SetIteratorPrototype/next/iteration-mutable.js
index 01b9f68efd..9d91688eab 100644
--- a/test/built-ins/SetIteratorPrototype/next/iteration-mutable.js
+++ b/test/built-ins/SetIteratorPrototype/next/iteration-mutable.js
@@ -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 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
-      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.
-  es6id: 23.2.3.11
- ---*/
+es6id: 23.2.3.11
+description: >
+  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
+  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.
+features: [Symbol.iterator]
+---*/
 
 var set = new Set();
 set.add(1);
diff --git a/test/built-ins/SetIteratorPrototype/next/iteration.js b/test/built-ins/SetIteratorPrototype/next/iteration.js
index 1889923afd..64688c12f0 100644
--- a/test/built-ins/SetIteratorPrototype/next/iteration.js
+++ b/test/built-ins/SetIteratorPrototype/next/iteration.js
@@ -1,11 +1,12 @@
 // 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.2.3.11
+description: >
+  The method should return a valid iterator with the context as the
+  IteratedObject.
+features:
+  - Symbol.iterator
  ---*/
 
 var set = new Set();
diff --git a/test/built-ins/SetIteratorPrototype/next/no-set-data.js b/test/built-ins/SetIteratorPrototype/next/no-set-data.js
deleted file mode 100644
index 55feabcadf..0000000000
--- a/test/built-ins/SetIteratorPrototype/next/no-set-data.js
+++ /dev/null
@@ -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({});
-});
diff --git a/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-entries.js b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-entries.js
new file mode 100644
index 0000000000..e5e616a5f5
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-entries.js
@@ -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]());
diff --git a/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-keys.js b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-keys.js
new file mode 100644
index 0000000000..7ae20213a1
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-keys.js
@@ -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]());
diff --git a/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-prototype-iterator.js b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-prototype-iterator.js
new file mode 100644
index 0000000000..87338d389e
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-prototype-iterator.js
@@ -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]());
diff --git a/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-values.js b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-values.js
new file mode 100644
index 0000000000..2443af3572
--- /dev/null
+++ b/test/built-ins/SetIteratorPrototype/next/this-not-object-throw-values.js
@@ -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]());
-- 
GitLab