| 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 |
features: [generators] |
| 8 |
es6id: 14.4 |
| 9 |
---*/ |
| 10 |
|
| 11 |
var iter, result; |
| 12 |
var obj = { |
| 13 |
*g1() { yield; }, |
| 14 |
*g2() { yield 1; } |
| 15 |
}; |
| 16 |
|
| 17 |
iter = obj.g1(); |
| 18 |
result = iter.next(); |
| 19 |
assert.sameValue( |
| 20 |
result.value, undefined, 'Without right-hand-side: first result `value`' |
| 21 |
); |
| 22 |
assert.sameValue( |
| 23 |
result.done, false, 'Without right-hand-side: first result `done` flag' |
| 24 |
); |
| 25 |
result = iter.next(); |
| 26 |
assert.sameValue( |
| 27 |
result.value, undefined, 'Without right-hand-side: second result `value`' |
| 28 |
); |
| 29 |
assert.sameValue( |
| 30 |
result.done, true, 'Without right-hand-eside: second result `done` flag' |
| 31 |
); |
| 32 |
|
| 33 |
iter = obj.g2(); |
| 34 |
result = iter.next(); |
| 35 |
assert.sameValue( |
| 36 |
result.value, 1, 'With right-hand-side: first result `value`' |
| 37 |
); |
| 38 |
assert.sameValue( |
| 39 |
result.done, false, 'With right-hand-side: first result `done` flag' |
| 40 |
); |
| 41 |
result = iter.next(); |
| 42 |
assert.sameValue( |
| 43 |
result.value, undefined, 'With right-hand-side: second result `value`' |
| 44 |
); |
| 45 |
assert.sameValue( |
| 46 |
result.done, true, 'With right-hand-eside: second result `done` flag' |
| 47 |
); |