Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/gen-private-method-static/yield-spread-arr-single.js

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