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

     1 // A map iterator can cope with removing the current entry.
     3 function test(pairs) {
     4     print(uneval(pairs));
     5     var map = Map(pairs);
     7     var all_keys = '';
     8     var false_keys = '';
     9     for (let [k, v] of map) {
    10         all_keys += k;
    11         if (!v)
    12             false_keys += k;
    13     }
    15     var log = '';
    16     for (let [k, remove] of map) {
    17         log += k;
    18         if (remove)
    19             map.delete(k);
    20     }
    21     assertEq(log, all_keys);
    23     var remaining_keys = [k for ([k] of map)].join('');
    24     assertEq(remaining_keys, false_keys);
    25 }
    27 // removing the only entry
    28 test([['a', true]]);
    30 // removing the first entry
    31 test([['a', true], ['b', false], ['c', false]]);
    33 // removing a middle entry
    34 test([['a', false], ['b', true], ['c', false]]);
    36 // removing the last entry
    37 test([['a', false], ['b', false], ['c', true]]);
    39 // removing all entries
    40 test([['a', true], ['b', true], ['c', true]]);

mercurial