Closed Bug 934223 Opened 11 years ago Closed 10 years ago

Implement revocable proxies

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 978279

People

(Reporter: bruant.d, Unassigned)

References

Details

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?
(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
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.