tor-browser

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

private-method-brand-check-super-class.js (1403B)


      1 // Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: Subclass can access private methods of a superclass (private method)
      6 esid: sec-privatefieldget
      7 info: |
      8  SuperCall : super Arguments
      9    ...
     10    10. Perform ? InitializeInstanceElements(result, F).
     11    ...
     12 
     13  InitializeInstanceFieldsElements ( O, constructor )
     14    1. Assert: Type ( O ) is Object.
     15    2. Assert: Assert constructor is an ECMAScript function object.
     16    3. If constructor.[[PrivateBrand]] is not undefined,
     17      a. Perform ? PrivateBrandAdd(O, constructor.[[PrivateBrand]]).
     18    4. Let fieldRecords be the value of constructor's [[Fields]] internal slot.
     19    5. For each item fieldRecord in order from fieldRecords,
     20      a. Perform ? DefineField(O, fieldRecord).
     21    6. Return.
     22 features: [class, class-methods-private]
     23 ---*/
     24 
     25 class S {
     26  #method() { return 'super class'; }
     27  
     28  superAccess() { return this.#method(); }
     29 }
     30 
     31 class C extends S {
     32  #method() { return 'test262'; }
     33  
     34  access() {
     35    return this.#method();
     36  }
     37 }
     38  
     39 let c = new C();
     40 
     41 assert.sameValue(c.access(), 'test262');
     42 assert.sameValue(c.superAccess(), 'super class');
     43 
     44 let s = new S();
     45 assert.sameValue(s.superAccess(), 'super class');
     46 assert.throws(TypeError, function() {
     47  c.access.call(s);
     48 }, 'invalid access of C private method');
     49 
     50 reportCompare(0, 0);