Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/private-field-with-initialized-id-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 ...
17 15. Set the running execution context's LexicalEnvironment to classScope.
18 16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
19 ...
20 27. For each ClassElement e in order from elements
21 a. If IsStatic of e is false, then
22 i. Let field be the result of ClassElementEvaluation for e with arguments proto and false.
23 ...
24
25 FieldDefinition : ClassElementName Initializer
26 1. Let name be the result of evaluating ClassElementName.
27 ...
28
29 ClassElementName : PrivateIdentifier
30 1. Let privateIdentifier be StringValue of PrivateIdentifier.
31 2. Let privateName be NewPrivateName(privateIdentifier).
32 3. Let scope be the running execution context's PrivateEnvironment.
33 4. Let scopeEnvRec be scope's EnvironmentRecord.
34 5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName).
35 6. Return privateName.
36
37 MemberExpression : MemberExpression . PrivateIdentifier
38 ...
39 5. Return MakePrivateReference(bv, fieldNameString).
40
41 MakePrivateReference ( baseValue, privateIdentifier )
42 ...
43 2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
44 3. Let privateName be GetValue(privateNameBinding).
45 ...
46
47 GetValue (V)
48 ...
49 5. If IsPropertyReference(V), then
50 a. If HasPrimitiveBase(V), then
51 i. Assert: In this case, base will never be null or undefined.
52 ii. Let base be ToObject(base).
53 b. If IsPrivateReference(V), then
54 i. Return ? PrivateFieldGet(GetReferencedName(V), base).
55 6. Else,
56 a. Assert: base is an Environment Record.
57 b. Return ? base.GetBindingValue(GetReferencedName(V), IsStrictReference(V)).
58
59 PrivateFieldGet (P, O)
60 1. Assert: P is a Private Name.
61 2. Assert: Type(O) is Object.
62 3. Let entry be PrivateFieldFind(P, O).
63 4. If entry is empty, throw a TypeError exception.
64 5. Return entry.[[PrivateFieldValue]].
65
66 features: [class-fields-private, class-fields-public, class]
67 ---*/
68
69 const self = this;
70 assert.throws(TypeError, function() {
71 class C {
72 #f = 'foo';
73 [self.#f] = 'Test262';
74 }
75 }, 'access to a not defined private field in object should throw a TypeError');
76
77
78 reportCompare(0, 0);