| 1 |
// |reftest| async |
| 2 |
// This file was procedurally generated from the following sources: |
| 3 |
// - src/class-elements/static-private-fields.case |
| 4 |
// - src/class-elements/productions/cls-decl-after-same-line-static-async-method.template |
| 5 |
/*--- |
| 6 |
description: static private fields (field definitions after a static async method in the same line) |
| 7 |
esid: prod-FieldDefinition |
| 8 |
features: [class-static-fields-private, class, class-fields-public, async-functions] |
| 9 |
flags: [generated, async] |
| 10 |
includes: [propertyHelper.js] |
| 11 |
info: | |
| 12 |
ClassElement : |
| 13 |
... |
| 14 |
static FieldDefinition ; |
| 15 |
|
| 16 |
FieldDefinition : |
| 17 |
ClassElementName Initializer_opt |
| 18 |
|
| 19 |
ClassElementName : |
| 20 |
PrivateName |
| 21 |
|
| 22 |
PrivateName : |
| 23 |
# IdentifierName |
| 24 |
|
| 25 |
---*/ |
| 26 |
|
| 27 |
|
| 28 |
class C { |
| 29 |
static async m() { return 42; } static #x; static #y; |
| 30 |
static x() { |
| 31 |
this.#x = 42; |
| 32 |
return this.#x; |
| 33 |
} |
| 34 |
static y() { |
| 35 |
this.#y = 43; |
| 36 |
return this.#y; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
var c = new C(); |
| 41 |
|
| 42 |
assert( |
| 43 |
!Object.prototype.hasOwnProperty.call(c, "m"), |
| 44 |
"m doesn't appear as an own property on the C instance" |
| 45 |
); |
| 46 |
assert( |
| 47 |
!Object.prototype.hasOwnProperty.call(C.prototype, "m"), |
| 48 |
"m doesn't appear as an own property on the C prototype" |
| 49 |
); |
| 50 |
|
| 51 |
verifyProperty(C, "m", { |
| 52 |
enumerable: false, |
| 53 |
configurable: true, |
| 54 |
writable: true, |
| 55 |
}, {restore: true}); |
| 56 |
|
| 57 |
C.m().then(function(v) { |
| 58 |
assert.sameValue(v, 42); |
| 59 |
|
| 60 |
function assertions() { |
| 61 |
// Cover $DONE handler for async cases. |
| 62 |
function $DONE(error) { |
| 63 |
if (error) { |
| 64 |
throw new Test262Error('Test262:AsyncTestFailure') |
| 65 |
} |
| 66 |
} |
| 67 |
// Test the private fields do not appear as properties before set to value |
| 68 |
assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); |
| 69 |
assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); |
| 70 |
assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); |
| 71 |
|
| 72 |
assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); |
| 73 |
assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); |
| 74 |
assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); |
| 75 |
|
| 76 |
// Test if private fields can be sucessfully accessed and set to value |
| 77 |
assert.sameValue(C.x(), 42, "test 7"); |
| 78 |
assert.sameValue(C.y(), 43, "test 8"); |
| 79 |
|
| 80 |
// Test the private fields do not appear as properties before after set to value |
| 81 |
assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9"); |
| 82 |
assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10"); |
| 83 |
} |
| 84 |
|
| 85 |
return Promise.resolve(assertions()); |
| 86 |
}).then($DONE, $DONE); |