js/src/jit-test/tests/collections/Map-iterator-remove-1.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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]]);

mercurial