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/. */
6 const asyncStoreHelper = require("resource://devtools/client/shared/async-store-helper.js");
7 const { validateBreakpointLocation } = ChromeUtils.importESModule(
8 "resource://devtools/shared/validate-breakpoint.sys.mjs",
9 { global: "contextual" }
12 const asyncStore = asyncStoreHelper("debugger", {
13 pendingBreakpoints: ["pending-breakpoints", {}],
15 xhrBreakpoints: ["xhr-breakpoints", []],
16 eventListenerBreakpoints: ["event-listener-breakpoints", undefined],
17 blackboxedRanges: ["blackboxedRanges", {}],
19 exports.asyncStore = asyncStore;
21 exports.getThreadOptions = async function () {
23 shouldPauseOnDebuggerStatement: Services.prefs.getBoolPref(
24 "devtools.debugger.pause-on-debugger-statement"
26 pauseOnExceptions: Services.prefs.getBoolPref(
27 "devtools.debugger.pause-on-exceptions"
29 ignoreCaughtExceptions: Services.prefs.getBoolPref(
30 "devtools.debugger.ignore-caught-exceptions"
32 shouldIncludeSavedFrames: Services.prefs.getBoolPref(
33 "devtools.debugger.features.async-captured-stacks"
35 shouldIncludeAsyncLiveFrames: Services.prefs.getBoolPref(
36 "devtools.debugger.features.async-live-stacks"
38 skipBreakpoints: Services.prefs.getBoolPref(
39 "devtools.debugger.skip-pausing"
41 logEventBreakpoints: Services.prefs.getBoolPref(
42 "devtools.debugger.log-event-breakpoints"
44 // This option is always true. See Bug 1654590 for removal.
46 breakpoints: sanitizeBreakpoints(await asyncStore.pendingBreakpoints),
47 // XXX: `event-listener-breakpoints` is a copy of the event-listeners state
48 // of the debugger panel. The `active` property is therefore linked to
49 // the `active` property of the state.
50 // See devtools/client/debugger/src/reducers/event-listeners.js
52 ((await asyncStore.eventListenerBreakpoints) || {}).active || [],
57 * Bug 1720512 - We used to store invalid breakpoints, leading to blank debugger.
58 * Filter out only the one that look invalid.
60 function sanitizeBreakpoints(breakpoints) {
61 if (typeof breakpoints != "object") {
64 // We are not doing any assertion against keys,
65 // as it looks like we are never using them anywhere in frontend, nor backend.
66 const validBreakpoints = {};
67 for (const key in breakpoints) {
68 const bp = breakpoints[key];
71 throw new Error("Undefined breakpoint");
73 // Debugger's main.js's `syncBreakpoints` will only use generatedLocation
74 // when restoring breakpoints.
75 validateBreakpointLocation(bp.generatedLocation);
76 // But Toolbox will still pass location to thread actor's reconfigure
77 // for target that don't support watcher+BreakpointListActor
78 validateBreakpointLocation(bp.location);
79 validBreakpoints[key] = bp;
82 "Ignore invalid breakpoint from debugger store",
88 return validBreakpoints;
90 exports.sanitizeBreakpoints = sanitizeBreakpoints;