| 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: Trying to get from PrivateName without [[Get]] throws TypeError |
| 6 |
esid: sec-privatefieldget |
| 7 |
info: | |
| 8 |
PrivateFieldGet (P, O ) |
| 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. Return entry.[[PrivateFieldValue]]. |
| 15 |
4. Perform ? PrivateBrandCheck(O, P). |
| 16 |
5. If P.[[Kind]] is "method", |
| 17 |
a. Return P.[[Value]]. |
| 18 |
6. Else, |
| 19 |
a. Assert: P.[[Kind]] is "accessor". |
| 20 |
b. If P does not have a [[Get]] field, throw a TypeError exception. |
| 21 |
c. Let getter be P.[[Get]]. |
| 22 |
d. Return ? Call(getter, O). |
| 23 |
features: [class-methods-private, class-fields-public, class] |
| 24 |
---*/ |
| 25 |
|
| 26 |
class A { |
| 27 |
get #f() { |
| 28 |
throw new Test262Error(); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
class C extends A { |
| 33 |
set #f(v) { |
| 34 |
throw new Test262Error(); |
| 35 |
} |
| 36 |
|
| 37 |
getAccess() { |
| 38 |
return this.#f; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
let c = new C(); |
| 43 |
assert.throws(TypeError, function() { |
| 44 |
c.getAccess(); |
| 45 |
}, 'subclass private accessor should shadow super class private accessor'); |
| 46 |
|
| 47 |
class B { |
| 48 |
get #f() { |
| 49 |
throw new Test262Error(); |
| 50 |
} |
| 51 |
|
| 52 |
Inner = class { |
| 53 |
set #f(v) { |
| 54 |
throw new Test262Error(); |
| 55 |
} |
| 56 |
|
| 57 |
getAccess() { |
| 58 |
return this.#f; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
let b = new B(); |
| 64 |
let innerB = new b.Inner(); |
| 65 |
assert.throws(TypeError, function() { |
| 66 |
innerB.getAccess(); |
| 67 |
}, 'inner class private accessor should shadow outer class private accessor'); |
| 68 |
|
| 69 |
class D { |
| 70 |
set #f(v) { |
| 71 |
throw new Test262Error(); |
| 72 |
} |
| 73 |
|
| 74 |
Inner = class { |
| 75 |
get #f() { |
| 76 |
throw new Test262Error(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
getAccess() { |
| 81 |
return this.#f; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
let d = new D(); |
| 86 |
assert.throws(TypeError, function() { |
| 87 |
d.getAccess(); |
| 88 |
}, 'inner class private accessor should not be visible to outer class private accessor'); |
| 89 |
|
| 90 |
|
| 91 |
reportCompare(0, 0); |