bug1664463.js (837B)
1 // |jit-test| skip-if: !('gc' in this) || !('drainJobQueue' in this) 2 // Test that an unused local in an async function is not kept alive by a closure 3 // (bug 1412202). Based on a test case by Andy Wingo in bug 1664463. 4 5 let nfinalized = 0; 6 let finalizers = new FinalizationRegistry(f => { nfinalized++; }); 7 8 class A { 9 constructor(callback) { 10 this.b = {callback}; 11 finalizers.register(this, this.b, this); 12 } 13 } 14 15 const LOOP_COUNT = 200; 16 const FINALIZER_COUNT = 200; 17 18 async function main() { 19 for (let j = 0; j < LOOP_COUNT; j++) { 20 for (let i = 0; i < FINALIZER_COUNT; i++) { 21 let console = globalThis.console; 22 let obj = new A(() => console.log("hello")); 23 } 24 drainJobQueue(); 25 } 26 27 gc(); 28 drainJobQueue(); 29 assertEq(nfinalized, LOOP_COUNT * FINALIZER_COUNT, "all objects should be finalized"); 30 } 31 main();