js/src/jit-test/tests/for-of/semantics-09.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/for-of/semantics-09.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +// The LHS of a for-of loop is not evaluated until after the .next() method returns.
     1.5 +
     1.6 +var s;
     1.7 +function f() {
     1.8 +    s += 'f';
     1.9 +    return {};
    1.10 +}
    1.11 +
    1.12 +// Test 1: .next() throws StopIteration right away. f is never called.
    1.13 +s = '';
    1.14 +for (f().x of [])
    1.15 +    s += '.';
    1.16 +assertEq(s, '');
    1.17 +
    1.18 +// Test 2: check proper interleaving of f calls, iterator.next() calls, and the loop body.
    1.19 +function g() {
    1.20 +    s += 'g';
    1.21 +    yield 0;
    1.22 +    s += 'g';
    1.23 +    yield 1;
    1.24 +    s += 'g';
    1.25 +}
    1.26 +for (f().x of g())
    1.27 +    s += '.';
    1.28 +assertEq(s, 'gf.gf.g');

mercurial