Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/class/fields-multiple-definitions-private-names.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/class-fields/private-names.case
3 // - src/class-fields/productions/cls-expr-multiple-definitions.template
4 /*---
5 description: static literal private names (multiple fields definitions)
6 esid: prod-FieldDefinition
7 features: [class-fields-private, class, class-fields-public]
8 flags: [generated]
9 includes: [propertyHelper.js]
10 info: |
11 ClassElement:
12 ...
13 FieldDefinition ;
14
15 FieldDefinition:
16 ClassElementName Initializer_opt
17
18 ClassElementName:
19 PrivateName
20
21 PrivateName:
22 #IdentifierName
23
24 ---*/
25
26
27 var C = class {
28 foo = "foobar";
29 m() { return 42 }
30 #x; #y
31 m2() { return 39 }
32 bar = "barbaz";
33 x() {
34 this.#x = 42;
35 return this.#x;
36 }
37 y() {
38 this.#y = 43;
39 return this.#y;
40 }
41 }
42
43 var c = new C();
44
45 assert.sameValue(c.m(), 42);
46 assert.sameValue(Object.hasOwnProperty.call(c, "m"), false);
47 assert.sameValue(c.m, C.prototype.m);
48
49 verifyProperty(C.prototype, "m", {
50 enumerable: false,
51 configurable: true,
52 writable: true,
53 });
54
55 assert.sameValue(c.m2(), 39);
56 assert.sameValue(Object.hasOwnProperty.call(c, "m2"), false);
57 assert.sameValue(c.m2, C.prototype.m2);
58
59 verifyProperty(C.prototype, "m2", {
60 enumerable: false,
61 configurable: true,
62 writable: true,
63 });
64
65 assert.sameValue(c.foo, "foobar");
66 assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false);
67 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false);
68
69 verifyProperty(c, "foo", {
70 value: "foobar",
71 enumerable: true,
72 configurable: true,
73 writable: true,
74 });
75
76 assert.sameValue(c.bar, "barbaz");
77 assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false);
78 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false);
79
80 verifyProperty(c, "bar", {
81 value: "barbaz",
82 enumerable: true,
83 configurable: true,
84 writable: true,
85 });
86
87 // Test the private fields do not appear as properties before set to value
88 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#x"), false, "test 1");
89 assert.sameValue(Object.hasOwnProperty.call(C, "#x"), false, "test 2");
90 assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 3");
91
92 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#y"), false, "test 4");
93 assert.sameValue(Object.hasOwnProperty.call(C, "#y"), false, "test 5");
94 assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 6");
95
96 // Test if private fields can be sucessfully accessed and set to value
97 assert.sameValue(c.x(), 42, "test 7");
98 assert.sameValue(c.y(), 43, "test 8");
99
100 // Test the private fields do not appear as properties before after set to value
101 assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 9");
102 assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 10");