tor-browser

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

privatefield-on-proxy.js (1399B)


      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: Sucessyfully get private reference 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    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 includes: [compareArray.js]
     25 features: [class, class-fields-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 = 3;
     43  method() {
     44    return this.#f;
     45  }
     46 }
     47 
     48 let t = new Test();
     49 let r = t.method();
     50 assert.sameValue(r, 3);
     51 
     52 assert.compareArray(arr, ['method']);
     53 
     54 
     55 reportCompare(0, 0);