| 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 expression 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] }, |
| 15 |
*g3() { {yield} }, |
| 16 |
*g4() { yield, yield; }, |
| 17 |
*g5() { (yield) ? yield : yield; } |
| 18 |
}; |
| 19 |
|
| 20 |
iter = obj.g1(); |
| 21 |
result = iter.next(); |
| 22 |
assert.sameValue( |
| 23 |
result.value, undefined, 'Within grouping operator: result `value`' |
| 24 |
); |
| 25 |
assert.sameValue( |
| 26 |
result.done, false, 'Within grouping operator: result `done` flag' |
| 27 |
); |
| 28 |
result = iter.next(); |
| 29 |
assert.sameValue( |
| 30 |
result.value, undefined, 'Following grouping operator: result `value`' |
| 31 |
); |
| 32 |
assert.sameValue( |
| 33 |
result.done, true, 'Following grouping operator: result `done` flag' |
| 34 |
); |
| 35 |
|
| 36 |
iter = obj.g2(); |
| 37 |
result = iter.next(); |
| 38 |
assert.sameValue( |
| 39 |
result.value, undefined, 'Within array literal: result `value`' |
| 40 |
); |
| 41 |
assert.sameValue( |
| 42 |
result.done, false, 'Within array literal: result `done` flag' |
| 43 |
); |
| 44 |
result = iter.next(); |
| 45 |
assert.sameValue( |
| 46 |
result.value, undefined, 'Following array literal: result `value`' |
| 47 |
); |
| 48 |
assert.sameValue( |
| 49 |
result.done, true, 'Following array literal: result `done` flag' |
| 50 |
); |
| 51 |
|
| 52 |
iter = obj.g3(); |
| 53 |
result = iter.next(); |
| 54 |
assert.sameValue( |
| 55 |
result.value, undefined, 'Within object literal: result `value`' |
| 56 |
); |
| 57 |
assert.sameValue( |
| 58 |
result.done, false, 'Within object literal: result `done` flag' |
| 59 |
); |
| 60 |
result = iter.next(); |
| 61 |
assert.sameValue( |
| 62 |
result.value, undefined, 'Following object literal: result `value`' |
| 63 |
); |
| 64 |
assert.sameValue( |
| 65 |
result.done, true, 'Following object literal: result `done` flag' |
| 66 |
); |
| 67 |
|
| 68 |
iter = obj.g4(); |
| 69 |
result = iter.next(); |
| 70 |
assert.sameValue( |
| 71 |
result.value, |
| 72 |
undefined, |
| 73 |
'First expression in comma expression: result `value`' |
| 74 |
); |
| 75 |
assert.sameValue( |
| 76 |
result.done, |
| 77 |
false, |
| 78 |
'First expression in comma expression: result `done` flag' |
| 79 |
); |
| 80 |
result = iter.next(); |
| 81 |
assert.sameValue( |
| 82 |
result.value, |
| 83 |
undefined, |
| 84 |
'Second expression in comma expression: result `value`' |
| 85 |
); |
| 86 |
assert.sameValue( |
| 87 |
result.done, |
| 88 |
false, |
| 89 |
'Second expression in comma expression: result `done` flag' |
| 90 |
); |
| 91 |
result = iter.next(); |
| 92 |
assert.sameValue( |
| 93 |
result.value, undefined, 'Following comma expression: result `value`' |
| 94 |
); |
| 95 |
assert.sameValue( |
| 96 |
result.done, true, 'Following comma expression: result `done` flag' |
| 97 |
); |
| 98 |
|
| 99 |
iter = obj.g5(); |
| 100 |
result = iter.next(); |
| 101 |
assert.sameValue( |
| 102 |
result.value, |
| 103 |
undefined, |
| 104 |
'Conditional expression in conditional operator: result `value`' |
| 105 |
); |
| 106 |
assert.sameValue( |
| 107 |
result.done, |
| 108 |
false, |
| 109 |
'Conditional expression in conditional operator: result `done` flag' |
| 110 |
); |
| 111 |
result = iter.next(); |
| 112 |
assert.sameValue( |
| 113 |
result.value, |
| 114 |
undefined, |
| 115 |
'Branch in conditional operator: result `value`' |
| 116 |
); |
| 117 |
assert.sameValue( |
| 118 |
result.done, |
| 119 |
false, |
| 120 |
'Branch in conditional operator: result `done` flag' |
| 121 |
); |
| 122 |
result = iter.next(); |
| 123 |
assert.sameValue( |
| 124 |
result.value, undefined, 'Following conditional operator: result `value`' |
| 125 |
); |
| 126 |
assert.sameValue( |
| 127 |
result.done, true, 'Following conditional operator: result `done` flag' |
| 128 |
); |