Skip to content

fix(runtime): hide WeakRef/WeakMap/WeakSet/FinalizationRegistry internal slots (#1766) - #2267

Merged
proggeramlug merged 1 commit into
mainfrom
worktree-fix-1766-weakmap-dispatch
May 28, 2026
Merged

fix(runtime): hide WeakRef/WeakMap/WeakSet/FinalizationRegistry internal slots (#1766)#2267
proggeramlug merged 1 commit into
mainfrom
worktree-fix-1766-weakmap-dispatch

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Summary

  • WeakRef / WeakMap / WeakSet / FinalizationRegistry stored their backing data under user-visible field names (target, entries, callback). User code reading (wr as any).target or (wm as any).entries returned the raw internal slot (the [key,value]-pair array, the WeakRef target, the cleanup callback) instead of undefined like Node — the weak-wrapper abstraction leaked.
  • Rename all four shapes to __perry_* sentinels (__perry_wr_target, __perry_wk_entries shared by WeakMap/WeakSet, __perry_fr_callback + __perry_fr_entries) so the user-level property reads land on undefined. The internal accessors (entries_array, js_weakref_deref, js_finreg_register/_unregister) use the same sentinels so functional methods stay byte-identical with Node.

Test plan

  • New gap test test-files/test_issue_1766_weakref_internal_fields.ts byte-identical with Node — covers the leak surface for all four wrapper kinds plus a positive functional round-trip per kind.
  • Existing test_gap_weakmap_dynamic.ts and test_gap_weakref_finalization.ts parity tests still byte-identical with Node (no regression).
  • cargo fmt --all -- --check clean.
  • cargo test --release -p perry-runtime --lib — 736 tests pass.

…nal slots (#1766)

The runtime wrappers for `WeakRef`, `WeakMap`, `WeakSet`, and
`FinalizationRegistry` stored their backing data under user-visible
field names (`target`, `entries`, `callback`). Reading those fields from
user code via `(wr as any).target` / `(wm as any).entries` returned the
internal storage slot instead of `undefined` like Node, leaking the
`[key, value]`-pair array out of the weak-collection abstraction.

Rename all four shapes' internal slots to `__perry_*` sentinels so
property reads land on undefined and the inspect-output / functional
methods continue to work through the same internal accessors.
@proggeramlug
proggeramlug merged commit d4d600a into main May 28, 2026
11 checks passed
@proggeramlug
proggeramlug deleted the worktree-fix-1766-weakmap-dispatch branch May 28, 2026 17:42
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