Skip to content

Documenting limitations (frozen and sealed objects, values that outlive the WeakMap) #4

Closed
@pygy

Description

@pygy

The approach taken by this lib is pretty good, since the GC lifetime of values is tied to that of keys, however, it has a few limitations that may be worth documenting:

  1. The lib doesn't work with frozen and sealed objects.
  2. The values held by a WeakMap can't be collected once the map itself is GCed, since the values here are tied to the keys.

A third thing, which is more of a suggestion:

Even if they are not enumerable, the keys can be obtained in some IE versions by using Object.getOwnPropertyNames. This could be mitigated relatively cheaply by storing the mapping inside a single object that is tied to the key object using a secret field as a value. You can then monkeypatch Object.getOwnPropertyNames to strip that secret field from the results and, also monkeypatch Object.getOwnPropertyNames if present (in IE thanks to a polyfill, not sure about other envs).

If this monkeypatch approach seems workable to you, you could also solve 1) by monkeypatching Object.freeze and Object.seal to add the secret field before freezing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions