privatefieldget-success-2.js (1095B)
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 A { 30 #x = 'Avalue'; 31 x() { 32 return this.#x; 33 } 34 } 35 class B extends A { 36 #x = 'Bvalue'; 37 x() { 38 return this.#x; 39 } 40 } 41 42 var b = new B(); 43 44 assert.sameValue(b.x(), 'Bvalue') 45 46 reportCompare(0, 0);