8000 fix: harden getRawTag against non-configurable and accessor Symbol.toStringTag by scrrlt · Pull Request #6078 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@scrrlt
Copy link
@scrrlt scrrlt commented Jan 5, 2026

summary

  • improves the stability of getRawTag by using Object.getOwnPropertyDescriptor to safely mask and unmask the Symbol.toStringTag property. It prevents TypeError in strict mode and ensures that getters/setters on the prototype chain are not destroyed during type detection.
  • current implementation assumes Symbol.toStringTag is always a simple, writable data property. causing two critical failures:
  • attempting to assign undefined to a non-configurable or read-only toStringTag throws a TypeError in strict mode.
  • If toStringTag is a getter, the current implementation overwrites it with undefined, permanently destroying the getter mechanism on the object instance.

fix

  • verifies property descriptors before assignment to ensure the property is configurable.
  • preserves the original property state (including getters/setters) using Object.defineProperty rather than simple assignment.
  • prevents temporary tag patching from leaking between lookups by ensuring cleanup occurs even if errors are thrown.
  • includes a fallback for environments without getOwnPropertyDescriptor, ensuring Object.prototype.toString is used when the tag cannot be safely modified.

test coverage
added a new test suite test/getRawTag.spec.js covering the following edge cases:

  • DataView instances (regression check).
  • non-configurable Symbol.toStringTag (prevents crash).
  • prototype setters that throw errors (hostile environment check).
  • restoration of accessor-based toStringTag after execution.

@scrrlt scrrlt changed the title fix: harden getRawTag fallback when Symbol.toStringTag is masked fix: harden getRawTag against non-configurable and accessor Symbol.toStringTag Jan 5, 2026
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

0