js/src/tests/ecma_6/Generators/delegating-yield-9.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 // Test that yield* can appear in a loop, and inside yield.
     3 function* countdown(n) {
     4     while (n > 0) {
     5         yield (yield* countdown(--n));
     6     }
     7     return 34;
     8 }
    10 function collect_results(iter) {
    11     var ret = [];
    12     var result;
    13     do {
    14         result = iter.next();
    15         ret.push(result);
    16     } while (!result.done);
    17     return ret;
    18 }
    20 var expected = [
    21     // Only 34 yielded from the "yield" and the last return make it out.
    22     // Three yields in countdown(3), two in countdown(2), and one in
    23     // countdown(1) (called twice).
    24     {value: 34, done: false},
    25     {value: 34, done: false},
    26     {value: 34, done: false},
    27     {value: 34, done: false},
    28     {value: 34, done: false},
    29     {value: 34, done: false},
    30     {value: 34, done: false},
    31     {value: 34, done: true}, // final
    32 ];
    34 assertDeepEq(collect_results(countdown(3)), expected);
    36 if (typeof reportCompare == "function")
    37     reportCompare(true, true);

mercurial