privategetter-on-proxy.js (1488B)
1 // Copyright (C) 2019 Caio Lima. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: Successfully access private getter on Proxy objects without using [[Get]] 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 c. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)). 18 PrivateFieldGet(P, O) 19 ... 20 4. Perform ? PrivateBrandCheck(O, P). 21 5. If P.[[Kind]] is "method", 22 ... 23 6. Else, 24 a. Assert: P.[[Kind]] is "accessor". 25 b. If P does not have a [[Get]] field, throw a TypeError exception. 26 c. Let getter be P.[[Get]]. 27 d. Return ? Call(getter, O). 28 includes: [compareArray.js] 29 features: [class, class-methods-private, Proxy] 30 ---*/ 31 32 let arr = []; 33 34 class ProxyBase { 35 constructor() { 36 return new Proxy(this, { 37 get: function (obj, prop) { 38 arr.push(prop); 39 return obj[prop]; 40 } 41 }); 42 } 43 } 44 45 class Test extends ProxyBase { 46 get #f() { 47 return 3; 48 } 49 method() { 50 return this.#f; 51 } 52 } 53 54 let t = new Test(); 55 let r = t.method(); 56 assert.sameValue(r, 3); 57 58 assert.compareArray(arr, ['method']); 59 60 61 reportCompare(0, 0);