head_devtools.js (1941B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* exported DevToolsUtils, DevToolsLoader */ 5 6 "use strict"; 7 8 const { require, DevToolsLoader } = ChromeUtils.importESModule( 9 "resource://devtools/shared/loader/Loader.sys.mjs" 10 ); 11 const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js"); 12 13 Services.prefs.setBoolPref("devtools.testing", true); 14 registerCleanupFunction(() => { 15 Services.prefs.clearUserPref("devtools.testing"); 16 }); 17 18 // Register a console listener, so console messages don't just disappear 19 // into the ether. 20 21 // If for whatever reason the test needs to post console errors that aren't 22 // failures, set this to true. 23 var ALLOW_CONSOLE_ERRORS = false; 24 25 // XXX This listener is broken, see bug 1456634, for now turn off no-undef here, 26 // this needs turning back on! 27 /* eslint-disable no-undef */ 28 var listener = { 29 observe(message) { 30 let string; 31 try { 32 message.QueryInterface(Ci.nsIScriptError); 33 dump( 34 message.sourceName + 35 ":" + 36 message.lineNumber + 37 ": " + 38 scriptErrorFlagsToKind(message.flags) + 39 ": " + 40 message.errorMessage + 41 "\n" 42 ); 43 string = message.errorMessage; 44 } catch (ex) { 45 // Be a little paranoid with message, as the whole goal here is to lose 46 // no information. 47 try { 48 string = "" + message.message; 49 } catch (e) { 50 string = "<error converting error message to string>"; 51 } 52 } 53 54 // Make sure we exit all nested event loops so that the test can finish. 55 while (DevToolsServer.xpcInspector.eventLoopNestLevel > 0) { 56 DevToolsServer.xpcInspector.exitNestedEventLoop(); 57 } 58 59 if (!ALLOW_CONSOLE_ERRORS) { 60 do_throw("head_devtools.js got console message: " + string + "\n"); 61 } 62 }, 63 }; 64 /* eslint-enable no-undef */ 65 66 Services.console.registerListener(listener);