| 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 getter contains proper HomeObject |
| 6 |
esid: sec-method-definitions-runtime-semantics-classelementevaluation |
| 7 |
info: | |
| 8 |
MethodDefinition : get ClassElementName () { FunctionBody } |
| 9 |
1. Let key be the result of evaluating ClassElementName. |
| 10 |
2. ReturnIfAbrupt(key). |
| 11 |
3. If the function code for this MethodDefinition is strict mode code, let strict be true. Otherwise let strict be false. |
| 12 |
4. Let scope be the running execution context's LexicalEnvironment. |
| 13 |
5. Let formalParameterList be an instance of the production FormalParameters:[empty] . |
| 14 |
6. Let closure be FunctionCreate(Method, formalParameterList, FunctionBody, scope, strict). |
| 15 |
7. Perform MakeMethod(closure, homeObject). |
| 16 |
8. Perform SetFunctionName(closure, key, "get"). |
| 17 |
9. If key is a Private Name, |
| 18 |
a. If key has a [[Kind]] field, |
| 19 |
i. Assert: key.[[Kind]] is "accessor". |
| 20 |
ii. Assert: key.[[Brand]] is homeObject. |
| 21 |
iii. Assert: key does not have a [[Get]] field. |
| 22 |
iv. Set key.[[Get]] to closure. |
| 23 |
b. Otherwise, |
| 24 |
i. Set key.[[Kind]] to "accessor". |
| 25 |
ii. Set key.[[Brand]] to homeObject. |
| 26 |
iii. Set key.[[Get]] to closure. |
| 27 |
10. Else, |
| 28 |
a. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true}. |
| 29 |
b. Perform ? DefinePropertyOrThrow(homeObject, key, desc). |
| 30 |
features: [class-methods-private, class] |
| 31 |
---*/ |
| 32 |
|
| 33 |
class A { |
| 34 |
method() { |
| 35 |
return "Test262"; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
class C extends A { |
| 40 |
get #m() { |
| 41 |
return super.method(); |
| 42 |
} |
| 43 |
|
| 44 |
access() { |
| 45 |
return this.#m; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
let c = new C(); |
| 50 |
assert.sameValue(c.access(), "Test262"); |
| 51 |
|
| 52 |
reportCompare(0, 0); |