1// Flags: --harmony-weak-refs 2'use strict'; 3require('../common'); 4const assert = require('assert'); 5 6// Test that finalization callbacks do not crash when caused through a regular 7// GC (not global.gc()). 8 9const start = Date.now(); 10const g = new globalThis.FinalizationGroup(() => { 11 const diff = Date.now() - start; 12 assert(diff < 10000, `${diff} >= 10000`); 13}); 14g.register({}, 42); 15 16setImmediate(() => { 17 const arr = []; 18 // Build up enough memory usage to hopefully trigger a platform task but not 19 // enough to trigger GC as an interrupt. 20 while (arr.length < 1000000) arr.push([]); 21 22 setTimeout(() => { 23 g; // Keep reference alive. 24 }, 200000).unref(); 25}); 26