Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/async-gen-private-method/yield-promise-reject-next-for-await-of-async-iterator.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/async-generators/yield-promise-reject-next-for-await-of-async-iterator.case
4 // - src/async-generators/default/async-class-decl-private-method.template
5 /*---
6 description: yield * [Promise.reject(value)] is treated as throw value (Async Generator method as a ClassDeclaration element)
7 esid: prod-AsyncGeneratorPrivateMethod
8 features: [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 let error = new Error();
24 async function * readFile() {
25 yield Promise.reject(error);
26 yield "unreachable";
27 }
28
29
30 var callCount = 0;
31
32 class C {
33 async *#gen() {
34 callCount += 1;
35 for await (let line of readFile()) {
36 yield line;
37 }
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 "#gen does not appear as an own property on C prototype"
48 );
49 assert(
50 !Object.prototype.hasOwnProperty.call(C, "#gen"),
51 "#gen does not appear as an own property on C constructor"
52 );
53 assert(
54 !Object.prototype.hasOwnProperty.call(c, "#gen"),
55 "#gen does not appear as an own property on C instance"
56 );
57
58 var iter = c.gen();
59
60 iter.next().then(() => {
61 throw new Test262Error("Promise incorrectly resolved.");
62 }, rejectValue => {
63
64 // yield Promise.reject(error);
65 assert.sameValue(rejectValue, error);
66
67 iter.next().then(({done, value}) => {
68 // iter is closed now.
69 assert.sameValue(done, true, "The value of IteratorResult.done is `true`");
70 assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`");
71 }).then($DONE, $DONE);
72 }).catch($DONE);
73
74 assert.sameValue(callCount, 1);
75
76 // Test the private fields do not appear as properties after set to value
77 assert(
78 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
79 "#gen does not appear as an own property on C prototype"
80 );
81 assert(
82 !Object.prototype.hasOwnProperty.call(C, "#gen"),
83 "#gen does not appear as an own property on C constructor"
84 );
85 assert(
86 !Object.prototype.hasOwnProperty.call(c, "#gen"),
87 "#gen does not appear as an own property on C instance"
88 );