Created
May 2, 2025 12:47
-
-
Save bouk/b793fcad62d075b35b250768cf7bf47f to your computer and use it in GitHub Desktop.
FinalizationRegistry Bug Reproduction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>FinalizationRegistry Bug Reproduction</title> | |
</head> | |
<body> | |
<p>Live Objects: <span id="liveCounter">0</span></p> | |
<p>Created Objects: <span id="createdCounter">0</span></p> | |
<p>Collected Objects: <span id="collectedCounter">0</span></p> | |
<script> | |
let liveObjects = 0 | |
let createdObjects = 0 | |
let collectedObjects = 0 | |
const liveCounter = document.getElementById('liveCounter') | |
const createdCounter = document.getElementById('createdCounter') | |
const collectedCounter = document.getElementById('collectedCounter') | |
const registry = new FinalizationRegistry(() => { | |
liveObjects-- | |
collectedObjects++ | |
}) | |
class TrackableObject { | |
constructor(id) { | |
this.id = id | |
this.data = new Uint8Array(5_000) | |
} | |
} | |
function createObject() { | |
for (let i = 0; i < 20000; i++) { | |
registry.register(new TrackableObject(i)) | |
createdObjects++ | |
liveObjects++ | |
} | |
} | |
setInterval(createObject, 1000 / 60) | |
function updateCounters() { | |
liveCounter.textContent = liveObjects | |
createdCounter.textContent = createdObjects | |
collectedCounter.textContent = collectedObjects | |
requestAnimationFrame(updateCounters) | |
} | |
requestAnimationFrame(updateCounters) | |
setTimeout(() => { | |
if (collectedObjects > 0) { | |
window.location.reload() | |
} | |
}, 3000) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment