yield-from-try.js (1338B)
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 within 7 `try` blocks. 8 features: [generators] 9 ---*/ 10 11 function* values() { 12 yield 1; 13 yield 1; 14 } 15 var dataIterator = values(); 16 var controlIterator = (function*() { 17 for (var x of dataIterator) { 18 try { 19 i++; 20 yield; 21 j++; 22 } catch (err) {} 23 k++; 24 } 25 26 l++; 27 })(); 28 var i = 0; 29 var j = 0; 30 var k = 0; 31 var l = 0; 32 33 controlIterator.next(); 34 assert.sameValue(i, 1, 'First iteration: pre-yield'); 35 assert.sameValue(j, 0, 'First iteration: post-yield'); 36 assert.sameValue(k, 0, 'First iteration: post-try'); 37 assert.sameValue(l, 0, 'First iteration: post-for-of'); 38 39 controlIterator.next(); 40 assert.sameValue(i, 2, 'Second iteration: pre-yield'); 41 assert.sameValue(j, 1, 'Second iteration: post-yield'); 42 assert.sameValue(k, 1, 'Second iteration: post-try'); 43 assert.sameValue(l, 0, 'Second iteration: post-for-of'); 44 45 controlIterator.next(); 46 assert.sameValue(i, 2, 'Third iteration: pre-yield'); 47 assert.sameValue(j, 2, 'Third iteration: post-yield'); 48 assert.sameValue(k, 2, 'Third iteration: post-try'); 49 assert.sameValue(l, 1, 'Third iteration: post-for-of'); 50 51 reportCompare(0, 0);