Bug 1454792 - Prevent duplicating arrays in Array type's read/write methods. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 05 Apr 2018 09:23:09 -0700
changeset 784232 07203e86c7c48d5894f860c9a120cd6e74f24f0b
parent 784231 854a98f364b347d193d130d811417c47162d1020
child 784233 3601d351cad391895d28d7555d2ffc09c6fb6009
push id106883
push userbmo:poirot.alex@gmail.com
push dateWed, 18 Apr 2018 09:44:52 +0000
reviewersjryans
bugs1454792
milestone61.0a1
Bug 1454792 - Prevent duplicating arrays in Array type's read/write methods. r=jryans MozReview-Commit-ID: 82GYGZUs6TH
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -217,18 +217,28 @@ types.addArrayType = function(subtype) {
   let name = "array:" + subtype.name;
 
   // Arrays of primitive types are primitive types themselves.
   if (subtype.primitive) {
     return types.addType(name);
   }
   return types.addType(name, {
     category: "array",
-    read: (v, ctx) => [...v].map(i => subtype.read(i, ctx)),
-    write: (v, ctx) => [...v].map(i => subtype.write(i, ctx))
+    read: (v, ctx) => {
+      if (isIterator(v)) {
+        v = [...v];
+      }
+      return v.map(i => subtype.read(i, ctx));
+    },
+    write: (v, ctx) => {
+      if (isIterator(v)) {
+        v = [...v];
+      }
+      return v.map(i => subtype.write(i, ctx));
+    }
   });
 };
 
 /**
  * Add a dict type to the type system.  This allows you to serialize
  * a JS object that contains non-primitive subtypes.
  *
  * Properties of the value that aren't included in the specializations