Bug 1454792 - Stop duplicating arrays in protocol.js's identifyWrite function. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 05 Apr 2018 09:14:09 -0700
changeset 414365 84aa9286a0313e225c48b45b04bf4dc4f6478a9a
parent 414364 c0eacd0c16628a3cdd5eadc4ebf7807ccce3fb4d
child 414366 88b340fcdc65faf3b0fb556d6d8a1db358dd9174
push id62863
push userapoirot@mozilla.com
push dateWed, 18 Apr 2018 20:56:37 +0000
treeherderautoland@dd66dac690ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1454792
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
  *