Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Errors accessing next, done, or value don't cause an exception to be |
michael@0 | 2 | // thrown into the iterator of a yield*. |
michael@0 | 3 | |
michael@0 | 4 | function* g(n) { for (var i=0; i<n; i++) yield i; } |
michael@0 | 5 | function* delegate(iter) { return yield* iter; } |
michael@0 | 6 | |
michael@0 | 7 | var log = "", inner, outer; |
michael@0 | 8 | |
michael@0 | 9 | // That var is poisoooooon, p-poison poison... |
michael@0 | 10 | var Poison = new Error; |
michael@0 | 11 | |
michael@0 | 12 | function log_calls(method) { |
michael@0 | 13 | return function () { |
michael@0 | 14 | log += "x" |
michael@0 | 15 | return method.call(this); |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function poison(receiver, prop) { |
michael@0 | 20 | Object.defineProperty(receiver, prop, { get: function () { throw Poison } }); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | // Poison inner.next. |
michael@0 | 24 | inner = g(10); |
michael@0 | 25 | outer = delegate(inner); |
michael@0 | 26 | inner.throw = log_calls(inner.throw); |
michael@0 | 27 | poison(inner, 'next') |
michael@0 | 28 | assertThrowsValue(outer.next.bind(outer), Poison); |
michael@0 | 29 | assertEq(log, ""); |
michael@0 | 30 | |
michael@0 | 31 | // Poison result value from inner. |
michael@0 | 32 | inner = g(10); |
michael@0 | 33 | outer = delegate(inner); |
michael@0 | 34 | inner.next = function () { return { done: true, get value() { throw Poison} } }; |
michael@0 | 35 | inner.throw = log_calls(inner.throw); |
michael@0 | 36 | assertThrowsValue(outer.next.bind(outer), Poison); |
michael@0 | 37 | assertEq(log, ""); |
michael@0 | 38 | |
michael@0 | 39 | // Poison result done from inner. |
michael@0 | 40 | inner = g(10); |
michael@0 | 41 | outer = delegate(inner); |
michael@0 | 42 | inner.next = function () { return { get done() { throw Poison }, value: 42 } }; |
michael@0 | 43 | inner.throw = log_calls(inner.throw); |
michael@0 | 44 | assertThrowsValue(outer.next.bind(outer), Poison); |
michael@0 | 45 | assertEq(log, ""); |
michael@0 | 46 | |
michael@0 | 47 | // mischief managed. |
michael@0 | 48 | if (typeof reportCompare == "function") |
michael@0 | 49 | reportCompare(true, true); |