| 1 |
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Private setter is visible to direct eval code |
| 6 |
esid: sec-privatefieldset |
| 7 |
info: | |
| 8 |
PrivateFieldSet (P, O, value ) |
| 9 |
1. Assert: P is a Private Name. |
| 10 |
2. If O is not an object, throw a TypeError exception. |
| 11 |
3. If P.[[Kind]] is "field", |
| 12 |
a. Let entry be PrivateFieldFind(P, O). |
| 13 |
b. If entry is empty, throw a TypeError exception. |
| 14 |
c. Set entry.[[PrivateFieldValue]] to value. |
| 15 |
d. Return. |
| 16 |
4. If P.[[Kind]] is "method", throw a TypeError exception. |
| 17 |
5. Else, |
| 18 |
a. Assert: P.[[Kind]] is "accessor". |
| 19 |
b. If O.[[PrivateFieldBrands]] does not contain P.[[Brand]], throw a TypeError exception. |
| 20 |
c. If P does not have a [[Set]] field, throw a TypeError exception. |
| 21 |
d. Let setter be P.[[Set]]. |
| 22 |
e. Perform ? Call(setter, O, value). |
| 23 |
f. Return. |
| 24 |
|
| 25 |
ClassElementName : PrivateIdentifier |
| 26 |
1. Let privateIdentifier be StringValue of PrivateIdentifier. |
| 27 |
2. Let privateName be NewPrivateName(privateIdentifier). |
| 28 |
3. Let scope be the running execution context's PrivateEnvironment. |
| 29 |
4. Let scopeEnvRec be scope's EnvironmentRecord. |
| 30 |
5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName). |
| 31 |
6. Return privateName. |
| 32 |
|
| 33 |
MakePrivateReference ( baseValue, privateIdentifier ) |
| 34 |
1. Let env be the running execution context's PrivateEnvironment. |
| 35 |
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env). |
| 36 |
3. Let privateName be GetValue(privateNameBinding). |
| 37 |
4. Assert: privateName is a Private Name. |
| 38 |
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true. |
| 39 |
features: [class-methods-private, class] |
| 40 |
---*/ |
| 41 |
|
| 42 |
class C { |
| 43 |
set #m(v) { this._v = v; }; |
| 44 |
|
| 45 |
setWithEval(v) { |
| 46 |
eval("this.#m = v"); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
class D { |
| 51 |
set #m(v) { throw new Test262Error(); }; |
| 52 |
} |
| 53 |
|
| 54 |
let c = new C(); |
| 55 |
c.setWithEval("Test262"); |
| 56 |
assert.sameValue(c._v, "Test262"); |
| 57 |
|
| 58 |
let d = new D(); |
| 59 |
assert.throws(TypeError, function() { |
| 60 |
c.setWithEval.call(d); |
| 61 |
}, "invalid access to a private setter"); |
| 62 |
|
| 63 |
reportCompare(0, 0); |