Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // A map iterator can cope with removing the current entry. |
michael@0 | 2 | |
michael@0 | 3 | function test(pairs) { |
michael@0 | 4 | print(uneval(pairs)); |
michael@0 | 5 | var map = Map(pairs); |
michael@0 | 6 | |
michael@0 | 7 | var all_keys = ''; |
michael@0 | 8 | var false_keys = ''; |
michael@0 | 9 | for (let [k, v] of map) { |
michael@0 | 10 | all_keys += k; |
michael@0 | 11 | if (!v) |
michael@0 | 12 | false_keys += k; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | var log = ''; |
michael@0 | 16 | for (let [k, remove] of map) { |
michael@0 | 17 | log += k; |
michael@0 | 18 | if (remove) |
michael@0 | 19 | map.delete(k); |
michael@0 | 20 | } |
michael@0 | 21 | assertEq(log, all_keys); |
michael@0 | 22 | |
michael@0 | 23 | var remaining_keys = [k for ([k] of map)].join(''); |
michael@0 | 24 | assertEq(remaining_keys, false_keys); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | // removing the only entry |
michael@0 | 28 | test([['a', true]]); |
michael@0 | 29 | |
michael@0 | 30 | // removing the first entry |
michael@0 | 31 | test([['a', true], ['b', false], ['c', false]]); |
michael@0 | 32 | |
michael@0 | 33 | // removing a middle entry |
michael@0 | 34 | test([['a', false], ['b', true], ['c', false]]); |
michael@0 | 35 | |
michael@0 | 36 | // removing the last entry |
michael@0 | 37 | test([['a', false], ['b', false], ['c', true]]); |
michael@0 | 38 | |
michael@0 | 39 | // removing all entries |
michael@0 | 40 | test([['a', true], ['b', true], ['c', true]]); |