yield-from-catch.js (1452B)
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 the `catch` block of `try` statements. 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 throw new Error(); 20 throw new Test262Error('This code is unreachable.'); 21 } catch (err) { 22 i++; 23 yield; 24 j++; 25 } 26 k++; 27 } 28 29 l++; 30 })(); 31 var i = 0; 32 var j = 0; 33 var k = 0; 34 var l = 0; 35 36 controlIterator.next(); 37 assert.sameValue(i, 1, 'First iteration: pre-yield'); 38 assert.sameValue(j, 0, 'First iteration: post-yield'); 39 assert.sameValue(k, 0, 'First iteration: post-try'); 40 assert.sameValue(l, 0, 'First iteration: post-for-of'); 41 42 controlIterator.next(); 43 assert.sameValue(i, 2, 'Second iteration: pre-yield'); 44 assert.sameValue(j, 1, 'Second iteration: post-yield'); 45 assert.sameValue(k, 1, 'Second iteration: post-try'); 46 assert.sameValue(l, 0, 'Second iteration: post-for-of'); 47 48 controlIterator.next(); 49 assert.sameValue(i, 2, 'Third iteration: pre-yield'); 50 assert.sameValue(j, 2, 'Third iteration: post-yield'); 51 assert.sameValue(k, 2, 'Third iteration: post-try'); 52 assert.sameValue(l, 1, 'Third iteration: post-for-of'); 53 54 reportCompare(0, 0);