summaryrefslogtreecommitdiffstats
path: root/devtools/shared/commands/thread-configuration
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /devtools/shared/commands/thread-configuration
parentInitial commit. (diff)
downloadfirefox-esr-upstream/115.8.0esr.tar.xz
firefox-esr-upstream/115.8.0esr.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/commands/thread-configuration')
-rw-r--r--devtools/shared/commands/thread-configuration/moz.build7
-rw-r--r--devtools/shared/commands/thread-configuration/tests/browser.ini7
-rw-r--r--devtools/shared/commands/thread-configuration/tests/head.js12
-rw-r--r--devtools/shared/commands/thread-configuration/thread-configuration-command.js72
4 files changed, 98 insertions, 0 deletions
diff --git a/devtools/shared/commands/thread-configuration/moz.build b/devtools/shared/commands/thread-configuration/moz.build
new file mode 100644
index 0000000000..28e8e0ffc4
--- /dev/null
+++ b/devtools/shared/commands/thread-configuration/moz.build
@@ -0,0 +1,7 @@
+# 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/.
+
+DevToolsModules(
+ "thread-configuration-command.js",
+)
diff --git a/devtools/shared/commands/thread-configuration/tests/browser.ini b/devtools/shared/commands/thread-configuration/tests/browser.ini
new file mode 100644
index 0000000000..d918fce245
--- /dev/null
+++ b/devtools/shared/commands/thread-configuration/tests/browser.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+tags = devtools
+subsuite = devtools
+support-files =
+ !/devtools/client/shared/test/shared-head.js
+ head.js
+
diff --git a/devtools/shared/commands/thread-configuration/tests/head.js b/devtools/shared/commands/thread-configuration/tests/head.js
new file mode 100644
index 0000000000..ce65b3d827
--- /dev/null
+++ b/devtools/shared/commands/thread-configuration/tests/head.js
@@ -0,0 +1,12 @@
+/* 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";
+
+/* eslint no-unused-vars: [2, {"vars": "local"}] */
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
+ this
+);
diff --git a/devtools/shared/commands/thread-configuration/thread-configuration-command.js b/devtools/shared/commands/thread-configuration/thread-configuration-command.js
new file mode 100644
index 0000000000..0db1c2a285
--- /dev/null
+++ b/devtools/shared/commands/thread-configuration/thread-configuration-command.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/. */
+
+"use strict";
+
+/**
+ * The ThreadConfigurationCommand should be used to maintain thread settings
+ * sent from the client for the thread actor.
+ *
+ * See the ThreadConfigurationActor for a list of supported configuration options.
+ */
+class ThreadConfigurationCommand {
+ constructor({ commands, watcherFront }) {
+ this._commands = commands;
+ this._watcherFront = watcherFront;
+ }
+
+ /**
+ * Return a promise that resolves to the related thread configuration actor's front.
+ *
+ * @return {Promise<ThreadConfigurationFront>}
+ */
+ async getThreadConfigurationFront() {
+ const front = await this._watcherFront.getThreadConfigurationActor();
+ return front;
+ }
+
+ async updateConfiguration(configuration) {
+ if (this._commands.targetCommand.hasTargetWatcherSupport()) {
+ // Remove thread options that are not currently supported by
+ // the thread configuration actor.
+ const filteredConfiguration = Object.fromEntries(
+ Object.entries(configuration).filter(
+ ([key, value]) => !["breakpoints", "eventBreakpoints"].includes(key)
+ )
+ );
+
+ const threadConfigurationFront = await this.getThreadConfigurationFront();
+ const updatedConfiguration =
+ await threadConfigurationFront.updateConfiguration(
+ filteredConfiguration
+ );
+ this._configuration = updatedConfiguration;
+ }
+
+ let threadFronts = await this._commands.targetCommand.getAllFronts(
+ this._commands.targetCommand.ALL_TYPES,
+ "thread"
+ );
+
+ // Lets always call reconfigure for all the target types that do not
+ // have target watcher support yet. e.g In the browser, even
+ // though `hasTargetWatcherSupport()` is true, only
+ // FRAME and CONTENT PROCESS targets use watcher actors,
+ // WORKER targets are supported via the legacy listerners.
+ threadFronts = threadFronts.filter(
+ threadFront =>
+ !this._commands.targetCommand.hasTargetWatcherSupport(
+ threadFront.targetFront.targetType
+ )
+ );
+
+ // Ignore threads that fail to be configured.
+ // Some workers may be destroying and `reconfigure` would be rejected.
+ await Promise.allSettled(
+ threadFronts.map(threadFront => threadFront.reconfigure(configuration))
+ );
+ }
+}
+
+module.exports = ThreadConfigurationCommand;