Bug 1455437 - Inline isIterator helper in protocol.js. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 18 Apr 2018 15:31:30 -0700
changeset 468579 6d7c927bd4a2ed9525db98e775be40f1b143c06a
parent 468578 02dd12e4b48f4b5a49e37563bc4fbd8411bb0bf7
child 468580 3ab74afe25565d6963f465510c6ab153a437a0ba
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1455437
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 1455437 - Inline isIterator helper in protocol.js. r=jryans MozReview-Commit-ID: DLoXENvbKOe
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -113,33 +113,26 @@ 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 (isIterator(v)) {
+  if (v && typeof v.next === "function") {
     return [...v];
   }
   return v;
 }
 
 /**
  * Add a type to the type system.
  *
@@ -218,23 +211,23 @@ types.addArrayType = function(subtype) {
 
   // Arrays of primitive types are primitive types themselves.
   if (subtype.primitive) {
     return types.addType(name);
   }
   return types.addType(name, {
     category: "array",
     read: (v, ctx) => {
-      if (isIterator(v)) {
+      if (v && typeof v.next === "function") {
         v = [...v];
       }
       return v.map(i => subtype.read(i, ctx));
     },
     write: (v, ctx) => {
-      if (isIterator(v)) {
+      if (v && typeof v.next === "function") {
         v = [...v];
       }
       return v.map(i => subtype.write(i, ctx));
     }
   });
 };
 
 /**