Skip to content

Commit

Permalink
fix: property descriptor edge cases
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aleclarson committed Jan 21, 2019
1 parent f9cd736 commit afaa737
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/proxy.js
Expand Up @@ -150,15 +150,13 @@ function deleteProperty(state, prop) {
}

function getOwnPropertyDescriptor(state, prop) {
const owner = state.modified
? state.copy
: has(state.drafts, prop)
? state.drafts
: state.base
const descriptor = Reflect.getOwnPropertyDescriptor(owner, prop)
if (descriptor && !(Array.isArray(owner) && prop === "length"))
descriptor.configurable = true
return descriptor
const owner = source(state)
const desc = Reflect.getOwnPropertyDescriptor(owner, prop)
if (desc) {
desc.writable = true
desc.configurable = !Array.isArray(owner) || prop !== "length"
}
return desc
}

function markChanged(state) {
Expand Down

0 comments on commit afaa737

Please sign in to comment.