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.

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

mercurial