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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Test that yield* can appear in a loop, and alongside yield.
michael@0 2
michael@0 3 function* countdown(n) {
michael@0 4 while (n > 0) {
michael@0 5 yield n;
michael@0 6 yield* countdown(--n);
michael@0 7 }
michael@0 8 return 34;
michael@0 9 }
michael@0 10
michael@0 11 function collect_results(iter) {
michael@0 12 var ret = [];
michael@0 13 var result;
michael@0 14 do {
michael@0 15 result = iter.next();
michael@0 16 ret.push(result);
michael@0 17 } while (!result.done);
michael@0 18 return ret;
michael@0 19 }
michael@0 20
michael@0 21 var expected = [
michael@0 22 // yield in countdown(3), n == 3
michael@0 23 {value: 3, done: false},
michael@0 24 // yield in yield* countdown(2), n == 2
michael@0 25 {value: 2, done: false},
michael@0 26 // yield in nested yield* countdown(1), n == 1
michael@0 27 {value: 1, done: false},
michael@0 28 // countdown(0) yields no values
michael@0 29 // second go-through of countdown(2) loop, n == 1
michael@0 30 {value: 1, done: false},
michael@0 31 // second go-through of countdown(3) loop, n == 2
michael@0 32 {value: 2, done: false},
michael@0 33 // yield in yield* countdown(1), n == 1
michael@0 34 {value: 1, done: false},
michael@0 35 // third go-through of countdown(3) loop, n == 1
michael@0 36 {value: 1, done: false},
michael@0 37 // done
michael@0 38 {value: 34, done: true}
michael@0 39 ];
michael@0 40
michael@0 41 assertDeepEq(expected, collect_results(countdown(3)));
michael@0 42
michael@0 43 if (typeof reportCompare == "function")
michael@0 44 reportCompare(true, true);

mercurial