summaryrefslogtreecommitdiffstats
path: root/devtools/server/actors/blackboxing.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/server/actors/blackboxing.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/blackboxing.js')
-rw-r--r--devtools/server/actors/blackboxing.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/devtools/server/actors/blackboxing.js b/devtools/server/actors/blackboxing.js
new file mode 100644
index 0000000000..a206f94cdd
--- /dev/null
+++ b/devtools/server/actors/blackboxing.js
@@ -0,0 +1,90 @@
+/* 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/. */
+
+"use strict";
+
+const { Actor } = require("resource://devtools/shared/protocol.js");
+const {
+ blackboxingSpec,
+} = require("resource://devtools/shared/specs/blackboxing.js");
+
+const {
+ SessionDataHelpers,
+} = require("resource://devtools/server/actors/watcher/SessionDataHelpers.jsm");
+const { SUPPORTED_DATA } = SessionDataHelpers;
+const { BLACKBOXING } = SUPPORTED_DATA;
+
+/**
+ * This actor manages the blackboxing of sources.
+ *
+ * Blackboxing data should be available as early as possible to new targets and
+ * will be forwarded to the WatcherActor to populate the shared session data available to
+ * all DevTools targets.
+ *
+ * @constructor
+ *
+ */
+class BlackboxingActor extends Actor {
+ constructor(watcherActor) {
+ super(watcherActor.conn, blackboxingSpec);
+ this.watcherActor = watcherActor;
+ }
+
+ /**
+ * Request to blackbox a new JS file either completely if no range is passed.
+ * Or only a precise subset of lines described by range attribute.
+ *
+ * @param {String} url
+ * Mandatory argument to mention what URL of JS file should be blackboxed.
+ * @param {Array<Objects>} ranges
+ * The whole file will be blackboxed if this array is empty.
+ * Each range is made of an object like this:
+ * {
+ * start: { line: 1, column: 1 },
+ * end: { line: 10, column: 10 },
+ * }
+ */
+ blackbox(url, ranges) {
+ if (!ranges.length) {
+ return this.watcherActor.addDataEntry(BLACKBOXING, [
+ { url, range: null },
+ ]);
+ }
+ return this.watcherActor.addDataEntry(
+ BLACKBOXING,
+ ranges.map(range => {
+ return {
+ url,
+ range,
+ };
+ })
+ );
+ }
+
+ /**
+ * Request to unblackbox some JS sources.
+ *
+ * See `blackbox` for more info.
+ */
+ unblackbox(url, ranges) {
+ if (!ranges.length) {
+ const existingRanges = (
+ this.watcherActor.getSessionDataForType(BLACKBOXING) || []
+ ).filter(entry => entry.url == url);
+
+ return this.watcherActor.removeDataEntry(BLACKBOXING, existingRanges);
+ }
+ return this.watcherActor.removeDataEntry(
+ BLACKBOXING,
+ ranges.map(range => {
+ return {
+ url,
+ range,
+ };
+ })
+ );
+ }
+}
+
+exports.BlackboxingActor = BlackboxingActor;