Skip to content

[codex] Fix Object.prototype.toString brands for functions and namespaces#4269

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-object-tostring-brands
Jun 4, 2026
Merged

[codex] Fix Object.prototype.toString brands for functions and namespaces#4269
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-object-tostring-brands

Conversation

@andrewtdiz
Copy link
Copy Markdown
Contributor

Summary

Part of #3986.

This fixes Object.prototype.toString.call(value) branding for callable values and the built-in namespace objects covered by Node:

  • brands closure-backed functions, class object pointers, and class refs as [object Function] before the numeric fallback
  • installs intrinsic Symbol.toStringTag values for Math, JSON, and Reflect
  • records intrinsic tag descriptors as { writable: false, enumerable: false, configurable: true }
  • adds a focused parity fixture for callable brands, namespace brands/descriptors, and explicit tag overrides

Root Cause

Perry's canonical object-to-string helper did not recognize closure-backed functions or class values before falling through to generic object/number branding. The Math, JSON, and Reflect namespace objects also had reflected members but no intrinsic Symbol.toStringTag, so the default tag stayed [object Object].

Validation

  • Pre-fix latest main plus the new fixture failed with ordinary: [object Object] where Node reports [object Function]
  • PERRY_NO_AUTO_OPTIMIZE=1 npm exec --yes --package=node@26 -- bash -lc 'node --version; ./run_parity_tests.sh --suite node-suite --module globals --filter object-tostring-brands'
  • PERRY_NO_AUTO_OPTIMIZE=1 npm exec --yes --package=node@26 -- bash -lc 'node --version; ./run_parity_tests.sh --suite node-suite --module globals --filter builtin-namespace'
  • PERRY_NO_AUTO_OPTIMIZE=1 npm exec --yes --package=node@26 -- bash -lc 'node --version; ./run_parity_tests.sh --suite node-suite --module globals --filter function-tostring'
  • CARGO_TARGET_DIR=/tmp/perry-object-tostring-check cargo check -p perry-runtime
  • cargo fmt --all -- --check
  • git diff --check
  • ./scripts/check_file_size.sh

@proggeramlug proggeramlug marked this pull request as ready for review June 4, 2026 09:59
@proggeramlug proggeramlug merged commit 2403d6f into PerryTS:main Jun 4, 2026
11 checks passed
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.

2 participants