Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/wrapped-in-sc-static-private-methods-with-fields.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/class-elements/static-private-methods-with-fields.case
3 // - src/class-elements/productions/cls-decl-wrapped-in-sc.template
4 /*---
5 description: static private methods with fields (fields definition wrapped in semicolons)
6 esid: prod-FieldDefinition
7 features: [class-static-methods-private, class-static-fields-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 #xVal; static #yVal;;;;;;;
29 ;;;;
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 // Test the private methods do not appear as properties before set to value
49 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
50 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
51 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
52
53 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
54 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
55 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
56
57 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
58 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
59 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
60
61 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
62 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
63 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
64
65 // Test if private fields can be sucessfully accessed and set to value
66 assert.sameValue(C.x(), 42, "test 13");
67 assert.sameValue(C.y(), 43, "test 14");
68
69 // Test the private fields do not appear as properties before after set to value
70 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
71 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
72
73 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
74 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
75
76 reportCompare(0, 0);