Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/async-gen-private-method/yield-star-next-call-value-get-abrupt.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/async-generators/yield-star-next-call-value-get-abrupt.case
4 // - src/async-generators/default/async-class-decl-private-method.template
5 /*---
6 description: Abrupt completion while getting value (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 6. Repeat
26 a. If received.[[Type]] is normal, then
27 ii. Let innerResult be ? Invoke(iterator, "next",
28 « received.[[Value]] »).
29 iii. If generatorKind is async, then set innerResult to
30 ? Await(innerResult).
31 ...
32 vi. If done is true, then
33 1. Return ? IteratorValue(innerResult).
34 ...
35
36 ---*/
37 var reason = {};
38 var obj = {
39 get [Symbol.iterator]() {
40 throw new Test262Error('it should not get Symbol.iterator');
41 },
42 [Symbol.asyncIterator]() {
43 return {
44 next() {
45 return {
46 done: true,
47 get value() {
48 throw reason;
49 }
50 };
51 }
52 };
53 }
54 };
55
56
57
58 var callCount = 0;
59
60 class C {
61 async *#gen() {
62 callCount += 1;
63 yield* obj;
64 throw new Test262Error('abrupt completion closes iter');
65
66 }
67 get gen() { return this.#gen; }
68 }
69
70 const c = new C();
71
72 // Test the private fields do not appear as properties before set to value
73 assert(
74 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
75 "#gen does not appear as an own property on C prototype"
76 );
77 assert(
78 !Object.prototype.hasOwnProperty.call(C, "#gen"),
79 "#gen does not appear as an own property on C constructor"
80 );
81 assert(
82 !Object.prototype.hasOwnProperty.call(c, "#gen"),
83 "#gen does not appear as an own property on C instance"
84 );
85
86 var iter = c.gen();
87
88 iter.next().then(() => {
89 throw new Test262Error('Promise incorrectly fulfilled.');
90 }, v => {
91 assert.sameValue(v, reason, "reject reason");
92
93 iter.next().then(({ done, value }) => {
94 assert.sameValue(done, true, 'the iterator is completed');
95 assert.sameValue(value, undefined, 'value is undefined');
96 }).then($DONE, $DONE);
97 }).catch($DONE);
98
99 assert.sameValue(callCount, 1);
100
101 // Test the private fields do not appear as properties after set to value
102 assert(
103 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
104 "#gen does not appear as an own property on C prototype"
105 );
106 assert(
107 !Object.prototype.hasOwnProperty.call(C, "#gen"),
108 "#gen does not appear as an own property on C constructor"
109 );
110 assert(
111 !Object.prototype.hasOwnProperty.call(c, "#gen"),
112 "#gen does not appear as an own property on C instance"
113 );