Implement revocable proxies

RESOLVED DUPLICATE of bug 978279

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 978279
4 years ago
3 years ago

People

(Reporter: David Bruant, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

4 years ago
Initial spec http://wiki.ecmascript.org/doku.php?id=strawman:revokable_proxies (but look at the latest ES6 draft for the most up-to-date version if changes happen).

In a nutshell:
  let { proxy, revoke } = Proxy.revocable(target, handler);
  proxy.foo // traps
  revoke()  // always returns undefined
  proxy.foo // throws TypeError: "proxy is revoked"
Is there anything this lets you do that isn't already possible with Direct Proxies? Or is this just streamlining the revocable proxy pattern with a native API?
(Reporter)

Comment 2

4 years ago
(In reply to Bobby Holley (:bholley) from comment #1)
> Is there anything this lets you do that isn't already possible with Direct
> Proxies?
It enables GC'ing of the target. For the longer explanation, see [1], but in a nutshell, whatever handler semantics is implemented, the proxy always keeps a reference to its target. Revoking the proxy allows to break this reference.
Some handler semantics could mean the same thing, but it'd be hard (undecidable? impossible?) for the JS engine to understand the handler enough to know that the target is collectable even when the proxy is still around.

> Or is this just streamlining the revocable proxy pattern with a native API?
That's just a nice side-effect :-)


[1] https://mail.mozilla.org/pipermail/es-discuss/2012-August/024344.html
Makes sense. This is trivial for us to implement. We should probably just use DeadObjectProxy and updates its throwing semantics to match whatever the ES spec wants.
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 978279
You need to log in before you can comment on or make changes to this bug.