Skip to content

fix: read toJSON accessors once per serialized value - #83

Merged
BridgeAR merged 1 commit into
BridgeAR:mainfrom
mayankdhingra02:codex/read-tojson-accessors-once
Nov 13, 2026
Merged

BridgeAR merged 1 commit into
BridgeAR:mainfrom
mayankdhingra02:codex/read-tojson-accessors-once

Conversation

@mayankdhingra02

Copy link
Copy Markdown
Contributor

An accessor-backed toJSON is currently read twice for one serialized value. A getter that creates its hook from changing state can therefore produce different data from JSON.stringify, which reads it once.

Keep the hook from the first lookup and invoke it with the original receiver. Regression tests cover own and inherited accessors, nested objects and arrays, both replacer forms, indentation and safe mode. They also preserve hooks with an own call property in the default mode.

npm test and npm run tsc pass on Node 18, 20, 22, 24 and 26, with 100% statement, branch, function and line coverage. Node 24/26 pass all 84,946 assertions. Node 18/20/22 pass 84,904 assertions and retain the existing skip for unavailable Float16Array. An independent comparison against native JSON also passes 4,212 cases on Node 18 and 26.

Optional throughput diagnostics exceeded the benchmark helper's 3% variance limit on both the original and patched source, so they do not establish a performance change.

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you. Is this something critical for you to be released?

@BridgeAR
BridgeAR merged commit 4e6f20f into BridgeAR:main Nov 13, 2026
5 checks passed
@mayankdhingra02

Copy link
Copy Markdown
Contributor Author

Thanks for merging! There’s no urgent release needed for this fix.

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