summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/breakpoint
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/utils/breakpoint
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 '')
-rw-r--r--devtools/client/debugger/src/utils/breakpoint/breakpointPositions.js20
-rw-r--r--devtools/client/debugger/src/utils/breakpoint/index.js72
-rw-r--r--devtools/client/debugger/src/utils/breakpoint/moz.build11
-rw-r--r--devtools/client/debugger/src/utils/breakpoint/tests/index.spec.js28
4 files changed, 131 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/utils/breakpoint/breakpointPositions.js b/devtools/client/debugger/src/utils/breakpoint/breakpointPositions.js
new file mode 100644
index 0000000000..49b8523284
--- /dev/null
+++ b/devtools/client/debugger/src/utils/breakpoint/breakpointPositions.js
@@ -0,0 +1,20 @@
+/* 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 { comparePosition } from "../location";
+import { getSelectedLocation } from "../selected-location";
+
+export function findPosition(positions, location) {
+ if (!positions) {
+ return null;
+ }
+
+ const lineBps = positions[location.line];
+ if (!lineBps) {
+ return null;
+ }
+ return lineBps.find(pos =>
+ comparePosition(getSelectedLocation(pos, location), location)
+ );
+}
diff --git a/devtools/client/debugger/src/utils/breakpoint/index.js b/devtools/client/debugger/src/utils/breakpoint/index.js
new file mode 100644
index 0000000000..5b0ce06533
--- /dev/null
+++ b/devtools/client/debugger/src/utils/breakpoint/index.js
@@ -0,0 +1,72 @@
+/* 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 { getSourceActorsForSource } from "../../selectors";
+import { isGenerated } from "../source";
+import { sortSelectedLocations } from "../location";
+export * from "./breakpointPositions";
+
+// The ID for a Breakpoint is derived from its location in its Source.
+export function makeBreakpointId(location) {
+ const { sourceId, line, column } = location;
+ const columnString = column || "";
+ return `${sourceId}:${line}:${columnString}`;
+}
+
+export function makeBreakpointServerLocationId(breakpointServerLocation) {
+ const { sourceUrl, sourceId, line, column } = breakpointServerLocation;
+ const sourceUrlOrId = sourceUrl || sourceId;
+ const columnString = column || "";
+
+ return `${sourceUrlOrId}:${line}:${columnString}`;
+}
+
+/**
+ * Create a location object to set a breakpoint on the server.
+ *
+ * Debugger location objects includes a source and sourceActor attributes
+ * whereas the server don't need them and instead only need either
+ * the source URL -or- a precise source actor ID.
+ */
+export function makeBreakpointServerLocation(state, location) {
+ const source = location.source;
+ if (!source) {
+ throw new Error("Missing 'source' attribute on location object");
+ }
+ const breakpointLocation = {
+ line: location.line,
+ column: location.column,
+ };
+ if (source.url) {
+ breakpointLocation.sourceUrl = source.url;
+ } else {
+ breakpointLocation.sourceId = getSourceActorsForSource(
+ state,
+ source.id
+ )[0].id;
+ }
+ return breakpointLocation;
+}
+
+export function createXHRBreakpoint(path, method, overrides = {}) {
+ const properties = {
+ path,
+ method,
+ disabled: false,
+ loading: false,
+ text: L10N.getFormatStr("xhrBreakpoints.item.label", path),
+ };
+
+ return { ...properties, ...overrides };
+}
+
+export function getSelectedText(breakpoint, selectedSource) {
+ return !!selectedSource && isGenerated(selectedSource)
+ ? breakpoint.text
+ : breakpoint.originalText;
+}
+
+export function sortSelectedBreakpoints(breakpoints, selectedSource) {
+ return sortSelectedLocations(breakpoints, selectedSource);
+}
diff --git a/devtools/client/debugger/src/utils/breakpoint/moz.build b/devtools/client/debugger/src/utils/breakpoint/moz.build
new file mode 100644
index 0000000000..02c5302a6c
--- /dev/null
+++ b/devtools/client/debugger/src/utils/breakpoint/moz.build
@@ -0,0 +1,11 @@
+# vim: set filetype=python:
+# 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/.
+
+DIRS += []
+
+CompiledModules(
+ "breakpointPositions.js",
+ "index.js",
+)
diff --git a/devtools/client/debugger/src/utils/breakpoint/tests/index.spec.js b/devtools/client/debugger/src/utils/breakpoint/tests/index.spec.js
new file mode 100644
index 0000000000..7ff0a1e75c
--- /dev/null
+++ b/devtools/client/debugger/src/utils/breakpoint/tests/index.spec.js
@@ -0,0 +1,28 @@
+/* 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 { sortSelectedBreakpoints } from "../index";
+
+import { makeMockBreakpoint, makeMockSource } from "../../test-mockup";
+
+describe("breakpoint sorting", () => {
+ it("sortSelectedBreakpoints should sort by line number and column ", () => {
+ const sorted = sortSelectedBreakpoints(
+ [
+ makeMockBreakpoint(undefined, 100, 2),
+ makeMockBreakpoint(undefined, 9, 2),
+ makeMockBreakpoint(undefined, 2),
+ makeMockBreakpoint(undefined, 2, 7),
+ ],
+ makeMockSource()
+ );
+
+ expect(sorted[0].location.line).toBe(2);
+ expect(sorted[0].location.column).toBe(undefined);
+ expect(sorted[1].location.line).toBe(2);
+ expect(sorted[1].location.column).toBe(7);
+ expect(sorted[2].location.line).toBe(9);
+ expect(sorted[3].location.line).toBe(100);
+ });
+});