C. Scott Ananian (2015-04-30T16:52:00.000Z)
d at domenic.me (2015-05-11T16:54:57.515Z)
On Mon, Feb 23, 2015 at 3:31 PM, Mark S. Miller <erights at google.com> wrote: > Object.freeze does not freeze their state. A proposal for a way to either > freeze the state of collections, and/or to create frozen snapshots of > collections, for future ES would be welcome and appreciated. I encourage > any such effort to pay attention to Clojure and React. I ran into this today. As a strawman proposal: Add "If TestIntegrityLevel(M, "frozen") is true, throw a TypeError exception" between steps 3 and 4 of 23.1.3.1 (Map.prototype.clear), 23.1.3.3 (Map.prototype.delete), 23.1.3.9 (Map.prototype.set), 23.2.3.1 (Set.prototype.add), 23.2.3.2 (Set.prototype.clear), and 23.2.3.4 (Set.prototype.delete). This wouldn't be some fancy all-singing all-dancing collection snapshot, and would still leave the user responsible for freezing the prototype, etc, but it would bring Map and Set back into parity with object (that is, m.get(f) behaves for the most part like o[f]). Users would still have to special-case Map/Set when they implement their own deepFreeze() methods, etc, but this ensures that the internal list is actually protected. It is (AFAICT) otherwise impossible in ES6 to maintain object identity when "freezing" an collection.