summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/main.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/debugger/src/main.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/main.js')
-rw-r--r--devtools/client/debugger/src/main.js137
1 files changed, 137 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/main.js b/devtools/client/debugger/src/main.js
new file mode 100644
index 0000000000..ee6313a689
--- /dev/null
+++ b/devtools/client/debugger/src/main.js
@@ -0,0 +1,137 @@
+/* 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/>. */
+
+import * as firefox from "./client/firefox";
+
+import { asyncStore, verifyPrefSchema, prefs } from "./utils/prefs";
+import { setupHelper } from "./utils/dbg";
+import { setToolboxTelemetry } from "./utils/telemetry";
+
+import {
+ bootstrapApp,
+ bootstrapStore,
+ bootstrapWorkers,
+ unmountRoot,
+ teardownWorkers,
+} from "./utils/bootstrap";
+
+import { initialBreakpointsState } from "./reducers/breakpoints";
+import { initialSourcesState } from "./reducers/sources";
+import { initialUIState } from "./reducers/ui";
+import { initialSourceBlackBoxState } from "./reducers/source-blackbox";
+
+const { sanitizeBreakpoints } = require("devtools/client/shared/thread-utils");
+
+async function syncBreakpoints() {
+ const breakpoints = await asyncStore.pendingBreakpoints;
+ const breakpointValues = Object.values(sanitizeBreakpoints(breakpoints));
+ return Promise.all(
+ breakpointValues.map(({ disabled, options, generatedLocation }) => {
+ if (disabled) {
+ return Promise.resolve();
+ }
+ // Set the breakpoint on the server using the generated location as generated
+ // sources are known on server, not original sources.
+ return firefox.clientCommands.setBreakpoint(generatedLocation, options);
+ })
+ );
+}
+
+async function syncXHRBreakpoints() {
+ const breakpoints = await asyncStore.xhrBreakpoints;
+ return Promise.all(
+ breakpoints.map(({ path, method, disabled }) => {
+ if (!disabled) {
+ firefox.clientCommands.setXHRBreakpoint(path, method);
+ }
+ })
+ );
+}
+
+function setPauseOnExceptions() {
+ const { pauseOnExceptions, pauseOnCaughtException } = prefs;
+ return firefox.clientCommands.pauseOnExceptions(
+ pauseOnExceptions,
+ pauseOnCaughtException
+ );
+}
+
+async function loadInitialState(commands, toolbox) {
+ const pendingBreakpoints = sanitizeBreakpoints(
+ await asyncStore.pendingBreakpoints
+ );
+ const tabs = { tabs: await asyncStore.tabs };
+ const xhrBreakpoints = await asyncStore.xhrBreakpoints;
+ const blackboxedRanges = await asyncStore.blackboxedRanges;
+ const eventListenerBreakpoints = await asyncStore.eventListenerBreakpoints;
+ const breakpoints = initialBreakpointsState(xhrBreakpoints);
+ const sourceBlackBox = initialSourceBlackBoxState({ blackboxedRanges });
+ const sources = initialSourcesState();
+ const ui = initialUIState();
+
+ return {
+ pendingBreakpoints,
+ tabs,
+ breakpoints,
+ eventListenerBreakpoints,
+ sources,
+ sourceBlackBox,
+ ui,
+ };
+}
+
+export async function bootstrap({
+ commands,
+ fluentBundles,
+ resourceCommand,
+ workers: panelWorkers,
+ panel,
+}) {
+ verifyPrefSchema();
+
+ const initialState = await loadInitialState(commands, panel.toolbox);
+ const workers = bootstrapWorkers(panelWorkers);
+
+ const { store, actions, selectors } = bootstrapStore(
+ firefox.clientCommands,
+ workers,
+ panel,
+ initialState
+ );
+
+ const connected = firefox.onConnect(
+ commands,
+ resourceCommand,
+ actions,
+ store
+ );
+
+ await syncBreakpoints();
+ await syncXHRBreakpoints();
+ await setPauseOnExceptions();
+
+ setupHelper({
+ store,
+ actions,
+ selectors,
+ workers,
+ targetCommand: commands.targetCommand,
+ client: firefox.clientCommands,
+ });
+
+ setToolboxTelemetry(panel.toolbox.telemetry);
+
+ bootstrapApp(store, panel.getToolboxStore(), {
+ fluentBundles,
+ toolboxDoc: panel.panelWin.parent.document,
+ });
+ await connected;
+ return { store, actions, selectors, client: firefox.clientCommands };
+}
+
+export async function destroy() {
+ firefox.onDisconnect();
+ unmountRoot();
+ teardownWorkers();
+}