diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/protocol/Actor | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/protocol/Actor')
-rw-r--r-- | devtools/shared/protocol/Actor/generateActorSpec.js | 62 | ||||
-rw-r--r-- | devtools/shared/protocol/Actor/moz.build | 8 |
2 files changed, 70 insertions, 0 deletions
diff --git a/devtools/shared/protocol/Actor/generateActorSpec.js b/devtools/shared/protocol/Actor/generateActorSpec.js new file mode 100644 index 0000000000..9b3b166c8b --- /dev/null +++ b/devtools/shared/protocol/Actor/generateActorSpec.js @@ -0,0 +1,62 @@ +/* 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"; + +var { Request } = require("resource://devtools/shared/protocol/Request.js"); +const { Response } = require("resource://devtools/shared/protocol/Response.js"); +var { + types, + registeredTypes, +} = require("resource://devtools/shared/protocol/types.js"); + +/** + * Generates an actor specification from an actor description. + */ +var generateActorSpec = function (actorDesc) { + const actorSpec = { + typeName: actorDesc.typeName, + methods: [], + }; + + // Find additional method specifications + if (actorDesc.methods) { + for (const name in actorDesc.methods) { + const methodSpec = actorDesc.methods[name]; + const spec = {}; + + spec.name = methodSpec.name || name; + spec.request = new Request( + Object.assign({ type: spec.name }, methodSpec.request || undefined) + ); + spec.response = new Response(methodSpec.response || undefined); + spec.release = methodSpec.release; + spec.oneway = methodSpec.oneway; + + actorSpec.methods.push(spec); + } + } + + // Find event specifications + if (actorDesc.events) { + actorSpec.events = new Map(); + for (const name in actorDesc.events) { + const eventRequest = actorDesc.events[name]; + Object.freeze(eventRequest); + actorSpec.events.set( + name, + new Request(Object.assign({ type: name }, eventRequest)) + ); + } + } + + if (!registeredTypes.has(actorSpec.typeName)) { + types.addActorType(actorSpec.typeName); + } + registeredTypes.get(actorSpec.typeName).actorSpec = actorSpec; + + return actorSpec; +}; + +exports.generateActorSpec = generateActorSpec; diff --git a/devtools/shared/protocol/Actor/moz.build b/devtools/shared/protocol/Actor/moz.build new file mode 100644 index 0000000000..3e3c46d49b --- /dev/null +++ b/devtools/shared/protocol/Actor/moz.build @@ -0,0 +1,8 @@ +# 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/. + +DevToolsModules( + "generateActorSpec.js", +) |