Skip to content
Myr

Fix: freezing of Map values during finalization (#1150)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Map keys are not enumerable properties of the Map object, so the propertyIsEnumerable check does not apply to them. This commit adds a condition to detect Map objects and uses Map.prototype.has to check for key existence. Fixes #1119.

authored by Chetan Satpute · committed by GitHub · parent 857b4b7 · Browse files · 2 files+7 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−2 removed

  • tests:+2 added−0 removed
  • other:+5 added−2 removed

2 files+7 added−2 removed

modified:__tests__/frozen.js+2 added
145 unmodified lines
146 const base = new Map()147148 const res = produce(base, draft => {149 draft.set("a", 1)150 draft.set("o", {b: 1})151 })152 expect(() => res.set("b", 2)).toThrowErrorMatchingSnapshot()153 expect(() => res.clear()).toThrowErrorMatchingSnapshot()154 expect(() => res.delete("b")).toThrowErrorMatchingSnapshot()155 expect(Object.isFrozen(res.get("o"))).toBe(true)156157 // In draft, still editable158 expect(produce(res, d => void d.set("a", 2))).not.toBe(res)159 })
110 unmodified lines
modified:src/core/finalize.ts+5 added-2 removed