summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/reducers/breakpoints.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/client/debugger/src/reducers/breakpoints.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/reducers/breakpoints.js')
-rw-r--r--devtools/client/debugger/src/reducers/breakpoints.js154
1 files changed, 154 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/reducers/breakpoints.js b/devtools/client/debugger/src/reducers/breakpoints.js
new file mode 100644
index 0000000000..46ca083d16
--- /dev/null
+++ b/devtools/client/debugger/src/reducers/breakpoints.js
@@ -0,0 +1,154 @@
+/* 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/>. */
+
+/**
+ * Breakpoints reducer
+ * @module reducers/breakpoints
+ */
+
+import { makeBreakpointId } from "../utils/breakpoint";
+
+export function initialBreakpointsState(xhrBreakpoints = []) {
+ return {
+ breakpoints: {},
+ xhrBreakpoints,
+ breakpointsDisabled: false,
+ };
+}
+
+function update(state = initialBreakpointsState(), action) {
+ switch (action.type) {
+ case "SET_BREAKPOINT": {
+ if (action.status === "start") {
+ return setBreakpoint(state, action);
+ }
+ return state;
+ }
+
+ case "REMOVE_BREAKPOINT": {
+ if (action.status === "start") {
+ return removeBreakpoint(state, action);
+ }
+ return state;
+ }
+
+ case "CLEAR_BREAKPOINTS": {
+ return { ...state, breakpoints: {} };
+ }
+
+ case "NAVIGATE": {
+ return initialBreakpointsState(state.xhrBreakpoints);
+ }
+
+ case "REMOVE_THREAD": {
+ return removeBreakpointsForThread(state, action.threadActorID);
+ }
+
+ case "SET_XHR_BREAKPOINT": {
+ return addXHRBreakpoint(state, action);
+ }
+
+ case "REMOVE_XHR_BREAKPOINT": {
+ return removeXHRBreakpoint(state, action);
+ }
+
+ case "UPDATE_XHR_BREAKPOINT": {
+ return updateXHRBreakpoint(state, action);
+ }
+
+ case "ENABLE_XHR_BREAKPOINT": {
+ return updateXHRBreakpoint(state, action);
+ }
+
+ case "DISABLE_XHR_BREAKPOINT": {
+ return updateXHRBreakpoint(state, action);
+ }
+ case "CLEAR_XHR_BREAKPOINTS": {
+ if (action.status == "start") {
+ return state;
+ }
+ return { ...state, xhrBreakpoints: [] };
+ }
+ }
+
+ return state;
+}
+
+function addXHRBreakpoint(state, action) {
+ const { xhrBreakpoints } = state;
+ const { breakpoint } = action;
+ const { path, method } = breakpoint;
+
+ const existingBreakpointIndex = state.xhrBreakpoints.findIndex(
+ bp => bp.path === path && bp.method === method
+ );
+
+ if (existingBreakpointIndex === -1) {
+ return {
+ ...state,
+ xhrBreakpoints: [...xhrBreakpoints, breakpoint],
+ };
+ } else if (xhrBreakpoints[existingBreakpointIndex] !== breakpoint) {
+ const newXhrBreakpoints = [...xhrBreakpoints];
+ newXhrBreakpoints[existingBreakpointIndex] = breakpoint;
+ return {
+ ...state,
+ xhrBreakpoints: newXhrBreakpoints,
+ };
+ }
+
+ return state;
+}
+
+function removeXHRBreakpoint(state, action) {
+ const { breakpoint } = action;
+ const { xhrBreakpoints } = state;
+
+ if (action.status === "start") {
+ return state;
+ }
+
+ return {
+ ...state,
+ xhrBreakpoints: xhrBreakpoints.filter(
+ bp => bp.path !== breakpoint.path || bp.method !== breakpoint.method
+ ),
+ };
+}
+
+function updateXHRBreakpoint(state, action) {
+ const { breakpoint, index } = action;
+ const { xhrBreakpoints } = state;
+ const newXhrBreakpoints = [...xhrBreakpoints];
+ newXhrBreakpoints[index] = breakpoint;
+ return {
+ ...state,
+ xhrBreakpoints: newXhrBreakpoints,
+ };
+}
+
+function setBreakpoint(state, { breakpoint }) {
+ const id = makeBreakpointId(breakpoint.location);
+ const breakpoints = { ...state.breakpoints, [id]: breakpoint };
+ return { ...state, breakpoints };
+}
+
+function removeBreakpoint(state, { breakpoint }) {
+ const id = makeBreakpointId(breakpoint.location);
+ const breakpoints = { ...state.breakpoints };
+ delete breakpoints[id];
+ return { ...state, breakpoints };
+}
+
+function removeBreakpointsForThread(state, threadActorID) {
+ const remainingBreakpoints = {};
+ for (const [id, breakpoint] of Object.entries(state.breakpoints)) {
+ if (breakpoint.thread !== threadActorID) {
+ remainingBreakpoints[id] = breakpoint;
+ }
+ }
+ return { ...state, breakpoints: remainingBreakpoints };
+}
+
+export default update;