summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Set/prototype/forEach
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-boolean.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-null.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-number.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-string.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-symbol.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-undefined.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/forEach.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-insertion-order.js31
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-iterable-entry-order.js29
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js44
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-deleted-then-readded.js47
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-not-deleted.js36
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js47
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/length.js19
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/name.js19
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/returns-undefined.js21
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js28
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit.js24
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-non-strict.js26
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-boolean.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-null.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-number.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-string.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-symbol.js23
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-undefined.js22
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/this-strict-strict.js26
-rw-r--r--js/src/tests/test262/built-ins/Set/prototype/forEach/throws-when-callback-throws.js28
35 files changed, 864 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/browser.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/browser.js
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-boolean.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-boolean.js
new file mode 100644
index 0000000000..f24c6d0ade
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-boolean.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `false` as callback
+
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach(false);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-null.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-null.js
new file mode 100644
index 0000000000..89b29d2737
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-null.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `null` as callback
+
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach(null);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-number.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-number.js
new file mode 100644
index 0000000000..38740e4dd0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-number.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `number` as callback
+
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach(0);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-string.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-string.js
new file mode 100644
index 0000000000..071fd839e2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-string.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `string` as callback
+
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach("");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-symbol.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-symbol.js
new file mode 100644
index 0000000000..0fccfd438a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-symbol.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `symbol` as callback
+
+features: [Symbol]
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach(Symbol());
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-undefined.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-undefined.js
new file mode 100644
index 0000000000..40afeda4db
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/callback-not-callable-undefined.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
+ ...
+
+ Passing `undefined` as callback
+
+---*/
+
+var s = new Set([1]);
+
+assert.throws(TypeError, function() {
+ s.forEach(undefined);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js
new file mode 100644
index 0000000000..d462ba579b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
+ ...
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call([], function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call([], function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js
new file mode 100644
index 0000000000..50f6171e36
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
+ ...
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(new Map(), function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(new Map(), function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js
new file mode 100644
index 0000000000..a8f2bb3d1e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
+ ...
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call({}, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call({}, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js
new file mode 100644
index 0000000000..8ec937a84c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
+ ...
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(Set.prototype, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(Set.prototype, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js
new file mode 100644
index 0000000000..e407f5e46c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 3. If S does not have a [[SetData]] internal slot, throw a TypeError exception.
+ ...
+features: [WeakSet]
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(new WeakSet(), function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(new WeakSet(), function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/forEach.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/forEach.js
new file mode 100644
index 0000000000..e1ec73eb15
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/forEach.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ typeof Set.prototype.forEach,
+ "function",
+ "`typeof Set.prototype.forEach` is `'function'`"
+);
+
+verifyNotEnumerable(Set.prototype, "forEach");
+verifyWritable(Set.prototype, "forEach");
+verifyConfigurable(Set.prototype, "forEach");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-insertion-order.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-insertion-order.js
new file mode 100644
index 0000000000..594b2c0735
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-insertion-order.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+---*/
+
+var s = new Set();
+var expects = [1, 2, 3];
+
+s.add(1).add(2).add(3);
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-iterable-entry-order.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-iterable-entry-order.js
new file mode 100644
index 0000000000..920de93dff
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-in-iterable-entry-order.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+---*/
+
+var expects = [1, 2, 3];
+var s = new Set(expects);
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js
new file mode 100644
index 0000000000..4a6eb0a13e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js
@@ -0,0 +1,44 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+
+ NOTE:
+
+ ...
+ New values added after the call to forEach begins are visited.
+
+---*/
+
+
+var s = new Set([1]);
+var expects = [1, 2, 3];
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ if (value === 1) {
+ set.add(2);
+ }
+
+ if (value === 2) {
+ set.add(3);
+ }
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-deleted-then-readded.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-deleted-then-readded.js
new file mode 100644
index 0000000000..b764598d72
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-deleted-then-readded.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+
+ NOTE:
+
+ ...
+ Values that are deleted after the call to forEach begins and before being visited are not visited unless the value is added again before the forEach call completes.
+ ...
+
+---*/
+
+
+var s = new Set([1, 2, 3]);
+var expects = [1, 3, 2];
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ // Delete `2` before being visited
+ if (value === 1) {
+ set.delete(2);
+ }
+
+ // Re-add `2` before forEach call completes
+ if (value === 3) {
+ set.add(2);
+ }
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-not-deleted.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-not-deleted.js
new file mode 100644
index 0000000000..97f5bde079
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-not-deleted.js
@@ -0,0 +1,36 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+
+ NOTE:
+
+ callbackfn should be a function that accepts three arguments. forEach calls callbackfn once for each value present in the set object, in value insertion order. callbackfn is called only for values of the Set which actually exist; it is not called for keys that have been deleted from the set.
+
+---*/
+
+var expects = [1, 3];
+var s = new Set([1, 2, 3]);
+
+s.delete(2);
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "`forEach` is not a no-op");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js
new file mode 100644
index 0000000000..11de01c1be
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+
+ NOTE:
+
+ ...
+ a value will be revisited if it is deleted after it has been visited and then re-added before the forEach call completes.
+ ...
+
+---*/
+
+
+var s = new Set([1, 2, 3]);
+var expects = [1, 2, 3, 1];
+
+s.forEach(function(value, entry, set) {
+ var expect = expects.shift();
+
+ // Delete `1` after visit
+ if (value === 2) {
+ set.delete(1);
+ }
+
+ // Re-add `1`
+ if (value === 3) {
+ set.add(1);
+ }
+
+ assert.sameValue(value, expect);
+ assert.sameValue(entry, expect);
+ assert.sameValue(set, s);
+});
+
+assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/length.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/length.js
new file mode 100644
index 0000000000..8304c78447
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/length.js
@@ -0,0 +1,19 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ The length property of the forEach method is 1.
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Set.prototype.forEach.length, 1, "The value of `Set.prototype.forEach.length` is `1`");
+
+verifyNotEnumerable(Set.prototype.forEach, "length");
+verifyNotWritable(Set.prototype.forEach, "length");
+verifyConfigurable(Set.prototype.forEach, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/name.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/name.js
new file mode 100644
index 0000000000..390b016c64
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/name.js
@@ -0,0 +1,19 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Set.prototype.forEach.name, "forEach", "The value of `Set.prototype.forEach.name` is `'forEach'`");
+
+verifyNotEnumerable(Set.prototype.forEach, "name");
+verifyNotWritable(Set.prototype.forEach, "name");
+verifyConfigurable(Set.prototype.forEach, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/not-a-constructor.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/not-a-constructor.js
new file mode 100644
index 0000000000..96509bf80a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/not-a-constructor.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ Set.prototype.forEach does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js]
+features: [Reflect.construct, Set, arrow-function]
+---*/
+
+assert.sameValue(
+ isConstructor(Set.prototype.forEach),
+ false,
+ 'isConstructor(Set.prototype.forEach) must return false'
+);
+
+assert.throws(TypeError, () => {
+ let s = new Set([]); new s.forEach(() => {});
+}, '`let s = new Set([]); new s.forEach(() => {})` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/returns-undefined.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/returns-undefined.js
new file mode 100644
index 0000000000..27cac6eb45
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/returns-undefined.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 8. Return undefined.
+
+---*/
+
+var s = new Set([1]);
+
+assert.sameValue(
+ s.forEach(function() {}),
+ undefined,
+ "`s.forEach(function() {})` returns `undefined`"
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/shell.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/shell.js
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js
new file mode 100644
index 0000000000..7c20508936
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ ...
+
+ An arrow function will ignore an explicit thisArg
+
+features: [arrow-function]
+---*/
+
+var s = new Set([1]);
+var usurper = {};
+var counter = 0;
+
+s.forEach(_ => {
+ assert.notSameValue(this, usurper, "`this` is not `usurper`");
+ counter++;
+}, usurper);
+
+assert.sameValue(counter, 1, "`forEach` is not a no-op");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit.js
new file mode 100644
index 0000000000..dcae47e946
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-arg-explicit.js
@@ -0,0 +1,24 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ ...
+---*/
+
+var s = new Set([1]);
+var thisArg = {};
+var counter = 0;
+
+s.forEach(function() {
+ assert.sameValue(this, thisArg, "`this` is `thisArg`");
+ counter++;
+}, thisArg);
+
+assert.sameValue(counter, 1, "`forEach` is not a no-op");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-non-strict.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-non-strict.js
new file mode 100644
index 0000000000..b7d3a08faf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-non-strict.js
@@ -0,0 +1,26 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ ...
+
+flags: [noStrict]
+---*/
+
+var s = new Set([1]);
+var counter = 0;
+var globalObject = this;
+
+s.forEach(function() {
+ assert.sameValue(this, globalObject, "`this` is the global object in non-strict mode code");
+ counter++;
+});
+
+assert.sameValue(counter, 1, "`forEach` is not a no-op");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-boolean.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-boolean.js
new file mode 100644
index 0000000000..d06d23cec1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-boolean.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(false, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(false, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-null.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-null.js
new file mode 100644
index 0000000000..9fb0dd4177
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-null.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(null, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(null, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-number.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-number.js
new file mode 100644
index 0000000000..2ee877c8dc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-number.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(0, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(0, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-string.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-string.js
new file mode 100644
index 0000000000..0e12d3fdc5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-string.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call("", function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call("", function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-symbol.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-symbol.js
new file mode 100644
index 0000000000..acf72f3e03
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-symbol.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+features: [Symbol]
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(Symbol(), function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(Symbol(), function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-undefined.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-undefined.js
new file mode 100644
index 0000000000..cc97196396
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-not-object-throw-undefined.js
@@ -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.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ 1. Let S be the this value.
+ 2. If Type(S) is not Object, throw a TypeError exception.
+
+---*/
+
+assert.throws(TypeError, function() {
+ Set.prototype.forEach.call(undefined, function() {});
+});
+
+assert.throws(TypeError, function() {
+ var s = new Set();
+ s.forEach.call(undefined, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/this-strict-strict.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-strict-strict.js
new file mode 100644
index 0000000000..8360f34120
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/this-strict-strict.js
@@ -0,0 +1,26 @@
+'use strict';
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ ...
+
+flags: [onlyStrict]
+---*/
+
+var s = new Set([1]);
+var counter = 0;
+
+s.forEach(function() {
+ assert.sameValue(this, undefined, "`this` is `undefined` in strict mode code");
+ counter++;
+});
+
+assert.sameValue(counter, 1, "`forEach` is not a no-op");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Set/prototype/forEach/throws-when-callback-throws.js b/js/src/tests/test262/built-ins/Set/prototype/forEach/throws-when-callback-throws.js
new file mode 100644
index 0000000000..423b0d2fe5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Set/prototype/forEach/throws-when-callback-throws.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-set.prototype.forEach
+description: >
+ Set.prototype.forEach ( callbackfn [ , thisArg ] )
+
+ ...
+ 7. Repeat for each e that is an element of entries, in original insertion order
+ a. If e is not empty, then
+ i. Let funcResult be Call(callbackfn, T, «e, e, S»).
+ ii. ReturnIfAbrupt(funcResult).
+ ...
+---*/
+
+var s = new Set([1]);
+var counter = 0;
+
+assert.throws(Error, function() {
+ s.forEach(function() {
+ counter++;
+ throw new Error();
+ });
+});
+
+assert.sameValue(counter, 1, "`forEach` is not a no-op");
+
+reportCompare(0, 0);