tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

privatemethods-on-proxy.js (1316B)


      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 method 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      a. Return P.[[Value]].
     23      ...
     24 includes: [compareArray.js]
     25 features: [class, class-methods-private, Proxy]
     26 ---*/
     27 
     28 let arr = [];
     29 
     30 class ProxyBase {
     31  constructor() {
     32    return new Proxy(this, {
     33      get: function (obj, prop) {
     34        arr.push(prop);
     35        return obj[prop];
     36      }
     37    });
     38  }
     39 }
     40 
     41 class Test extends ProxyBase {
     42  #f() {
     43    return 3;
     44  }
     45  method() {
     46    return this.#f();
     47  }
     48 }
     49 
     50 let t = new Test();
     51 let r = t.method();
     52 assert.sameValue(r, 3);
     53 
     54 assert.compareArray(arr, ['method']);
     55 
     56 
     57 reportCompare(0, 0);