tor-browser

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

private-method-get-and-call.js (1535B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/class-elements/private-method-get-and-call.case
      3 // - src/class-elements/default/cls-expr.template
      4 /*---
      5 description: Function returned by a private method can be called with other values as 'this' (field definitions in a class expression)
      6 esid: prod-FieldDefinition
      7 features: [class, class-methods-private]
      8 flags: [generated]
      9 info: |
     10    PrivateFieldGet (P, O)
     11      1. Assert: P is a Private Name.
     12      2. If O is not an object, throw a TypeError exception.
     13      3. If P.[[Kind]] is "field",
     14        a. Let entry be PrivateFieldFind(P, O).
     15        b. If entry is empty, throw a TypeError exception.
     16        c. Return entry.[[PrivateFieldValue]].
     17      4. Perform ? PrivateBrandCheck(O, P).
     18      5. If P.[[Kind]] is "method",
     19        a. Return P.[[Value]].
     20      6. Else,
     21        a. Assert: P.[[Kind]] is "accessor".
     22        b. If P does not have a [[Get]] field, throw a TypeError exception.
     23        c. Let getter be P.[[Get]].
     24        d. Return ? Call(getter, O).
     25 
     26    PrivateBrandCheck(O, P)
     27      1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true,
     28        a. Throw a TypeError exception.
     29 
     30 ---*/
     31 
     32 
     33 var C = class {
     34  #m() { return this._v; }
     35    
     36  getPrivateMethod() {
     37      return this.#m;
     38  }
     39 
     40 }
     41 
     42 let c = new C();
     43 
     44 let o1 = {_v: 'test262'};
     45 let o2 = {_v: 'foo'}; 
     46 assert.sameValue(c.getPrivateMethod().call(o1), 'test262');
     47 assert.sameValue(c.getPrivateMethod().call(o2), 'foo');
     48 
     49 reportCompare(0, 0);