Mass Proxy Revocation
Alexander J. Vincent
ajvincent@gmail.com
Proxy creation takes two arguments.
Shadow
target
Membrane
WeakMap
<html>
Proxy Handler
Proxy Handler
<html> proxy
Background: Membranes combine proxies, maps.
This is fine for individual proxies, but doesn’t scale well.
If you have hundreds of proxies, you have hundreds of revoker functions, or you don’t care about revoking proxies at all.
What is a membrane?
<html>
<head>
<title>Hello</title>
<script src=”hello.js”></script>
</head>
<body>
<p>
<button onclick=”doSomething();”>Hi</button>
</p>
</body>
</html>
function doSomething() {
const button = document.getElementsByTagName(
“button”
)[0];
button.disabled = true;
const p = document.createElement(“p”);
p.appendChild(“Good day!”);
document.body.appendChild(p);
}
Web browsers implement and trust the elements. The elements are “native”, living inside the browser’s trusted code, and are objects.
JavaScript code is foreign to the browser, and the browser treats that code with suspicion.
The browser provides some access to the objects, but it doesn’t dare provide unrestricted access.
A membrane separates “mutually suspicious” object graphs from each other, using proxies to tunnel through.
Membranes interpose between object graphs.
<html>
<body>
<head>
firstChild
lastChild
parentNode
parentNode
firstChild
lastChild
parentNode
parentNode
“Blue”
“Yellow”
Membranes interpose between object graphs.
<html>
Event
listener
<body>
lastChild
lastChild
parentNode
addEventListener()
addEventListener()
“Blue”
“Yellow”
Why are membranes important?
Now, imagine revoking hundreds or thousands of proxies synchronously, with one revoker function for every proxy. That’s where we are right now in membranes.
Membranes: The cell model
“Green”
“Blue”
Membranes: The geometric model
<html>
<html>
<body>
onload
<body>
onload
“Blue”
“Green”
Membranes: The geometric model
<html>
<html>
<body>
onload
<body>
onload
“Blue”
“Green”
Membranes: The geometric model
<html>
<html>
<html>
<body>
onload
<body>
onload
<body>
onload
“Purple”
“Blue”
“Green”
Cleaning up an object graph is why we’re here.
<html>
<html>
<html>
<body>
onload
<body>
onload
<body>
onload
“Purple”
“Blue”
“Green”
Proposal: Add an options argument to proxies.
The options object would initially support one property, a “revocation signal”.
// The finalization registry inspired this API. Names of static methods open to change.
// A symbol, so we can pass it across realms if necessary.
const signal = Proxy.createSignal();
return new Proxy(shadowTarget, proxyHandler, { signal });
// ...
Proxy.finalizeSignal(signal); // kills the proxy.
Proposal: Add an options argument to proxies.
This would mean membranes might not need Proxy.revocable(). So we wouldn’t create so many revokers in the first place.
Cross-cutting concern: Cancellation Proposal
Mass Proxy Revocation
Thank you. Stage 1?
Alexander J. Vincent
ajvincent@gmail.com