Skip to content

Commit afaa737

Browse files
committed
fix: property descriptor edge cases
Using the `drafts` object as a source of property descriptors is bad, because enumerability is not preserved by the `drafts` object. Thus, we must use `state.base` when `state.copy` is undefined, which means we need to ensure the property descriptor has a `writable` value of true. Otherwise, the descriptor would be lying.
1 parent f9cd736 commit afaa737

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/proxy.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,13 @@ function deleteProperty(state, prop) {
150150
}
151151

152152
function getOwnPropertyDescriptor(state, prop) {
153-
const owner = state.modified
154-
? state.copy
155-
: has(state.drafts, prop)
156-
? state.drafts
157-
: state.base
158-
const descriptor = Reflect.getOwnPropertyDescriptor(owner, prop)
159-
if (descriptor && !(Array.isArray(owner) && prop === "length"))
160-
descriptor.configurable = true
161-
return descriptor
153+
const owner = source(state)
154+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop)
155+
if (desc) {
156+
desc.writable = true
157+
desc.configurable = !Array.isArray(owner) || prop !== "length"
158+
}
159+
return desc
162160
}
163161

164162
function markChanged(state) {

0 commit comments

Comments
 (0)