VulpesOS/gaia/tests/jsmarionette/client/marionette-client/lib/marionette/message.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

67 lines
1.4 KiB
JavaScript
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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';
function Command(body) {
this.id = null;
this.name = body.name;
this.params = body.parameters || {};
}
Command.prototype.toString = function() {
return 'Command ' + JSON.stringify({
id: this.id,
name: this.name,
params: this.params
});
};
Command.prototype.toMsg = function() {
if (!this.id) {
throw new RangeError('Command ID must be specified');
}
return [Command.TYPE, this.id, this.name, this.params];
};
Command.fromMsg = function(msg) {
return new Command(msg[1], msg[2], msg[3]);
};
Command.TYPE = 0;
function Response(msgId, obj) {
this.id = msgId;
this.error = null;
this.result = null;
if (obj instanceof Error) {
this.error = obj;
} else {
this.result = obj;
}
}
Response.prototype.toString = function() {
return 'Response ' + JSON.stringify({
id: this.id,
error: this.error,
result: this.result
});
};
Response.prototype.toMsg = function() {
return [Response.TYPE, this.id, this.error, this.result];
};
Response.fromMsg = function(msg) {
return new Response(msg[1], msg[2] || msg[3]);
};
Response.TYPE = 1;
module.exports = {
Command: Command,
Response: Response,
};