js/src/jit-test/tests/for-of/next-shenanigans.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 for-of 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 var GeneratorObjectPrototype = Object.getPrototypeOf(g).prototype;
michael@0 5 var GeneratorObjectPrototype_next = GeneratorObjectPrototype.next;
michael@0 6
michael@0 7 // Monkeypatch next on an iterator.
michael@0 8 var inner = g(20);
michael@0 9 var n = 0;
michael@0 10 for (let x of inner) {
michael@0 11 if (n == 0) {
michael@0 12 assertEq(x, n++);
michael@0 13 } else if (n == 1) {
michael@0 14 assertEq(x, n++);
michael@0 15 inner.next = function() { return { value: 42, done: false }; };
michael@0 16 } else if (n == 2) {
michael@0 17 assertEq(x, 42);
michael@0 18 inner.next = function() { return { value: 100, done: true }; };
michael@0 19 } else
michael@0 20 throw 'not reached';
michael@0 21 }
michael@0 22
michael@0 23 // Monkeypatch next on the prototype.
michael@0 24 var inner = g(20);
michael@0 25 var n = 0;
michael@0 26 for (let x of inner) {
michael@0 27 if (n == 0) {
michael@0 28 assertEq(x, n++);
michael@0 29 } else if (n == 1) {
michael@0 30 assertEq(x, n++);
michael@0 31 GeneratorObjectPrototype.next =
michael@0 32 function() { return { value: 42, done: false }; };
michael@0 33 } else if (n == 2) {
michael@0 34 n++;
michael@0 35 assertEq(x, 42);
michael@0 36 GeneratorObjectPrototype.next = GeneratorObjectPrototype_next;
michael@0 37 } else if (n <= 20) {
michael@0 38 assertEq(x, n++ - 1);
michael@0 39 } else
michael@0 40 throw 'not reached';
michael@0 41 }

mercurial