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/. */
7 const Services = require("Services");
10 * This module controls various global flags that can be toggled on and off.
11 * These flags are generally used to change the behavior of the code during
12 * testing. They are tracked by preferences so that they are propagated
13 * between the parent and content processes. The flags are exposed via a module
14 * as a conveniene and to stop from littering preference names throughout the
17 * Each of the flags is documented where it is defined.
21 * We cannot make a normal property writeable on `exports` because
22 * the module system freezes it. This function observes a preference
23 * and provides the latest value through a getter.
25 function makePrefTrackedFlag(exports, name, pref) {
27 // We don't have access to pref in worker, so disable all logs by default
31 flag = Services.prefs.getBoolPref(pref, false);
32 const prefObserver = () => {
33 flag = Services.prefs.getBoolPref(pref, false);
35 Services.prefs.addObserver(pref, prefObserver);
37 // Also listen for Loader unload to unregister the pref observer and prevent leaking
38 const unloadObserver = function(subject) {
39 if (subject.wrappedJSObject == require("@loader/unload")) {
40 Services.prefs.removeObserver(pref, prefObserver);
41 Services.obs.removeObserver(unloadObserver, "devtools:loader:destroy");
44 Services.obs.addObserver(unloadObserver, "devtools:loader:destroy");
46 Object.defineProperty(exports, name, {
54 * Setting the "devtools.debugger.log" preference to true will enable logging of
55 * the RDP calls to the devtools server.
57 makePrefTrackedFlag(exports, "wantLogging", "devtools.debugger.log");
60 * Setting the "devtools.debugger.log.verbose" preference to true will enable a
61 * more verbose logging of the the RDP. The "devtools.debugger.log" preference
62 * must be set to true as well for this to have any effect.
64 makePrefTrackedFlag(exports, "wantVerbose", "devtools.debugger.log.verbose");
67 * Setting the "devtools.testing" preference to true will toggle on certain
68 * behaviors that can differ from the production version of the code. These
69 * behaviors typically enable easier testing or enhanced debugging features.
71 makePrefTrackedFlag(exports, "testing", "devtools.testing");