Bug 1497342, part 1 - Add nondeterministicGetWeakMapKeys() to SpecialPowers r=jmaher
authorAndrew McCreight <continuation@gmail.com>
Wed, 10 Oct 2018 17:35:52 +0000
changeset 499036 b2afdca1a42f8f1014e88a009cbaf7ca39d09711
parent 499035 8f52497c3d96f9f193a82ab2e715230ea77528db
child 499037 07a4bffa3dd65ee6137403289dd3422ee9167557
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1497342
milestone64.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 1497342, part 1 - Add nondeterministicGetWeakMapKeys() to SpecialPowers r=jmaher Differential Revision: https://phabricator.services.mozilla.com/D8131
testing/mochitest/tests/Harness_sanity/mochitest.ini
testing/mochitest/tests/Harness_sanity/test_getweakmapkeys.html
testing/specialpowers/content/specialpowersAPI.js
--- a/testing/mochitest/tests/Harness_sanity/mochitest.ini
+++ b/testing/mochitest/tests/Harness_sanity/mochitest.ini
@@ -38,8 +38,9 @@ subsuite = clipboard
 skip-if = toolkit == 'android'  # bug 688052
 [test_sanity_manifest.html]
 skip-if = toolkit == 'android' # we use the old manifest style on android
 fail-if = true
 [test_sanity_manifest_pf.html]
 skip-if = toolkit == 'android' # we use the old manifest style on android
 fail-if = true
 [test_sanity_waitForCondition.html]
+[test_getweakmapkeys.html]
new file mode 100644
--- /dev/null
+++ b/testing/mochitest/tests/Harness_sanity/test_getweakmapkeys.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for SpecialPowers.nondeterministicGetWeakMapKeys</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<div id="content" class="testbody">
+  <script type="text/javascript">
+    var emptyMap = new WeakMap;
+    is(SpecialPowers.nondeterministicGetWeakMapKeys(emptyMap).length, 0, "Empty map has no keys");
+    var twoMap = new WeakMap;
+    var x = {};
+    var y = {};
+    twoMap.set(x, 1);
+    twoMap.set(y, 2);
+    var twoMapKeys = SpecialPowers.nondeterministicGetWeakMapKeys(twoMap);
+    is(twoMapKeys.length, 2, "Map with two things should have two keys");
+    ok(twoMapKeys[0] == x || twoMapKeys[1] == x, "One of the keys should be x");
+    ok(twoMapKeys[0] == y || twoMapKeys[1] == y, "One of the keys should be y");
+  </script>
+</div>
+</body>
+</html>
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -1607,16 +1607,20 @@ SpecialPowersAPI.prototype = {
           cb();
         }
       };
     }
 
     Cu.schedulePreciseGC(genGCCallback(callback));
   },
 
+  nondeterministicGetWeakMapKeys(m) {
+    return ChromeUtils.nondeterministicGetWeakMapKeys(m);
+  },
+
   getMemoryReports() {
     try {
       Cc["@mozilla.org/memory-reporter-manager;1"]
         .getService(Ci.nsIMemoryReporterManager)
         .getReports(() => {}, null, () => {}, null, false);
     } catch (e) { }
   },