Debian Codegraph @

js/src/tests/test262/language/expressions/class/elements/after-same-line-static-async-gen-static-private-methods-with-fields.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/class-elements/static-private-methods-with-fields.case
4 // - src/class-elements/productions/cls-expr-after-same-line-static-async-gen.template
5 /*---
6 description: static private methods with fields (field definitions after a static async generator in the same line)
7 esid: prod-FieldDefinition
8 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public, async-iteration]
9 flags: [generated, async]
10 includes: [propertyHelper.js]
11 info: |
12 ClassElement :
13 ...
14 static FieldDefinition ;
15
16 FieldDefinition :
17 ClassElementName Initializer_opt
18
19 ClassElementName :
20 PrivateName
21
22 PrivateName :
23 # IdentifierName
24
25 ---*/
26
27
28 var C = class {
29 static async *m() { return 42; } static #xVal; static #yVal;
30 static #x(value) {
31 this.#xVal = value;
32 return this.#xVal;
33 }
34 static #y(value) {
35 this.#yVal = value;
36 return this.#yVal;
37 }
38 static x() {
39 return this.#x(42);
40 }
41 static y() {
42 return this.#y(43);
43 }
44 }
45
46 var c = new C();
47
48 assert(
49 !Object.prototype.hasOwnProperty.call(c, "m"),
50 "m doesn't appear as an own property on the C instance"
51 );
52 assert(
53 !Object.prototype.hasOwnProperty.call(C.prototype, "m"),
54 "m doesn't appear as an own property on the C prototype"
55 );
56
57 verifyProperty(C, "m", {
58 enumerable: false,
59 configurable: true,
60 writable: true,
61 }, {restore: true});
62
63 C.m().next().then(function(v) {
64 assert.sameValue(v.value, 42);
65 assert.sameValue(v.done, true);
66
67 function assertions() {
68 // Cover $DONE handler for async cases.
69 function $DONE(error) {
70 if (error) {
71 throw new Test262Error('Test262:AsyncTestFailure')
72 }
73 }
74 // Test the private methods do not appear as properties before set to value
75 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
76 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
77 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
78
79 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
80 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
81 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
82
83 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
84 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
85 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
86
87 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
88 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
89 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
90
91 // Test if private fields can be sucessfully accessed and set to value
92 assert.sameValue(C.x(), 42, "test 13");
93 assert.sameValue(C.y(), 43, "test 14");
94
95 // Test the private fields do not appear as properties before after set to value
96 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
97 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
98
99 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
100 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
101 }
102
103 return Promise.resolve(assertions());
104 }).then($DONE, $DONE);