Skip to content

test: pin draft prototype-inspection behavior restored by #1271#1272

Open
jonatankruszewski wants to merge 1 commit into
immerjs:mainfrom
jonatankruszewski:prototype-inspection-tests
Open

test: pin draft prototype-inspection behavior restored by #1271#1272
jonatankruszewski wants to merge 1 commit into
immerjs:mainfrom
jonatankruszewski:prototype-inspection-tests

Conversation

@jonatankruszewski

Copy link
Copy Markdown

Follow-up to our conversation. This adds a test-only file that pins the prototype-inspection behavior of drafts, so it can't silently regress in a future 11.x refactor.

Why

#1259 wrapped constructor/__proto__ reads in a sanitizing Proxy. That broke ecosystem libraries which introspect prototypes to classify values — e.g. lodash's isPrototype (behind _.isEmpty/_.isEqual/_.isPlainObject) reads
value.constructor.prototype, and fast-deep-equal compares a.constructor.

Reading constructor.prototype through the guard tripped the Proxy invariant for Object's non-configurable prototype, so those reads threw or misreported

(#1265, #1266, #1268). It was reverted in #1271.

Right now nothing in the suite locks in the reverted behavior, so the same guard could get reintroduced without a failing test. These cases close that gap.

What's covered

Notes

Drafts must stay safe for ecosystem introspection idioms: lodash's
isPrototype (used by isEmpty/isEqual/isPlainObject) reads
value.constructor.prototype, and fast-deep-equal compares constructor
identity. The guard reverted in immerjs#1271 broke these (immerjs#1265, immerjs#1266, immerjs#1268)
while its tests still passed, because try/catch made a crash and a
successful block indistinguishable.

These tests assert observable behavior directly, so they fail on
11.1.9-11.1.11 (verified: constructor.prototype throws, constructor
identity and 'in' checks break, writes to own keys named prototype are
dropped) and pass on main. setPrototypeOf remains forbidden; the
applyPatches-layer pollution guards in patch.js are untouched.
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