Bug 1337743 - Command parameters may be null; r?whimboo
The fourth element of the command packet may be null and for that to
hit our default type check in message.Command's constructor we need to
interpret null as undefined.
This allows us to receive packets such as
[<number>, <number>, <string>, <null or value>]
MozReview-Commit-ID: EcAmsPAzz5p
--- a/testing/marionette/message.js
+++ b/testing/marionette/message.js
@@ -93,18 +93,18 @@ Message.fromMsg = function (data) {
* @param {number} msgId
* Message ID unique identifying this message.
* @param {string} name
* Command name.
* @param {Object<string, ?>} params
* Command parameters.
*/
this.Command = class {
- constructor(msgId, name, params={}) {
- this.id = msgId;
+ constructor(msgID, name, params = {}) {
+ this.id = msgID;
this.name = name;
this.parameters = params;
this.onerror = null;
this.onresult = null;
this.origin = MessageOrigin.Client;
this.sent = false;
@@ -128,21 +128,28 @@ this.Command = class {
toMsg() {
return [Command.TYPE, this.id, this.name, this.parameters];
}
toString() {
return "Command {id: " + this.id + ", " +
"name: " + JSON.stringify(this.name) + ", " +
- "parameters: " + JSON.stringify(this.parameters) + "}"
+ "parameters: " + JSON.stringify(this.parameters) + "}";
}
static fromMsg(msg) {
- return new Command(msg[1], msg[2], msg[3]);
+ let [msgID, name, params] = [msg[1], msg[2], msg[3]];
+
+ // if parameters are given but null, treat them as undefined
+ if (params === null) {
+ params = undefined;
+ }
+
+ return new Command(msgID, name, params);
}
};
Command.TYPE = 0;
const validator = {
exclusionary: {