Bug 1454899 - Prevent request arguments duplication on each request call. r=jryans
MozReview-Commit-ID: GaLM6LsCoWp
--- 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