1 // Test basic usage of onGarbageCollection
3 const root = newGlobal();
4 const dbg = new Debugger();
5 const wrappedRoot = dbg.addDebuggee(root)
7 const NUM_SLICES = root.NUM_SLICES = 10;
12 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
13 registerCleanupFunction(() => {
14 Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
17 dbg.memory.onGarbageCollection = data => {
20 print("Got onGarbageCollection: " + JSON.stringify(data, null, 2));
22 equal(typeof data.reason, "string");
23 equal(typeof data.nonincrementalReason == "string" || data.nonincrementalReason === null,
26 let lastStartTimestamp = 0;
27 for (let i = 0; i < data.collections.length; i++) {
28 let slice = data.collections[i];
30 equal(slice.startTimestamp >= lastStartTimestamp, true);
31 equal(slice.startTimestamp <= slice.endTimestamp, true);
33 lastStartTimestamp = slice.startTimestamp;
36 equal(data.collections.length >= 1, true);
37 slicesFound += data.collections.length;
48 for (var i = 0; i < NUM_SLICES; i++) {
60 equal(fired, true, "The GC hook should have fired at least once");
62 // NUM_SLICES + 1 full gc + however many were triggered naturally (due to
63 // whatever zealousness setting).
64 print("Found " + slicesFound + " slices");
65 equal(slicesFound >= NUM_SLICES + 1, true);