test_weak_keys.js (1780B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* See https://bugzilla.mozilla.org/show_bug.cgi?id=1165807 */ 6 7 function run_test() 8 { 9 var bunnies = new String("bunnies"); 10 var lizards = new String("lizards"); 11 12 var weakset = new WeakSet([bunnies, lizards]); 13 var weakmap = new WeakMap(); 14 weakmap.set(bunnies, 23); 15 weakmap.set(lizards, "oh no"); 16 17 var keys = ChromeUtils.nondeterministicGetWeakMapKeys(bunnies); 18 equal(keys, undefined, "test nondeterministicGetWeakMapKeys on non-WeakMap"); 19 20 keys = ChromeUtils.nondeterministicGetWeakMapKeys(weakmap); 21 equal(keys.length, 2, "length of nondeterministicGetWeakMapKeys"); 22 equal(weakmap.get(bunnies), 23, "check bunnies in weakmap"); 23 equal(weakmap.get(lizards), "oh no", "check lizards in weakmap"); 24 25 keys = ChromeUtils.nondeterministicGetWeakSetKeys(bunnies); 26 equal(keys, undefined, "test nondeterministicGetWeakSetKeys on non-WeakMap"); 27 28 keys = ChromeUtils.nondeterministicGetWeakSetKeys(weakset); 29 equal(keys.length, 2, "length of nondeterministicGetWeakSetKeys"); 30 ok(weakset.has(bunnies), "check bunnies in weakset"); 31 ok(weakset.has(lizards), "check lizards in weakset"); 32 33 bunnies = null; 34 keys = null; 35 36 Cu.forceGC(); 37 38 keys = ChromeUtils.nondeterministicGetWeakMapKeys(weakmap); 39 equal(keys.length, 1, "length of nondeterministicGetWeakMapKeys after GC"); 40 equal(weakmap.get(lizards), "oh no", "check lizards still in weakmap"); 41 42 keys = ChromeUtils.nondeterministicGetWeakSetKeys(weakset); 43 equal(keys.length, 1, "length of nondeterministicGetWeakSetKeys after GC"); 44 ok(weakset.has(lizards), "check lizards still in weakset"); 45 }