Skip to content

fix(codemode): live Map/Set forEach, generator prototypes, repeated function declarations, delete on non-references - #50450

Merged
rekram1-node merged 1 commit into
v2from
small-fixes-two
Sep 21, 2026
Merged

rekram1-node merged 1 commit into
v2from
small-fixes-two

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Five small JS-conformance fixes, each a few lines.

 const m = new Map([[1, "a"], [2, "b"]])
 m.forEach((v, k) => { if (k === 1) { m.delete(2); m.set(3, "c") } log(k) })
-1 2                      // walked a snapshot
+1 3                      // live, as in JS: deleted entries skipped, added ones visited

 function* g() {}
-g() instanceof g         // TypeError: no 'prototype' object
+g() instanceof g         // true; each generator function has its own prototype

 function f() { return 1 }
 function f() { return 2 }
-                         // TypeError: Identifier 'f' has already been declared
+f()                      // 2; last declaration wins, and `var f` may share the name

 const fact = function inner(n) { return n <= 1 ? 1 : n * inner(n - 1) }
-fact(4)                  // ReferenceError: Unknown identifier 'inner'
+fact(4)                  // 24; a named function expression sees its own name, read-only

-delete 0                 // TypeError: Only data fields may be deleted
+delete 0                 // true; the operand is evaluated. `delete variable` still throws.

Where

change file
forEach: drop the Array.from snapshot; the host Map/Set iterator is already live stdlib/collections.ts
createFunction: define prototype on generator functions; push a read-only own-name scope for named function expressions interpreter/interpreter.ts
createGenerator: use the function's prototype as the generator's proto interpreter/interpreter.ts
hoistFunctions: scope.set instead of scope.declare interpreter/interpreter.ts
evaluateDeleteExpression: non-member, non-identifier operand → evaluate, true interpreter/interpreter.ts
Fn.capturedScopes is now Array (it was already a fresh copy from capture()) interpreter/objects.ts

Plain functions still have no prototype — they cannot construct here. Assigning to a named function expression's own name throws (strict-mode behavior); sloppy JS ignores it silently.

Tests

suite before after
codemode 5281 5294
test262 3982 / 411 3990 / 403

Eight skipped.txt entries removed (statements/function/S13_A3_T1, S13_A6_T1, S14_A2, S14_A5_T1/T2, statements/generators/has-instance, prototype-typeof, prototype-uniqueness). Two [ ] lines in interpreter-support.md flipped to [x].

…unction declarations, delete on non-references
@rekram1-node
rekram1-node merged commit 02566f6 into v2 Sep 21, 2026
9 of 10 checks passed
@rekram1-node
rekram1-node deleted the small-fixes-two branch September 21, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant