weakmap-expose.js (821B)
1 // Test that WeakMap.get() doesn't return a gray GC thing. 2 3 function checkNotGray(value) { 4 // Assigning a gray GC thing to an object propery will assert. 5 let test = {}; 6 test.property = value; 7 } 8 9 // 1. Make a black WeakMap with a gray key and gray value. 10 11 gczeal(0); 12 13 let key = {}; 14 let value = {}; 15 16 let map = new WeakMap(); 17 map.set(key, value); 18 19 let gray = grayRoot(); 20 gray.key = key; 21 22 addMarkObservers([map, key, value]); 23 24 gray = null; 25 key = null; 26 value = null; 27 28 gc(); 29 30 let marks = getMarks(); 31 assertEq(marks[0], "black"); 32 assertEq(marks[1], "gray"); 33 assertEq(marks[2], "gray"); 34 35 // 2. Get our key back, which will expose it and mark it black. 36 37 key = nondeterministicGetWeakMapKeys(map)[0]; 38 checkNotGray(key); 39 40 // 3. Look up the value in the map and check it's not gray. 41 42 value = map.get(key); 43 checkNotGray(value);