Bug 1453385 - Prevent protocol.js from copying all response objects. r=jryans
MozReview-Commit-ID: 5suOD9UmIr
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -713,22 +713,31 @@ Response.prototype = {
* Write a response for the given return value.
*
* @param val ret
* The return value.
* @param object ctx
* The object writing the response.
*/
write: function(ret, ctx) {
- return JSON.parse(JSON.stringify(this.template, function(key, value) {
+ // Consider that `template` is either directly a `RetVal`,
+ // or a dictionary with may be one `RetVal`.
+ if (this.template instanceof RetVal) {
+ return this.template.write(ret, ctx);
+ }
+ let result = {};
+ for (let key in this.template) {
+ let value = this.template[key];
if (value instanceof RetVal) {
- return value.write(ret, ctx);
+ result[key] = value.write(ret, ctx);
+ } else {
+ result[key] = value;
}
- return value;
- }));
+ }
+ return result;
},
/**
* Read a return value from the given response.
*
* @param object packet
* The response packet.
* @param object ctx