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