Bug 1454792 - Stop duplicating arrays in protocol.js's identifyWrite function. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 05 Apr 2018 09:14:09 -0700
changeset 784230 23da050bfed71740d3e5dcb09f05523b8612f023
parent 784229 f5a89dde3e88615d74466fac86cba7470961f0a8
child 784231 854a98f364b347d193d130d811417c47162d1020
push id106883
push userbmo:poirot.alex@gmail.com
push dateWed, 18 Apr 2018 09:44:52 +0000
reviewersjryans
bugs1454792
milestone61.0a1
Bug 1454792 - Stop duplicating arrays in protocol.js's identifyWrite function. r=jryans MozReview-Commit-ID: LTgw12JInh9
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -113,26 +113,33 @@ types.getType = function(type) {
   if (pieces.length > 1) {
     return types.addActorDetail(type, pieces[0], pieces[1]);
   }
 
   throw Error("Unknown type: " + type);
 };
 
 /**
+ * Helper function to identify iterators. This will return false for Arrays.
+ */
+function isIterator(v) {
+  return v && typeof v === "object" && Symbol.iterator in v && !Array.isArray(v);
+}
+
+/**
  * Don't allow undefined when writing primitive types to packets.  If
  * you want to allow undefined, use a nullable type.
  */
 function identityWrite(v) {
   if (v === undefined) {
     throw Error("undefined passed where a value is required");
   }
   // This has to handle iterator->array conversion because arrays of
   // primitive types pass through here.
-  if (v && typeof (v) === "object" && Symbol.iterator in v) {
+  if (isIterator(v)) {
     return [...v];
   }
   return v;
 }
 
 /**
  * Add a type to the type system.
  *