diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/shared/flags.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/flags.js')
-rw-r--r-- | devtools/shared/flags.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/devtools/shared/flags.js b/devtools/shared/flags.js new file mode 100644 index 0000000000..1b0ec26472 --- /dev/null +++ b/devtools/shared/flags.js @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +/** + * This module controls various global flags that can be toggled on and off. + * These flags are generally used to change the behavior of the code during + * testing. They are tracked by preferences so that they are propagated + * between the parent and content processes. The flags are exposed via a module + * as a conveniene and to stop from littering preference names throughout the + * code ase. + * + * Each of the flags is documented where it is defined. + */ + +/** + * We cannot make a normal property writeable on `exports` because + * the module system freezes it. This function observes a preference + * and provides the latest value through a getter. + */ +function makePrefTrackedFlag(exports, name, pref) { + let flag; + // We don't have access to pref in worker, so disable all logs by default + if (isWorker) { + flag = false; + } else { + flag = Services.prefs.getBoolPref(pref, false); + const prefObserver = () => { + flag = Services.prefs.getBoolPref(pref, false); + }; + Services.prefs.addObserver(pref, prefObserver); + + // Also listen for Loader unload to unregister the pref observer and prevent leaking + const unloadObserver = function (subject) { + if (subject.wrappedJSObject == require("@loader/unload")) { + Services.prefs.removeObserver(pref, prefObserver); + Services.obs.removeObserver(unloadObserver, "devtools:loader:destroy"); + } + }; + Services.obs.addObserver(unloadObserver, "devtools:loader:destroy"); + } + Object.defineProperty(exports, name, { + get() { + return flag; + }, + }); +} + +/** + * Setting the "devtools.debugger.log" preference to true will enable logging of + * the RDP calls to the devtools server. + */ +makePrefTrackedFlag(exports, "wantLogging", "devtools.debugger.log"); + +/** + * Setting the "devtools.debugger.log.verbose" preference to true will enable a + * more verbose logging of the the RDP. The "devtools.debugger.log" preference + * must be set to true as well for this to have any effect. + */ +makePrefTrackedFlag(exports, "wantVerbose", "devtools.debugger.log.verbose"); + +/** + * Setting the "devtools.testing" preference to true will toggle on certain + * behaviors that can differ from the production version of the code. These + * behaviors typically enable easier testing or enhanced debugging features. + */ +makePrefTrackedFlag(exports, "testing", "devtools.testing"); |