Bug 1454899 - Prevent request arguments duplication on each request call. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 05 Apr 2018 10:00:02 -0700
changeset 788342 0fed75c74fbe4a57c67214d02947c73d10f589e9
parent 786343 378a8a64401f765bfd0706ff678a4f5db7c05385
child 788343 65d58ab6dc271e9d8095d7a24fd21d794d7272a8
push id107967
push userbmo:poirot.alex@gmail.com
push dateThu, 26 Apr 2018 11:54:58 +0000
reviewersjryans
bugs1454899
milestone61.0a1
Bug 1454899 - Prevent request arguments duplication on each request call. r=jryans MozReview-Commit-ID: GaLM6LsCoWp
devtools/server/tests/unit/test_protocol_simple.js
devtools/shared/protocol.js
--- a/devtools/server/tests/unit/test_protocol_simple.js
+++ b/devtools/server/tests/unit/test_protocol_simple.js
@@ -39,28 +39,16 @@ const rootSpec = protocol.generateActorS
     },
     simpleArgs: {
       request: {
         firstArg: Arg(0),
         secondArg: Arg(1),
       },
       response: RetVal()
     },
-    nestedArgs: {
-      request: {
-        firstArg: Arg(0),
-        nest: {
-          secondArg: Arg(1),
-          nest: {
-            thirdArg: Arg(2)
-          }
-        }
-      },
-      response: RetVal()
-    },
     optionArgs: {
       request: {
         option1: Option(0),
         option2: Option(0)
       },
       response: RetVal()
     },
     optionalArgs: {
@@ -120,20 +108,16 @@ var RootActor = protocol.ActorClassWithS
   promiseReturn: function() {
     return Promise.resolve(1);
   },
 
   simpleArgs: function(a, b) {
     return { firstResponse: a + 1, secondResponse: b + 1 };
   },
 
-  nestedArgs: function(a, b, c) {
-    return { a: a, b: b, c: c };
-  },
-
   optionArgs: function(options) {
     return { option1: options.option1, option2: options.option2 };
   },
 
   optionalArgs: function(a, b = 200) {
     return b;
   },
 
@@ -232,27 +216,16 @@ function run_test() {
                         "secondArg": 10,
                         "to": "<actorid>"});
       trace.expectReceive({"firstResponse": 6,
                            "secondResponse": 11,
                            "from": "<actorid>"});
       Assert.equal(ret.firstResponse, 6);
       Assert.equal(ret.secondResponse, 11);
     }).then(() => {
-      return rootClient.nestedArgs(1, 2, 3);
-    }).then(ret => {
-      trace.expectSend({"type": "nestedArgs",
-                        "firstArg": 1,
-                        "nest": {"secondArg": 2, "nest": {"thirdArg": 3}},
-                        "to": "<actorid>"});
-      trace.expectReceive({"a": 1, "b": 2, "c": 3, "from": "<actorid>"});
-      Assert.equal(ret.a, 1);
-      Assert.equal(ret.b, 2);
-      Assert.equal(ret.c, 3);
-    }).then(() => {
       return rootClient.optionArgs({
         "option1": 5,
         "option2": 10
       });
     }).then(ret => {
       trace.expectSend({"type": "optionArgs",
                         "option1": 5,
                         "option2": 10,
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -678,24 +678,29 @@ Request.prototype = {
    *
    * @param array fnArgs
    *    The function arguments to place in the request.
    * @param object ctx
    *    The object making the request.
    * @returns a request packet.
    */
   write: function(fnArgs, ctx) {
-    let str = JSON.stringify(this.template, (key, value) => {
+    let ret = {};
+    for (let key in this.template) {
+      let value = this.template[key];
       if (value instanceof Arg) {
-        return value.write(value.index in fnArgs ? fnArgs[value.index] : undefined,
-                           ctx, key);
+        ret[key] = value.write(value.index in fnArgs ? fnArgs[value.index] : undefined,
+                               ctx, key);
+      } else if (key == "type") {
+        ret[key] = value;
+      } else {
+        throw new Error("Request can only an object with `Arg` or `Option` properties");
       }
-      return value;
-    });
-    return JSON.parse(str);
+    }
+    return ret;
   },
 
   /**
    * Read a request.
    *
    * @param object packet
    *    The request packet.
    * @param object ctx