yield-as-statement.js (1227B)
1 // Copyright (C) 2013 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: > 6 `yield` is a valid statement within generator function bodies. 7 es6id: 14.4 8 features: [generators] 9 ---*/ 10 11 var iter, result; 12 function* g1() { yield; } 13 function* g2() { yield 1; } 14 15 iter = g1(); 16 result = iter.next(); 17 assert.sameValue( 18 result.value, undefined, 'Without right-hand-side: first result `value`' 19 ); 20 assert.sameValue( 21 result.done, false, 'Without right-hand-side: first result `done` flag' 22 ); 23 result = iter.next(); 24 assert.sameValue( 25 result.value, undefined, 'Without right-hand-side: second result `value`' 26 ); 27 assert.sameValue( 28 result.done, true, 'Without right-hand-eside: second result `done` flag' 29 ); 30 31 iter = g2(); 32 result = iter.next(); 33 assert.sameValue( 34 result.value, 1, 'With right-hand-side: first result `value`' 35 ); 36 assert.sameValue( 37 result.done, false, 'With right-hand-side: first result `done` flag' 38 ); 39 result = iter.next(); 40 assert.sameValue( 41 result.value, undefined, 'With right-hand-side: second result `value`' 42 ); 43 assert.sameValue( 44 result.done, true, 'With right-hand-eside: second result `done` flag' 45 ); 46 47 reportCompare(0, 0);