head.js (1044B)
1 "use strict"; 2 3 const { addDebuggerToGlobal } = ChromeUtils.importESModule( 4 "resource://gre/modules/jsdebugger.sys.mjs" 5 ); 6 7 const SYSTEM_PRINCIPAL = Cc["@mozilla.org/systemprincipal;1"].createInstance( 8 Ci.nsIPrincipal 9 ); 10 11 function addTestingFunctionsToGlobal(global) { 12 global.eval( 13 ` 14 const testingFunctions = Cu.getJSTestingFunctions(); 15 for (let k in testingFunctions) { 16 17 this[k] = testingFunctions[k]; 18 } 19 ` 20 ); 21 if (!global.print) { 22 global.print = info; 23 } 24 if (!global.newGlobal) { 25 global.newGlobal = newGlobal; 26 } 27 if (!global.Debugger) { 28 addDebuggerToGlobal(global); 29 } 30 } 31 32 addTestingFunctionsToGlobal(this); 33 34 /* Create a new global, with all the JS shell testing functions. Similar to the 35 * newGlobal function exposed to JS shells, and useful for porting JS shell 36 * tests to xpcshell tests. 37 */ 38 function newGlobal(args) { 39 const global = new Cu.Sandbox(SYSTEM_PRINCIPAL, { 40 freshCompartment: true, 41 ...args, 42 }); 43 addTestingFunctionsToGlobal(global); 44 return global; 45 }