js/src/tests/ecma_6/Generators/delegating-yield-3.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.

     1 // Test yield* with iter.next and monkeypatching.
     3 function* g(n) { for (var i=0; i<n; i++) yield i; }
     4 function* delegate(iter) { return yield* iter; }
     5 var GeneratorObjectPrototype = Object.getPrototypeOf(g).prototype;
     6 var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next;
     8 // Monkeypatch next on an iterator.
     9 var inner = g(20);
    10 var outer = delegate(inner);
    11 assertIteratorNext(outer, 0);
    12 assertIteratorNext(outer, 1);
    13 inner.next = function() { return 0; };
    14 // 42 yielded directly without re-boxing.
    15 assertEq(0, outer.next());
    16 // Outer generator not terminated.
    17 assertEq(0, outer.next());
    18 // Restore.
    19 inner.next = GeneratorObjectPrototype_next;
    20 assertIteratorNext(outer, 2);
    21 // Repatch.
    22 inner.next = function() { return { value: 42, done: true }; };
    23 assertIteratorDone(outer, 42);
    25 // Monkeypunch next on the prototype.
    26 var inner = g(20);
    27 var outer = delegate(inner);
    28 assertIteratorNext(outer, 0);
    29 assertIteratorNext(outer, 1);
    30 GeneratorObjectPrototype.next = function() { return 0; };
    31 // 42 yielded directly without re-boxing.
    32 assertEq(0, GeneratorObjectPrototype_next.call(outer));
    33 // Outer generator not terminated.
    34 assertEq(0, GeneratorObjectPrototype_next.call(outer));
    35 // Restore.
    36 GeneratorObjectPrototype.next = GeneratorObjectPrototype_next;
    37 assertIteratorNext(outer, 2);
    39 if (typeof reportCompare == "function")
    40     reportCompare(true, true);

mercurial