flags.js (2593B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /** 8 * This module controls various global flags that can be toggled on and off. 9 * These flags are generally used to change the behavior of the code during 10 * testing. They are tracked by preferences so that they are propagated 11 * between the parent and content processes. The flags are exposed via a module 12 * as a conveniene and to stop from littering preference names throughout the 13 * code ase. 14 * 15 * Each of the flags is documented where it is defined. 16 */ 17 18 /** 19 * We cannot make a normal property writeable on `exports` because 20 * the module system freezes it. This function observes a preference 21 * and provides the latest value through a getter. 22 */ 23 function makePrefTrackedFlag(exports, name, pref) { 24 let flag; 25 // We don't have access to pref in worker, so disable all logs by default 26 if (isWorker) { 27 flag = false; 28 } else { 29 flag = Services.prefs.getBoolPref(pref, false); 30 const prefObserver = () => { 31 flag = Services.prefs.getBoolPref(pref, false); 32 }; 33 Services.prefs.addObserver(pref, prefObserver); 34 35 // Also listen for Loader unload to unregister the pref observer and prevent leaking 36 const unloadObserver = function (subject) { 37 if (subject.wrappedJSObject == require("@loader/unload")) { 38 Services.prefs.removeObserver(pref, prefObserver); 39 Services.obs.removeObserver(unloadObserver, "devtools:loader:destroy"); 40 } 41 }; 42 Services.obs.addObserver(unloadObserver, "devtools:loader:destroy"); 43 } 44 Object.defineProperty(exports, name, { 45 get() { 46 return flag; 47 }, 48 }); 49 } 50 51 /** 52 * Setting the "devtools.debugger.log" preference to true will enable logging of 53 * the RDP calls to the devtools server. 54 */ 55 makePrefTrackedFlag(exports, "wantLogging", "devtools.debugger.log"); 56 57 /** 58 * Setting the "devtools.debugger.log.verbose" preference to true will enable a 59 * more verbose logging of the the RDP. The "devtools.debugger.log" preference 60 * must be set to true as well for this to have any effect. 61 */ 62 makePrefTrackedFlag(exports, "wantVerbose", "devtools.debugger.log.verbose"); 63 64 /** 65 * Setting the "devtools.testing" preference to true will toggle on certain 66 * behaviors that can differ from the production version of the code. These 67 * behaviors typically enable easier testing or enhanced debugging features. 68 */ 69 makePrefTrackedFlag(exports, "testing", "devtools.testing");