Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / remote / webdriver-bidi / modules / WindowGlobalBiDiModule.sys.mjs
blob5aff8449326a357a3c67c19d3971cac59dc6a317
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs";
7 const lazy = {};
9 ChromeUtils.defineESModuleGetters(lazy, {
10   deserialize: "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs",
11   serialize: "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs",
12 });
14 /**
15  * Base class for all WindowGlobal BiDi MessageHandler modules.
16  */
17 export class WindowGlobalBiDiModule extends Module {
18   get #nodeCache() {
19     return this.#processActor.getNodeCache();
20   }
22   get #processActor() {
23     return ChromeUtils.domProcessChild.getActor("WebDriverProcessData");
24   }
26   /**
27    * Wrapper to deserialize a local / remote value.
28    *
29    * @param {Realm} realm
30    *     The Realm in which the value is deserialized.
31    * @param {object} serializedValue
32    *     Value of any type to be deserialized.
33    * @param {ExtraSerializationOptions=} extraOptions
34    *     Extra Remote Value deserialization options.
35    *
36    * @returns {object}
37    *     Deserialized representation of the value.
38    */
39   deserialize(realm, serializedValue, extraOptions = {}) {
40     extraOptions.nodeCache = this.#nodeCache;
42     return lazy.deserialize(realm, serializedValue, extraOptions);
43   }
45   /**
46    * Wrapper to serialize a value as a remote value.
47    *
48    * @param {object} value
49    *     Value of any type to be serialized.
50    * @param {SerializationOptions} serializationOptions
51    *     Options which define how ECMAScript objects should be serialized.
52    * @param {OwnershipModel} ownershipType
53    *     The ownership model to use for this serialization.
54    * @param {Realm} realm
55    *     The Realm from which comes the value being serialized.
56    * @param {ExtraSerializationOptions} extraOptions
57    *     Extra Remote Value serialization options.
58    *
59    * @returns {object}
60    *     Promise that resolves to the serialized representation of the value.
61    */
62   serialize(
63     value,
64     serializationOptions,
65     ownershipType,
66     realm,
67     extraOptions = {}
68   ) {
69     const { nodeCache = this.#nodeCache, seenNodeIds = new Map() } =
70       extraOptions;
72     const serializedValue = lazy.serialize(
73       value,
74       serializationOptions,
75       ownershipType,
76       new Map(),
77       realm,
78       { nodeCache, seenNodeIds }
79     );
81     return serializedValue;
82   }