question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change "harden" to share a WeakMap of already-frozen objects

See original GitHub issue

Our 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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
erightscommented, Jan 13, 2019

Noting again here that we’re likely to change terminology from “deeply frozen” and such to “hardened”.

1reaction
erightscommented, Jan 5, 2019

No, because Object.isFrozen is not transitive. If def stopped at a frozen object, it could miss non-frozen objects that were reachable from named properties of that frozen object:

const bad = Object.freeze([{}]);
// At this point, we have a frozen array containing 
// a non-frozen object in its transitive API surface.
def(bad);

If the call to def succeeds, then the transitive API surface starting at bad must be frozen. But an isFrozen check would stop too early.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found