Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / devtools / client / shared / thread-utils.js
blob7f3aa4a8ac54fadbd4d1952cb9bdf6c85efaec6f
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 "use strict";
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", {}],
14   tabs: ["tabs", []],
15   xhrBreakpoints: ["xhr-breakpoints", []],
16   eventListenerBreakpoints: ["event-listener-breakpoints", undefined],
17   blackboxedRanges: ["blackboxedRanges", {}],
18 });
19 exports.asyncStore = asyncStore;
21 exports.getThreadOptions = async function () {
22   return {
23     shouldPauseOnDebuggerStatement: Services.prefs.getBoolPref(
24       "devtools.debugger.pause-on-debugger-statement"
25     ),
26     pauseOnExceptions: Services.prefs.getBoolPref(
27       "devtools.debugger.pause-on-exceptions"
28     ),
29     ignoreCaughtExceptions: Services.prefs.getBoolPref(
30       "devtools.debugger.ignore-caught-exceptions"
31     ),
32     shouldIncludeSavedFrames: Services.prefs.getBoolPref(
33       "devtools.debugger.features.async-captured-stacks"
34     ),
35     shouldIncludeAsyncLiveFrames: Services.prefs.getBoolPref(
36       "devtools.debugger.features.async-live-stacks"
37     ),
38     skipBreakpoints: Services.prefs.getBoolPref(
39       "devtools.debugger.skip-pausing"
40     ),
41     logEventBreakpoints: Services.prefs.getBoolPref(
42       "devtools.debugger.log-event-breakpoints"
43     ),
44     // This option is always true. See Bug 1654590 for removal.
45     observeAsmJS: true,
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
51     eventBreakpoints:
52       ((await asyncStore.eventListenerBreakpoints) || {}).active || [],
53   };
56 /**
57  * Bug 1720512 - We used to store invalid breakpoints, leading to blank debugger.
58  * Filter out only the one that look invalid.
59  */
60 function sanitizeBreakpoints(breakpoints) {
61   if (typeof breakpoints != "object") {
62     return {};
63   }
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];
69     try {
70       if (!bp) {
71         throw new Error("Undefined breakpoint");
72       }
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;
80     } catch (e) {
81       console.error(
82         "Ignore invalid breakpoint from debugger store",
83         bp,
84         e.message
85       );
86     }
87   }
88   return validBreakpoints;
90 exports.sanitizeBreakpoints = sanitizeBreakpoints;