Skip to content

fix(runtime): honor Function.prototype.toString in String(fn) - #4547

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-string-function-tostring-20260605
Jun 5, 2026
Merged

fix(runtime): honor Function.prototype.toString in String(fn)#4547
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-string-function-tostring-20260605

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Summary

  • Resolve function toString through %Function.prototype% for closure string coercion so monkeypatches affect String(fn) and new String(fn).
  • Reuse the same lookup for native fn.toString() dispatch before falling back to registered source text.
  • Add a focused globals parity fixture for plain functions, arrows, and boxed String coercion.

Tests

  • cargo check -q -p perry-hir -p perry-runtime (passes with existing warning noise)
  • PATH=/root/.npm/_npx/bac97da9607b7ef2/node_modules/.bin:$PATH node --experimental-strip-types test-parity/node-suite/globals/function-tostring-override.ts
  • PATH=/root/.npm/_npx/bac97da9607b7ef2/node_modules/.bin:$PATH PERRY_NO_AUTO_OPTIMIZE=1 ./run_parity_tests.sh --suite node-suite --module globals --filter function-tostring
  • cargo fmt --all -- --check
  • git diff --check
  • ./scripts/check_file_size.sh

Fixes #4535

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.

runtime: String()/new String() coercion of a function ignores monkeypatched Function.prototype.toString

2 participants