From 22c1a61ddcabd66bed3ae8cf731ef064b8c7bc7d Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Mon, 16 Nov 2026 13:53:02 +0000 Subject: [PATCH 1/2] tests: Map and Set forEach callbacks that keep their keys and values Callbacks declaring fewer parameters than forEach passes, pushing the keys and values into captured arrays, two of them over one Map; the Map and the Set then delete an entry. Under -mm=own each callback gets a copy of what it keeps (compiler: own callbacks declaring fewer parameters). Co-Authored-By: Claude Opus 5.5 --- tests/map_set_forEach_captures.ts | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/map_set_forEach_captures.ts diff --git a/tests/map_set_forEach_captures.ts b/tests/map_set_forEach_captures.ts new file mode 100644 index 0000000..e8c7ae8 --- /dev/null +++ b/tests/map_set_forEach_captures.ts @@ -0,0 +1,32 @@ +// Callbacks over a Map or a Set that keep what they are given: the keys and values pushed into a +// captured array, by callbacks that declare fewer parameters than forEach passes. Under -mm=own each +// gets a copy of the string it keeps. +function main() { + for (let round = 0; round < 100; round++) { + const m = new Map(); + m.set("a", "x"); + m.set("b", "y"); + const keys: string[] = []; + m.forEach((v, k) => { keys.push(k); }); + const values: string[] = []; + m.forEach((v) => { values.push(v); }); + let total = 0; + const counts = new Map(); + counts.set("one", 1); + counts.set("two", 2); + counts.forEach((v) => { total += v; }); + + const s = new Set(["p", "q", "r"]); + const items: string[] = []; + s.forEach((v) => { items.push(v); }); + + m.delete("a"); + s.delete("p"); + assert(keys.length == 2 && keys[0] == "a" && keys[1] == "b", "keys"); + assert(values.length == 2 && values[0] == "x" && values[1] == "y", "values"); + assert(total == 3, "total"); + assert(items.length == 3 && items[0] == "p" && items[2] == "r", "items"); + } + + print("done."); +} From c0391197a259216c1943abf5e71ecf5df0904c43 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Mon, 16 Nov 2026 14:12:30 +0000 Subject: [PATCH 2/2] tests: map_set_forEach_captures ends with the ALL DONE marker Co-Authored-By: Claude Opus 5.5 --- tests/map_set_forEach_captures.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/map_set_forEach_captures.ts b/tests/map_set_forEach_captures.ts index e8c7ae8..139302f 100644 --- a/tests/map_set_forEach_captures.ts +++ b/tests/map_set_forEach_captures.ts @@ -28,5 +28,5 @@ function main() { assert(items.length == 3 && items[0] == "p" && items[2] == "r", "items"); } - print("done."); + print("ALL DONE"); }