// At controller construction
let massRevoker;
let tracker = { revoked: false };
let controllerPromise = new Promise(resolve => massRevoker = resolve);
controllerPromise = controllerPromise.then(() => tracker.revoked = true);
// At Proxy.revocable(target, handler, controller)
function addRevokerReference(weakRefToRevoker) {
controllerPromise.then(() => {
const revoker = weakRefToRevoker.deref();
if (revoker)
revoker();
});
}
if (controller) {
addRevokerReference(new WeakRef(revoker));
}
We still want to add the third argument, but a shim could implement asynchronous revocation this way.
This approach is notably worse in terms of memory allocation and GC pressure, because it implies each call to Proxy.revoke() attaches a Promise via .then() for each proxy we create. A solution in the JavaScript engine is still preferable.
We still want to add the third argument, but a shim could implement asynchronous revocation this way.
This approach is notably worse in terms of memory allocation and GC pressure, because it implies each call to Proxy.revoke() attaches a Promise via
.then()
for each proxy we create. A solution in the JavaScript engine is still preferable.