head_ongc.js (1048B)
1 var {addDebuggerToGlobal, addSandboxedDebuggerToGlobal} = ChromeUtils.importESModule("resource://gre/modules/jsdebugger.sys.mjs"); 2 3 const testingFunctions = Cu.getJSTestingFunctions(); 4 const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal); 5 6 function addTestingFunctionsToGlobal(global) { 7 for (let k in testingFunctions) { 8 global[k] = testingFunctions[k]; 9 } 10 global.print = info; 11 global.newGlobal = newGlobal; 12 addDebuggerToGlobal(global); 13 } 14 15 function newGlobal() { 16 const global = new Cu.Sandbox(systemPrincipal, { freshZone: true }); 17 addTestingFunctionsToGlobal(global); 18 return global; 19 } 20 21 addTestingFunctionsToGlobal(this); 22 23 function executeSoon(f) { 24 Services.tm.dispatchToMainThread({ run: f }); 25 } 26 27 // The onGarbageCollection tests don't play well gczeal settings and lead to 28 // intermittents. 29 if (typeof gczeal == "function") { 30 gczeal(0); 31 } 32 33 // Make sure to GC before we start the test, so that no zones are scheduled for 34 // GC before we start testing onGarbageCollection hooks. 35 gc();