change "harden" to share a WeakMap of already-frozen objects
See original GitHub issueOur current def()
function currently does too much work: it doesn’t remember what’s been frozen already, so it will re-freeze things like Function.prototype every time. To fix this, deepFreeze() needs to be turned into a “Freezer” object that retains a WeakMap of everything it has ever frozen, def() should take a Freezer, and the def() exposed as a global should close over the Freezer and deliver it here. deepFreezePrimordials() should use that same Freezer
This isn’t a security issue, merely a performance one.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
WeakMap - JavaScript - MDN Web Docs
A WeakMap is a collection of key/value pairs whose keys must be objects, with values of any arbitrary JavaScript type, and which does...
Read more >WeakMap and WeakSet - The Modern JavaScript Tutorial
We put the data to a WeakMap , using the object as the key, and when the ... If we replace Map with...
Read more >Do we change states when setting new values in weakmaps?
To answer your question about WeakMaps, I think you are talking about side effects. When using a WeakMap you can imagine that there...
Read more >WeakMap and WeakSet: Understanding JavaScript weak ...
Learn about weak references in JavaScript and how we can use them by utilizing the WeakMap and WeakSet objects.
Read more >tc39/proposal-symbols-as-weakmap-keys - GitHub
Easy to create and share keys. Instead of requiring creating a new object to be only used as a key, a symbol would...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Noting again here that we’re likely to change terminology from “deeply frozen” and such to “hardened”.
No, because
Object.isFrozen
is not transitive. Ifdef
stopped at a frozen object, it could miss non-frozen objects that were reachable from named properties of that frozen object:If the call to
def
succeeds, then the transitive API surface starting atbad
must be frozen. But anisFrozen
check would stop too early.