Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/privatefieldget-success-5.js

raw
1 // Copyright (C) 2017 Valerie Young. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: Successfully access private field
6 esid: sec-getvalue
7 info: |
8 GetValue ( V )
9 ...
10 5. If IsPropertyReference(V), then
11 ...
12 b. If IsPrivateReference(V), then
13 i. Let env be the running execution context's PrivateNameEnvironment.
14 ii. Let field be ? ResolveBinding(GetReferencedName(V), env).
15 iii. Assert: field is a Private Name.
16 iv. Return ? PrivateFieldGet(field, base).
17
18 PrivateFieldGet (P, O )
19 1. Assert: P is a Private Name value.
20 2. If O is not an object, throw a TypeError exception.
21 3. Let entry be PrivateFieldFind(P, O).
22 4. If entry is empty, throw a TypeError exception.
23 5. Return entry.[[PrivateFieldValue]].
24
25 features: [class, class-fields-private]
26 ---*/
27
28
29 class C {
30 #x = 42;
31 f() {
32 return this.#x;
33 }
34 }
35
36 var c1 = new C();
37 var c2 = new C();
38 var value = c2.f.call(c1);
39
40 assert.sameValue(value, 42);
41
42 reportCompare(0, 0);