Bug 1453385 - Prevent protocol.js from copying all response objects. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 09 Apr 2018 12:45:17 -0700
changeset 781937 2df70ad4a7ca369bc3950a9fe9c0a0499eda0815
parent 781447 c72bc98897898cd795ef159f8b855c6d2f1f07b5
child 781938 6c0db50fca68d786637418f1088b418b583595a4
push id106451
push userbmo:poirot.alex@gmail.com
push dateFri, 13 Apr 2018 20:48:33 +0000
reviewersjryans
bugs1453385
milestone61.0a1
Bug 1453385 - Prevent protocol.js from copying all response objects. r=jryans MozReview-Commit-ID: 5suOD9UmIr
devtools/shared/protocol.js
--- 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