Bug 1337743 - Command parameters may be null; r?whimboo draft
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 09 Feb 2017 16:38:13 +0000
changeset 551792 88f08a43ec9751ce80ac914cbcc34708c8b955d4
parent 551791 d48b15969c77cd8cf1a8ed744681847078149f7c
child 551793 f45c706d4014b7ee3453861c4c8272db360fbe32
push id51152
push userbmo:ato@mozilla.com
push dateMon, 27 Mar 2017 12:36:48 +0000
reviewerswhimboo
bugs1337743
milestone55.0a1
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
testing/marionette/message.js
--- 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: {