summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js')
-rw-r--r--js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js b/js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js
new file mode 100644
index 0000000000..06e64bf63d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js
@@ -0,0 +1,39 @@
+// |reftest| shell-option(--enable-iterator-helpers) skip-if(!this.hasOwnProperty('Iterator')||!xulRuntime.shell) -- iterator-helpers is not enabled unconditionally, requires shell-options
+// Copyright (C) 2023 Michael Ficarra. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-iteratorprototype.forEach
+description: >
+ Gets the next method from the iterator only once
+info: |
+ %Iterator.prototype%.forEach ( fn )
+
+features: [iterator-helpers]
+flags: []
+---*/
+let nextGets = 0;
+
+class TestIterator extends Iterator {
+ get next() {
+ ++nextGets;
+ let counter = 5;
+ return function () {
+ if (counter < 0) {
+ return { done: true, value: undefined };
+ } else {
+ return { done: false, value: --counter };
+ }
+ };
+ }
+}
+
+let iterator = new TestIterator();
+
+assert.sameValue(nextGets, 0);
+assert.sameValue(
+ iterator.forEach(() => {}),
+ undefined
+);
+assert.sameValue(nextGets, 1);
+
+reportCompare(0, 0);