Skip to content

fix(guard): HasPropertyKey ignores keys inherited from Object.prototype - #1699

Open
kevthedawg wants to merge 1 commit into
sinclairzx81:mainfrom
kevthedawg:fix/clean-own-keys
Open

kevthedawg wants to merge 1 commit into
sinclairzx81:mainfrom
kevthedawg:fix/clean-own-keys

Conversation

@kevthedawg

@kevthedawg kevthedawg commented Sep 26, 2026 •

Copy link
Copy Markdown

Fixes #1698

HasPropertyKey uses key in value, so every plain object picks up toString, valueOf etc. from Object.prototype. That's why Clean doesn't remove keys with those names, and it also makes Check fail when an optional toString is left out, and trips up required, Diff, Default and Repair.

This keeps the prototype walk from 1.0.64 (so getTime on a Date still matches) but stops before Object.prototype. The compiled path still inlines in for normal keys and only calls the guard for Object.prototype names, so it's no slower.

Added tests for each case.

HasPropertyKey used `key in value`, so every plain object "had" toString,
valueOf, hasOwnProperty and the other Object.prototype members. Clean kept
undeclared keys with those names, Check rejected objects that omit an
optional toString or valueOf, Diff missed inserts of those keys, and
{ required: ['toString'] } accepted {}.

HasPropertyKey now walks the prototype chain but stops at Object.prototype,
so class and globalThis instance keys (Date getTime, Uint8Array byteLength)
still count. The emitter keeps the inline `in` for all other keys and calls
the guard for Object.prototype member names. Default and Repair now read
property presence through the guard instead of `value[key]` and `in`.

Fixes sinclairzx81#1698
@kevthedawg kevthedawg changed the title fix(value): Clean decides declared properties by own keys fix(guard): HasPropertyKey ignores keys inherited from Object.prototype Sep 28, 2026

This branch has not been deployed

No deployments
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.

Value.Clean keeps undeclared properties named after Object.prototype members (toString, valueOf, hasOwnProperty…)

1 participant