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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_6/Generators/delegating-yield-10.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +// Errors accessing next, done, or value don't cause an exception to be
     1.5 +// thrown into the iterator of a yield*.
     1.6 +
     1.7 +function* g(n) { for (var i=0; i<n; i++) yield i; }
     1.8 +function* delegate(iter) { return yield* iter; }
     1.9 +
    1.10 +var log = "", inner, outer;
    1.11 +
    1.12 +// That var is poisoooooon, p-poison poison...
    1.13 +var Poison = new Error;
    1.14 +
    1.15 +function log_calls(method) {
    1.16 +    return function () {
    1.17 +        log += "x"
    1.18 +        return method.call(this);
    1.19 +    }
    1.20 +}
    1.21 +
    1.22 +function poison(receiver, prop) {
    1.23 +    Object.defineProperty(receiver, prop, { get: function () { throw Poison } });
    1.24 +}
    1.25 +
    1.26 +// Poison inner.next.
    1.27 +inner = g(10);
    1.28 +outer = delegate(inner);
    1.29 +inner.throw = log_calls(inner.throw);
    1.30 +poison(inner, 'next')
    1.31 +assertThrowsValue(outer.next.bind(outer), Poison);
    1.32 +assertEq(log, "");
    1.33 +
    1.34 +// Poison result value from inner.
    1.35 +inner = g(10);
    1.36 +outer = delegate(inner);
    1.37 +inner.next = function () { return { done: true, get value() { throw Poison} } };
    1.38 +inner.throw = log_calls(inner.throw);
    1.39 +assertThrowsValue(outer.next.bind(outer), Poison);
    1.40 +assertEq(log, "");
    1.41 +
    1.42 +// Poison result done from inner.
    1.43 +inner = g(10);
    1.44 +outer = delegate(inner);
    1.45 +inner.next = function () { return { get done() { throw Poison }, value: 42 } };
    1.46 +inner.throw = log_calls(inner.throw);
    1.47 +assertThrowsValue(outer.next.bind(outer), Poison);
    1.48 +assertEq(log, "");
    1.49 +
    1.50 +// mischief managed.
    1.51 +if (typeof reportCompare == "function")
    1.52 +    reportCompare(true, true);

mercurial