test: pin draft prototype-inspection behavior restored by #1271#1272
Open
jonatankruszewski wants to merge 1 commit into
Open
test: pin draft prototype-inspection behavior restored by #1271#1272jonatankruszewski wants to merge 1 commit into
jonatankruszewski wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sisPrototype(behind_.isEmpty/_.isEqual/_.isPlainObject) readsvalue.constructor.prototype, and fast-deep-equal comparesa.constructor.Reading
constructor.prototypethrough the guard tripped the Proxy invariant forObject's non-configurableprototype, 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
draft.constructorreturns the real constructor for object, array, and[immerable]class draftsfast-deep-equal#1266)draft.constructor.prototypeis readable and doesn't throw (TypeError: 'get' on proxy: property 'prototype' is a read-only and non-configurable data property on the proxy target #1265, lodash.isEmpty() on a draft throws "TypeError: 'get' on proxy: property 'prototype'..." since 11.1.9 #1268)isPrototypeidiom works on drafts (lodash.isEmpty() on a draft throws "TypeError: 'get' on proxy: property 'prototype'..." since 11.1.9 #1268)constructor) report correctly throughin/Object.keys, and own data keys namedconstructor/prototyperound-tripObject.getPrototypeOf/__proto__return the real prototypesetPrototypeOfon a draft is still forbiddenNotes
__tests__/prototype-inspection.jsonly.