Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/async-gen-private-method/yield-star-getiter-async-undefined-sync-get-abrupt.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/async-generators/yield-star-getiter-async-undefined-sync-get-abrupt.case
4 // - src/async-generators/default/async-class-decl-private-method.template
5 /*---
6 description: Abrupt completion while getting @@iterator after undefined @@asyncIterator (Async Generator method as a ClassDeclaration element)
7 esid: prod-AsyncGeneratorPrivateMethod
8 features: [Symbol.iterator, Symbol.asyncIterator, async-iteration, class-methods-private]
9 flags: [generated, async]
10 info: |
11 ClassElement :
12 PrivateMethodDefinition
13
14 MethodDefinition :
15 AsyncGeneratorMethod
16
17 Async Generator Function Definitions
18
19 AsyncGeneratorMethod :
20 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
21
22
23 YieldExpression: yield * AssignmentExpression
24
25 1. Let exprRef be the result of evaluating AssignmentExpression.
26 2. Let value be ? GetValue(exprRef).
27 3. Let generatorKind be ! GetGeneratorKind().
28 4. Let iterator be ? GetIterator(value, generatorKind).
29 ...
30
31 GetIterator ( obj [ , hint ] )
32
33 ...
34 3. If hint is async,
35 a. Set method to ? GetMethod(obj, @@asyncIterator).
36 b. If method is undefined,
37 i. Let syncMethod be ? GetMethod(obj, @@iterator).
38 ...
39
40 GetMethod ( V, P )
41
42 ...
43 2. Let func be ? GetV(V, P).
44 ...
45
46 ---*/
47 var calls = 0;
48 var reason = {};
49 var obj = {
50 get [Symbol.iterator]() {
51 throw reason;
52 },
53 get [Symbol.asyncIterator]() {
54 calls += 1;
55 return undefined;
56 }
57 };
58
59
60
61 var callCount = 0;
62
63 class C {
64 async *#gen() {
65 callCount += 1;
66 yield* obj;
67 throw new Test262Error('abrupt completion closes iter');
68
69 }
70 get gen() { return this.#gen; }
71 }
72
73 const c = new C();
74
75 // Test the private fields do not appear as properties before set to value
76 assert(
77 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
78 "#gen does not appear as an own property on C prototype"
79 );
80 assert(
81 !Object.prototype.hasOwnProperty.call(C, "#gen"),
82 "#gen does not appear as an own property on C constructor"
83 );
84 assert(
85 !Object.prototype.hasOwnProperty.call(c, "#gen"),
86 "#gen does not appear as an own property on C instance"
87 );
88
89 var iter = c.gen();
90
91 iter.next().then(() => {
92 throw new Test262Error('Promise incorrectly fulfilled.');
93 }, v => {
94 assert.sameValue(v, reason, 'reject reason');
95 assert.sameValue(calls, 1);
96
97 iter.next().then(({ done, value }) => {
98 assert.sameValue(done, true, 'the iterator is completed');
99 assert.sameValue(value, undefined, 'value is undefined');
100 }).then($DONE, $DONE);
101 }).catch($DONE);
102
103 assert.sameValue(callCount, 1);
104
105 // Test the private fields do not appear as properties after set to value
106 assert(
107 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
108 "#gen does not appear as an own property on C prototype"
109 );
110 assert(
111 !Object.prototype.hasOwnProperty.call(C, "#gen"),
112 "#gen does not appear as an own property on C constructor"
113 );
114 assert(
115 !Object.prototype.hasOwnProperty.call(c, "#gen"),
116 "#gen does not appear as an own property on C instance"
117 );