Bug 1454792 - Stop duplicating arrays in protocol.js's identifyWrite function. r=jryans
MozReview-Commit-ID: LTgw12JInh9
--- 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.
*