yield-star.js (1493B)
1 // Copyright (C) 2015 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 es6id: 13.6.4.13 5 description: > 6 Control flow during body evaluation should honor `yield *` statements. 7 features: [generators] 8 ---*/ 9 10 function* values() { 11 yield 1; 12 yield 1; 13 } 14 var dataIterator = values(); 15 var controlIterator = (function*() { 16 for (var x of dataIterator) { 17 i++; 18 yield * values(); 19 j++; 20 } 21 22 k++; 23 })(); 24 var i = 0; 25 var j = 0; 26 var k = 0; 27 28 controlIterator.next(); 29 assert.sameValue(i, 1, 'First iteration: pre-yield'); 30 assert.sameValue(j, 0, 'First iteration: post-yield'); 31 assert.sameValue(k, 0, 'First iteration: post-for-of'); 32 33 controlIterator.next(); 34 assert.sameValue(i, 1, 'Second iteration: pre-yield'); 35 assert.sameValue(j, 0, 'Second iteration: post-yield'); 36 assert.sameValue(k, 0, 'Second iteration: post-for-of'); 37 38 controlIterator.next(); 39 assert.sameValue(i, 2, 'Third iteration: pre-yield'); 40 assert.sameValue(j, 1, 'Third iteration: post-yield'); 41 assert.sameValue(k, 0, 'Third iteration: post-for-of'); 42 43 controlIterator.next(); 44 assert.sameValue(i, 2, 'Fourth iteration: pre-yield'); 45 assert.sameValue(j, 1, 'Fourth iteration: post-yield'); 46 assert.sameValue(k, 0, 'Fourth iteration: post-for-of'); 47 48 controlIterator.next(); 49 assert.sameValue(i, 2, 'Fifth iteration: pre-yield'); 50 assert.sameValue(j, 2, 'Fifth iteration: post-yield'); 51 assert.sameValue(k, 1, 'Fifth iteration: post-for-of'); 52 53 reportCompare(0, 0);