summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js')
-rw-r--r--js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js b/js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js
new file mode 100644
index 0000000000..132fcdeeee
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Iterator/prototype/map/mapper-args.js
@@ -0,0 +1,58 @@
+// |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.map
+description: >
+ Iterator.prototype.map mapper is passed the yielded value and a counter as arguments
+info: |
+ %Iterator.prototype%.map ( mapper )
+
+ 5.b.iv. Let mapped be Completion(Call(mapper, undefined, « value, 𝔽(counter) »)).
+
+features: [iterator-helpers]
+flags: []
+---*/
+function* g() {
+ yield 'a';
+ yield 'b';
+ yield 'c';
+ yield 'd';
+ yield 'e';
+}
+
+let assertionCount = 0;
+let iter = g().map((v, count) => {
+ switch (v) {
+ case 'a':
+ assert.sameValue(count, 0);
+ ++assertionCount;
+ return 0;
+ case 'b':
+ assert.sameValue(count, 1);
+ ++assertionCount;
+ return 1;
+ case 'c':
+ assert.sameValue(count, 2);
+ ++assertionCount;
+ return 2;
+ case 'd':
+ assert.sameValue(count, 3);
+ ++assertionCount;
+ return 3;
+ case 'e':
+ assert.sameValue(count, 4);
+ ++assertionCount;
+ return 4;
+ default:
+ throw new Error();
+ }
+});
+
+assert.sameValue(assertionCount, 0);
+
+for (let i of iter);
+
+assert.sameValue(assertionCount, 5);
+
+reportCompare(0, 0);