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