| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/class-fields/private-names.case |
| 3 |
// - src/class-fields/productions/cls-expr-multiple-stacked-definitions.template |
| 4 |
/*--- |
| 5 |
description: static literal private names (multiple stacked fields definitions through ASI) |
| 6 |
esid: prod-FieldDefinition |
| 7 |
features: [class-fields-private, class, class-fields-public] |
| 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 |
var C = class { |
| 28 |
#x; #y |
| 29 |
foo = "foobar" |
| 30 |
bar = "barbaz"; |
| 31 |
x() { |
| 32 |
this.#x = 42; |
| 33 |
return this.#x; |
| 34 |
} |
| 35 |
y() { |
| 36 |
this.#y = 43; |
| 37 |
return this.#y; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
var c = new C(); |
| 42 |
|
| 43 |
assert.sameValue(c.foo, "foobar"); |
| 44 |
assert.sameValue(Object.hasOwnProperty.call(C, "foo"), false); |
| 45 |
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "foo"), false); |
| 46 |
|
| 47 |
verifyProperty(c, "foo", { |
| 48 |
value: "foobar", |
| 49 |
enumerable: true, |
| 50 |
configurable: true, |
| 51 |
writable: true, |
| 52 |
}); |
| 53 |
|
| 54 |
assert.sameValue(c.bar, "barbaz"); |
| 55 |
assert.sameValue(Object.hasOwnProperty.call(C, "bar"), false); |
| 56 |
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "bar"), false); |
| 57 |
|
| 58 |
verifyProperty(c, "bar", { |
| 59 |
value: "barbaz", |
| 60 |
enumerable: true, |
| 61 |
configurable: true, |
| 62 |
writable: true, |
| 63 |
}); |
| 64 |
|
| 65 |
// Test the private fields do not appear as properties before set to value |
| 66 |
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#x"), false, "test 1"); |
| 67 |
assert.sameValue(Object.hasOwnProperty.call(C, "#x"), false, "test 2"); |
| 68 |
assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 3"); |
| 69 |
|
| 70 |
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#y"), false, "test 4"); |
| 71 |
assert.sameValue(Object.hasOwnProperty.call(C, "#y"), false, "test 5"); |
| 72 |
assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 6"); |
| 73 |
|
| 74 |
// Test if private fields can be sucessfully accessed and set to value |
| 75 |
assert.sameValue(c.x(), 42, "test 7"); |
| 76 |
assert.sameValue(c.y(), 43, "test 8"); |
| 77 |
|
| 78 |
// Test the private fields do not appear as properties before after set to value |
| 79 |
assert.sameValue(Object.hasOwnProperty.call(c, "#x"), false, "test 9"); |
| 80 |
assert.sameValue(Object.hasOwnProperty.call(c, "#y"), false, "test 10"); |