diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/shared/commands/object/object-command.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream/124.0.1.tar.xz firefox-upstream/124.0.1.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/shared/commands/object/object-command.js')
-rw-r--r-- | devtools/shared/commands/object/object-command.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/devtools/shared/commands/object/object-command.js b/devtools/shared/commands/object/object-command.js new file mode 100644 index 0000000000..0396b6167a --- /dev/null +++ b/devtools/shared/commands/object/object-command.js @@ -0,0 +1,63 @@ +/* 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 ObjectCommand helps inspecting and managing lifecycle + * of all inspected JavaScript objects. + */ +class ObjectCommand { + constructor({ commands, descriptorFront, watcherFront }) { + this.#commands = commands; + } + #commands = null; + + /** + * Release a set of object actors all at once. + * + * @param {Array<ObjectFront>} frontsToRelease + * List of fronts for the object to release. + */ + async releaseObjects(frontsToRelease) { + // @backward-compat { version 123 } A new Objects Manager front has a new "releaseActors" method. + // Only supportsReleaseActors=true codepath can be kept once 123 is the release channel. + const { supportsReleaseActors } = this.#commands.client.mainRoot.traits; + + // First group all object fronts per target + const actorsPerTarget = new Map(); + const promises = []; + for (const frontToRelease of frontsToRelease) { + const { targetFront } = frontToRelease; + // If the front is already destroyed, its target front will be nullified. + if (!targetFront) { + continue; + } + + let actorIDsToRemove = actorsPerTarget.get(targetFront); + if (!actorIDsToRemove) { + actorIDsToRemove = []; + actorsPerTarget.set(targetFront, actorIDsToRemove); + } + if (supportsReleaseActors) { + actorIDsToRemove.push(frontToRelease.actorID); + frontToRelease.destroy(); + } else { + promises.push(frontToRelease.release()); + } + } + + if (supportsReleaseActors) { + // Then release all fronts by bulk per target + for (const [targetFront, actorIDs] of actorsPerTarget) { + const objectsManagerFront = await targetFront.getFront("objects-manager"); + promises.push(objectsManagerFront.releaseObjects(actorIDs)); + } + } + + await Promise.all(promises); + } +} + +module.exports = ObjectCommand; |