Bug 1260938 - Add the `ThreadSafeDevToolsUtils.isSet` utility; r=jimb a=kwierso
authorNick Fitzgerald <fitzgen@gmail.com>
Thu, 31 Mar 2016 16:19:47 -0700
changeset 291301 49adb658e099d5b38c24c5c4cf34e603c0e12afc
parent 291300 a5e17a9cb4a02db80b1ba543a1158966c470078a
child 291302 9c04c66d849bae2c29518f81a3d6a13068ef485f
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb, kwierso
bugs1260938
milestone48.0a1
Bug 1260938 - Add the `ThreadSafeDevToolsUtils.isSet` utility; r=jimb a=kwierso MozReview-Commit-ID: IqY3Abv3OX
devtools/shared/ThreadSafeDevToolsUtils.js
devtools/shared/tests/unit/test_isSet.js
devtools/shared/tests/unit/xpcshell.ini
--- a/devtools/shared/ThreadSafeDevToolsUtils.js
+++ b/devtools/shared/ThreadSafeDevToolsUtils.js
@@ -240,16 +240,23 @@ exports.isPromise = function (p) {
 /**
  * Return true if `thing` is a SavedFrame, false otherwise.
  */
 exports.isSavedFrame = function (thing) {
   return Object.prototype.toString.call(thing) === "[object SavedFrame]";
 };
 
 /**
+ * Return true iff `thing` is a `Set` object (possibly from another global).
+ */
+exports.isSet = function(thing) {
+  return Object.prototype.toString.call(thing) === "[object Set]";
+};
+
+/**
  * Given a list of lists, flatten it. Only flattens one level; does not
  * recursively flatten all levels.
  *
  * @param {Array<Array<Any>>} lists
  * @return {Array<Any>}
  */
 exports.flatten = function(lists) {
   return Array.prototype.concat.apply([], lists);
new file mode 100644
--- /dev/null
+++ b/devtools/shared/tests/unit/test_isSet.js
@@ -0,0 +1,25 @@
+/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test ThreadSafeDevToolsUtils.isSet
+
+function run_test() {
+  const { isSet } = DevToolsUtils;
+
+  equal(isSet(new Set()), true);
+  equal(isSet(new Map()), false);
+  equal(isSet({}), false);
+  equal(isSet("I swear I'm a Set"), false);
+  equal(isSet(5), false);
+
+  const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
+        .createInstance(Ci.nsIPrincipal);
+  const sandbox = new Cu.Sandbox(systemPrincipal);
+
+  equal(isSet(Cu.evalInSandbox("new Set()", sandbox)), true);
+  equal(isSet(Cu.evalInSandbox("new Map()", sandbox)), false);
+  equal(isSet(Cu.evalInSandbox("({})", sandbox)), false);
+  equal(isSet(Cu.evalInSandbox("'I swear I\\'m a Set'", sandbox)), false);
+  equal(isSet(Cu.evalInSandbox("5", sandbox)), false);
+}
--- a/devtools/shared/tests/unit/xpcshell.ini
+++ b/devtools/shared/tests/unit/xpcshell.ini
@@ -11,16 +11,17 @@ support-files =
 [test_fetch-chrome.js]
 [test_fetch-file.js]
 [test_fetch-http.js]
 [test_fetch-resource.js]
 [test_flatten.js]
 [test_indentation.js]
 [test_independent_loaders.js]
 [test_invisible_loader.js]
+[test_isSet.js]
 [test_safeErrorString.js]
 [test_defineLazyPrototypeGetter.js]
 [test_async-utils.js]
 [test_consoleID.js]
 [test_cssAngle.js]
 [test_cssColor.js]
 [test_prettifyCSS.js]
 [test_require_lazy.js]