| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/generators/yield-spread-obj.case |
| 3 |
// - src/generators/default/class-decl-private-method.template |
| 4 |
/*--- |
| 5 |
description: Use yield value in a object spread position (Generator private method as a ClassDeclaration element) |
| 6 |
esid: prod-GeneratorPrivateMethod |
| 7 |
features: [object-spread, generators, class-methods-private] |
| 8 |
flags: [generated] |
| 9 |
info: | |
| 10 |
ClassElement : |
| 11 |
PrivateMethodDefinition |
| 12 |
|
| 13 |
MethodDefinition : |
| 14 |
GeneratorMethod |
| 15 |
|
| 16 |
14.4 Generator Function Definitions |
| 17 |
|
| 18 |
GeneratorMethod : |
| 19 |
* PropertyName ( UniqueFormalParameters ) { GeneratorBody } |
| 20 |
|
| 21 |
|
| 22 |
Spread Properties |
| 23 |
|
| 24 |
PropertyDefinition[Yield]: |
| 25 |
(...) |
| 26 |
...AssignmentExpression[In, ?Yield] |
| 27 |
|
| 28 |
---*/ |
| 29 |
|
| 30 |
var callCount = 0; |
| 31 |
|
| 32 |
class C { |
| 33 |
*#gen() { |
| 34 |
callCount += 1; |
| 35 |
yield { |
| 36 |
...yield, |
| 37 |
y: 1, |
| 38 |
...yield yield, |
| 39 |
}; |
| 40 |
} |
| 41 |
get gen() { return this.#gen; } |
| 42 |
} |
| 43 |
|
| 44 |
const c = new C(); |
| 45 |
|
| 46 |
// Test the private fields do not appear as properties before set to value |
| 47 |
assert( |
| 48 |
!Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), |
| 49 |
"Private field '#gen' does not appear as an own property on C prototype" |
| 50 |
); |
| 51 |
assert( |
| 52 |
!Object.prototype.hasOwnProperty.call(C, "#gen"), |
| 53 |
"Private field '#gen' does not appear as an own property on C constructor" |
| 54 |
); |
| 55 |
assert( |
| 56 |
!Object.prototype.hasOwnProperty.call(c, "#gen"), |
| 57 |
"Private field '#gen' does not appear as an own property on C instance" |
| 58 |
); |
| 59 |
|
| 60 |
var iter = c.gen(); |
| 61 |
|
| 62 |
iter.next(); |
| 63 |
iter.next({ x: 42 }); |
| 64 |
iter.next({ x: 'lol' }); |
| 65 |
var item = iter.next({ y: 39 }); |
| 66 |
|
| 67 |
assert.sameValue(item.value.x, 42); |
| 68 |
assert.sameValue(item.value.y, 39); |
| 69 |
assert.sameValue(Object.keys(item.value).length, 2); |
| 70 |
assert.sameValue(item.done, false); |
| 71 |
|
| 72 |
assert.sameValue(callCount, 1); |
| 73 |
|
| 74 |
// Test the private fields do not appear as properties after set to value |
| 75 |
assert( |
| 76 |
!Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), |
| 77 |
"Private field '#gen' does not appear as an own property on C prototype" |
| 78 |
); |
| 79 |
assert( |
| 80 |
!Object.prototype.hasOwnProperty.call(C, "#gen"), |
| 81 |
"Private field '#gen' does not appear as an own property on C constructor" |
| 82 |
); |
| 83 |
assert( |
| 84 |
!Object.prototype.hasOwnProperty.call(c, "#gen"), |
| 85 |
"Private field '#gen' does not appear as an own property on C instance" |
| 86 |
); |
| 87 |
|
| 88 |
reportCompare(0, 0); |