test_onGarbageCollection-05.js (1085B)
1 // Test that the onGarbageCollection hook reports its gc cycle's number (aka the 2 // major GC number) and that it is monotonically increasing. 3 4 const root = newGlobal(); 5 const dbg = new Debugger(); 6 const wrappedRoot = dbg.addDebuggee(root) 7 8 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 9 registerCleanupFunction(() => { 10 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 11 }); 12 13 function run_test() { 14 do_test_pending(); 15 16 let numFired = 0; 17 let lastGCCycleNumber = undefined; 18 19 (function loop() { 20 if (numFired == 10) { 21 dbg.memory.onGarbageCollection = undefined; 22 dbg.enabled = false; 23 return void do_test_finished(); 24 } 25 26 dbg.memory.onGarbageCollection = data => { 27 print("onGarbageCollection: " + uneval(data)); 28 29 if (numFired != 0) { 30 equal(typeof lastGCCycleNumber, "number"); 31 equal(data.gcCycleNumber - lastGCCycleNumber, 1); 32 } 33 34 numFired++; 35 lastGCCycleNumber = data.gcCycleNumber; 36 37 executeSoon(loop); 38 }; 39 40 root.eval("gc(this)"); 41 }()); 42 }