Debian Codegraph @

js/src/tests/test262/language/expressions/class/elements/new-sc-line-method-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-expr-new-sc-line-method.template
4 /*---
5 description: static private methods (field definitions followed by a method in a new line with a semicolon)
6 esid: prod-FieldDefinition
7 features: [class-static-methods-private, class, class-fields-public]
8 flags: [generated]
9 includes: [propertyHelper.js]
10 info: |
11 ClassElement :
12 ...
13 static 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 ;
29 m() { return 42; }
30 static #x(value) {
31 return value / 2;
32 }
33 static #y(value) {
34 return value * 2;
35 }
36 static x() {
37 return this.#x(84);
38 }
39 static y() {
40 return this.#y(43);
41 }
42 }
43
44 var c = new C();
45
46 assert.sameValue(c.m(), 42);
47 assert.sameValue(c.m, C.prototype.m);
48 assert(
49 !Object.prototype.hasOwnProperty.call(c, "m"),
50 "m doesn't appear as an own property on the C instance"
51 );
52
53 verifyProperty(C.prototype, "m", {
54 enumerable: false,
55 configurable: true,
56 writable: true,
57 });
58
59 // Test the private methods do not appear as properties before set to value
60 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
61 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
62 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
63
64 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
65 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
66 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
67
68 // Test if private fields can be sucessfully accessed and set to value
69 assert.sameValue(C.x(), 42, "test 7");
70 assert.sameValue(C.y(), 86, "test 8");
71
72 // Test the private fields do not appear as properties before after set to value
73 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9");
74 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10");
75
76 reportCompare(0, 0);