Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/new-sc-line-gen-private-names.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/class-elements/private-names.case
3 // - src/class-elements/productions/cls-decl-new-sc-line-generator.template
4 /*---
5 description: private names (field definitions followed by a method in a new line with a semicolon)
6 esid: prod-FieldDefinition
7 features: [class-fields-private, class, class-fields-public, generators]
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 class C {
28 #x; #y;
29 *m() { return 42; }
30 x() {
31 this.#x = 42;
32 return this.#x;
33 }
34 y() {
35 this.#y = 43;
36 return this.#y;
37 }
38 }
39
40 var c = new C();
41
42 assert.sameValue(c.m().next().value, 42);
43 assert.sameValue(c.m, C.prototype.m);
44 assert(
45 !Object.prototype.hasOwnProperty.call(c, "m"),
46 "m doesn't appear as an own property on the C instance"
47 );
48
49 verifyProperty(C.prototype, "m", {
50 enumerable: false,
51 configurable: true,
52 writable: true,
53 });
54
55 // Test the private fields do not appear as properties before set to value
56 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
57 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
58 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
59
60 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
61 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
62 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
63
64 // Test if private fields can be sucessfully accessed and set to value
65 assert.sameValue(c.x(), 42, "test 7");
66 assert.sameValue(c.y(), 43, "test 8");
67
68 // Test the private fields do not appear as properties before after set to value
69 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 9");
70 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 10");
71
72 reportCompare(0, 0);