summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js')
-rw-r--r--js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js b/js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js
new file mode 100644
index 0000000000..7c74ffe05f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Iterator/prototype/flatMap/get-next-method-only-once.js
@@ -0,0 +1,44 @@
+// |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.flatMap
+description: >
+ Gets the next method from the underlying iterator only once
+info: |
+ %Iterator.prototype%.flatMap ( mapper )
+
+ 4. Let iterated be ? GetIteratorDirect(O).
+
+features: [iterator-helpers]
+flags: []
+---*/
+let nextGets = 0;
+let nextCalls = 0;
+
+class CountingIterator extends Iterator {
+ get next() {
+ ++nextGets;
+ let iter = (function* () {
+ for (let i = 1; i < 5; ++i) {
+ yield i;
+ }
+ })();
+ return function () {
+ ++nextCalls;
+ return iter.next();
+ };
+ }
+}
+
+let iterator = new CountingIterator();
+
+assert.sameValue(nextGets, 0);
+assert.sameValue(nextCalls, 0);
+
+for (const value of iterator.flatMap(() => []));
+
+assert.sameValue(nextGets, 1);
+assert.sameValue(nextCalls, 5);
+
+reportCompare(0, 0);