test_nativewrappers.js (1207B)
1 /* eslint-disable strict */ 2 function run_test() { 3 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true); 4 registerCleanupFunction(() => { 5 Services.prefs.clearUserPref("security.allow_eval_with_system_principal"); 6 }); 7 const { addDebuggerToGlobal } = ChromeUtils.importESModule( 8 "resource://gre/modules/jsdebugger.sys.mjs" 9 ); 10 addDebuggerToGlobal(globalThis); 11 12 const dbg = makeDebugger({ 13 shouldAddNewGlobalAsDebuggee() { 14 return true; 15 }, 16 }); 17 const g = createTestGlobal("test1"); 18 dbg.addDebuggee(g); 19 dbg.onDebuggerStatement = function (frame) { 20 const args = frame.arguments; 21 try { 22 args[0]; 23 Assert.ok(true); 24 } catch (ex) { 25 Assert.ok(false); 26 } 27 }; 28 29 g.eval("function stopMe(arg) {debugger;}"); 30 31 const g2 = createTestGlobal("test2"); 32 g2.g = g; 33 // Not using the "stringify a function" trick because that runs afoul of the 34 // Cu.importGlobalProperties lint and we don't need it here anyway. 35 g2.eval(`(function createBadEvent() { 36 let parser = new DOMParser(); 37 let doc = parser.parseFromString("<foo></foo>", "text/xml"); 38 g.stopMe(doc.createEvent("MouseEvent")); 39 } )()`); 40 41 dbg.disable(); 42 }