Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/regular-definitions-static-private-methods.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/class-elements/static-private-methods.case
3 // - src/class-elements/productions/cls-decl-regular-definitions.template
4 /*---
5 description: static private methods (regular fields defintion)
6 esid: prod-FieldDefinition
7 features: [class-static-methods-private, class, class-fields-public]
8 flags: [generated]
9 info: |
10 ClassElement :
11 ...
12 static FieldDefinition ;
13
14 FieldDefinition :
15 ClassElementName Initializer_opt
16
17 ClassElementName :
18 PrivateName
19
20 PrivateName :
21 # IdentifierName
22
23 ---*/
24
25
26 class C {
27
28 static #x(value) {
29 return value / 2;
30 }
31 static #y(value) {
32 return value * 2;
33 }
34 static x() {
35 return this.#x(84);
36 }
37 static y() {
38 return this.#y(43);
39 }
40 }
41
42 var c = new C();
43
44 // Test the private methods do not appear as properties before set to value
45 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
46 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
47 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
48
49 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
50 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
51 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
52
53 // Test if private fields can be sucessfully accessed and set to value
54 assert.sameValue(C.x(), 42, "test 7");
55 assert.sameValue(C.y(), 86, "test 8");
56
57 // Test the private fields do not appear as properties before after set to value
58 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9");
59 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10");
60
61 reportCompare(0, 0);