summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/ast
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /devtools/client/debugger/src/actions/ast
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/actions/ast')
-rw-r--r--devtools/client/debugger/src/actions/ast/index.js5
-rw-r--r--devtools/client/debugger/src/actions/ast/moz.build11
-rw-r--r--devtools/client/debugger/src/actions/ast/setInScopeLines.js98
3 files changed, 114 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/actions/ast/index.js b/devtools/client/debugger/src/actions/ast/index.js
new file mode 100644
index 0000000000..ec2c1ae84c
--- /dev/null
+++ b/devtools/client/debugger/src/actions/ast/index.js
@@ -0,0 +1,5 @@
+/* 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/>. */
+
+export { setInScopeLines } from "./setInScopeLines";
diff --git a/devtools/client/debugger/src/actions/ast/moz.build b/devtools/client/debugger/src/actions/ast/moz.build
new file mode 100644
index 0000000000..5b0152d2ad
--- /dev/null
+++ b/devtools/client/debugger/src/actions/ast/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(
+ "index.js",
+ "setInScopeLines.js",
+)
diff --git a/devtools/client/debugger/src/actions/ast/setInScopeLines.js b/devtools/client/debugger/src/actions/ast/setInScopeLines.js
new file mode 100644
index 0000000000..72bd33b59f
--- /dev/null
+++ b/devtools/client/debugger/src/actions/ast/setInScopeLines.js
@@ -0,0 +1,98 @@
+/* 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 {
+ hasInScopeLines,
+ getSourceTextContent,
+ getVisibleSelectedFrame,
+} from "../../selectors/index";
+
+import { getSourceLineCount } from "../../utils/source";
+
+import { isFulfilled } from "../../utils/async-value";
+
+function getOutOfScopeLines(outOfScopeLocations) {
+ if (!outOfScopeLocations) {
+ return null;
+ }
+
+ const uniqueLines = new Set();
+ for (const location of outOfScopeLocations) {
+ for (let i = location.start.line; i < location.end.line; i++) {
+ uniqueLines.add(i);
+ }
+ }
+
+ return uniqueLines;
+}
+
+async function getInScopeLines(
+ location,
+ sourceTextContent,
+ { dispatch, getState, parserWorker }
+) {
+ let locations = null;
+ if (location.line && parserWorker.isLocationSupported(location)) {
+ locations = await parserWorker.findOutOfScopeLocations(location);
+ }
+
+ const linesOutOfScope = getOutOfScopeLines(locations);
+ const sourceNumLines =
+ !sourceTextContent || !isFulfilled(sourceTextContent)
+ ? 0
+ : getSourceLineCount(sourceTextContent.value);
+
+ const noLinesOutOfScope =
+ linesOutOfScope == null || linesOutOfScope.size == 0;
+
+ // This operation can be very costly for large files so we sacrifice a bit of readability
+ // for performance sake.
+ // We initialize an array with a fixed size and we'll directly assign value for lines
+ // that are not out of scope. This is much faster than having an empty array and pushing
+ // into it.
+ const sourceLines = new Array(sourceNumLines);
+ for (let i = 0; i < sourceNumLines; i++) {
+ const line = i + 1;
+ if (noLinesOutOfScope || !linesOutOfScope.has(line)) {
+ sourceLines[i] = line;
+ }
+ }
+
+ // Finally we need to remove any undefined values, i.e. the ones that were matching
+ // out of scope lines.
+ return sourceLines.filter(i => i != undefined);
+}
+
+export function setInScopeLines() {
+ return async thunkArgs => {
+ const { getState, dispatch } = thunkArgs;
+ const visibleFrame = getVisibleSelectedFrame(getState());
+
+ if (!visibleFrame) {
+ return;
+ }
+
+ const { location } = visibleFrame;
+ const sourceTextContent = getSourceTextContent(getState(), location);
+
+ // Ignore if in scope lines have already be computed, or if the selected location
+ // doesn't have its content already fully fetched.
+ // The ParserWorker will only have the source text content once the source text content is fulfilled.
+ if (
+ hasInScopeLines(getState(), location) ||
+ !sourceTextContent ||
+ !isFulfilled(sourceTextContent)
+ ) {
+ return;
+ }
+
+ const lines = await getInScopeLines(location, sourceTextContent, thunkArgs);
+
+ dispatch({
+ type: "IN_SCOPE_LINES",
+ location,
+ lines,
+ });
+ };
+}