Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/private-field-is-visible-in-computed-properties.js

raw
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: PrivateName of a class is visible in its ComputetProperty scope
6 esid: prod-ClassTail
7 info: |
8 ClassTail : ClassHeritage { ClassBody }
9 1. Let lex be the LexicalEnvironment of the running execution context.
10 2. Let classScope be NewDeclarativeEnvironment(lex).
11 3. Let classScopeEnvRec be classScope's EnvironmentRecord.
12 ...
13 8. If ClassBodyopt is present, then
14 a. For each element dn of the PrivateBoundIdentifiers of ClassBodyopt,
15 i. Perform classPrivateEnvRec.CreateImmutableBinding(dn, true).
16 ii. Let privateName be NewPrivateName(dn).
17 iii. Perform ! classPrivateEnvRec.InitializeBinding(dn, dn).
18 ...
19 15. Set the running execution context's LexicalEnvironment to classScope.
20 16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
21 ...
22 27. For each ClassElement e in order from elements
23 a. If IsStatic of e is false, then
24 i. Let field be the result of ClassElementEvaluation for e with arguments proto and false.
25 ...
26
27 GetValue ( V )
28 ...
29 5. If IsPropertyReference(V), then
30 ...
31 b. If IsPrivateReference(V), then
32 i. Return ? PrivateFieldGet(GetReferencedName(V), base).
33
34 PrivateFieldGet ( P, O )
35 ...
36 4. If entry is empty, throw a TypeError exception.
37 ...
38
39 features: [class-fields-private, class-fields-public, class]
40 ---*/
41
42 const self = this;
43 assert.throws(TypeError, function() {
44 class C {
45 [self.#f] = 'Test262';
46 #f = 'foo';
47 }
48 }, 'access to a not defined private field in object should throw a TypeError');
49
50
51 reportCompare(0, 0);