Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/class/fields-regular-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-regular-definitions.template
4 /*---
5 description: static literal private names (regular fields defintion)
6 esid: prod-FieldDefinition
7 features: [class-fields-private, class, class-fields-public]
8 flags: [generated]
9 info: |
10 ClassElement:
11 ...
12 FieldDefinition ;
13
14 FieldDefinition:
15 ClassElementName Initializer_opt
16
17 ClassElementName:
18 PrivateName
19
20 PrivateName:
21 #IdentifierName
22
23 ---*/
24
25
26 var C = class {
27 #x; #y
28 x() {
29 this.#x = 42;
30 return this.#x;
31 }
32 y() {
33 this.#y = 43;
34 return this.#y;
35 }
36 }
37
38 var c = new C();
39
40 // Test the private fields do not appear as properties before set to value
41 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#x"), false, "test 1");
42 assert.sameValue(Object.hasOwnProperty.call(C, "#x"), false, "test 2");
43 assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 3");
44
45 assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#y"), false, "test 4");
46 assert.sameValue(Object.hasOwnProperty.call(C, "#y"), false, "test 5");
47 assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 6");
48
49 // Test if private fields can be sucessfully accessed and set to value
50 assert.sameValue(c.x(), 42, "test 7");
51 assert.sameValue(c.y(), 43, "test 8");
52
53 // Test the private fields do not appear as properties before after set to value
54 assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 9");
55 assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 10");