tc39 / proposal-mass-proxy-revocation

Proposal for revoking proxies en masse.
MIT License
5 stars 1 forks source link

Interaction with `Proxy.revocable` #25

Open dead-claudia opened 11 months ago

dead-claudia commented 11 months ago

The existing Promise,revocable could be near trivially implemented as follows in the current proposal, ignoring the part about the added symbol:

Proxy.revocable = (target, handler) => {
    const signal = Proxy.createSignal()
    return {
        proxy: new Proxy(target, handler, {signal}),
        revoke() {
            Proxy.finalizeSymbol(signal)
        },
    }
}
ajvincent commented 11 months ago

I think this is unwise, for two reasons.

  1. Proxy.revocable without signals works now.
  2. This proposal pitches adding a third argument for a signal to pass in. So instead of tracking one signal, we'd be tracking potentially two - the external, and the internal.

Sure, you could theoretically. Why would you want to?

dead-claudia commented 11 months ago

@ajvincent I wasn't intending to make a suggestion here. I just wanted to give some visibility on an interesting result, in that the current Proxy.revocable could be almost trivially written in terms of this proposal, and for similar reasons.

Sorry, should've made myself clearer.


Also, the full one with the extra signal parameter can just be done by using a proxy to a proxy, one for each signal:

Proxy.revocable = (target, handler, options) => {
    const signal = Proxy.createSignal()
    return {
        proxy: new Proxy(new Proxy(target, handler, options), {}, {signal}),
        revoke() {
            Proxy.finalizeSymbol(signal)
        },
    }
}