Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / shared / flags.js
blob1b0ec2647299a07c22656c9a5cbd1e567025a43b
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/. */
5 "use strict";
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.
15 * Each of the flags is documented where it is defined.
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.
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);
33 Services.prefs.addObserver(pref, prefObserver);
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");
42 Services.obs.addObserver(unloadObserver, "devtools:loader:destroy");
44 Object.defineProperty(exports, name, {
45 get() {
46 return flag;
48 });
51 /**
52 * Setting the "devtools.debugger.log" preference to true will enable logging of
53 * the RDP calls to the devtools server.
55 makePrefTrackedFlag(exports, "wantLogging", "devtools.debugger.log");
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.
62 makePrefTrackedFlag(exports, "wantVerbose", "devtools.debugger.log.verbose");
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.
69 makePrefTrackedFlag(exports, "testing", "devtools.testing");