tor-browser

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

set-access-of-shadowed-private-method.js (2057B)


      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: Trying to set private method throws TypeError
      6 esid: sec-privatefieldset
      7 info: |
      8  PrivateFieldSet ( P, O, value )
      9    1. Assert: P is a Private Name.
     10    2. If O is not an object, throw a TypeError exception.
     11    3. If P.[[Kind]] is "field",
     12      a. Let entry be PrivateFieldFind(P, O).
     13      b. If entry is empty, throw a TypeError exception.
     14      c. Set entry.[[PrivateFieldValue]] to value.
     15      d. Return.
     16    4. If P.[[Kind]] is "method", throw a TypeError exception.
     17    5. Else,
     18      a. Assert: P.[[Kind]] is "accessor".
     19      b. If O.[[PrivateFieldBrands]] does not contain P.[[Brand]], throw a TypeError exception.
     20      c. If P does not have a [[Set]] field, throw a TypeError exception.
     21      d. Let setter be P.[[Set]].
     22      e. Perform ? Call(setter, O, value).
     23      f. Return.
     24 features: [class-methods-private, class-fields-public, class]
     25 ---*/
     26 
     27 class A {
     28  set #f(v) {
     29    throw new Test262Error();
     30  }
     31 }
     32 
     33 class B extends A {
     34  #f() {
     35    throw new Test262Error();
     36  }
     37 
     38  setAccess() {
     39    this.#f = 'Test262';
     40  }
     41 }
     42 
     43 let b = new B();
     44 assert.throws(TypeError, function() {
     45  b.setAccess();
     46 }, 'subclass private method should shadow super class private accessor');
     47 
     48 class C {
     49  set #f(v) {
     50    throw new Test262Error();
     51  }
     52 
     53  Inner = class {
     54    #f() {
     55      throw new Test262Error();
     56    }
     57 
     58    setAccess() {
     59      this.#f = 'Test262';
     60    }
     61  }
     62 }
     63 
     64 let c = new C();
     65 let innerC = new c.Inner();
     66 assert.throws(TypeError, function() {
     67  innerC.setAccess();
     68 }, 'inner class private method should shadow outer class private accessor');
     69 
     70 class D {
     71  #f() {
     72    throw new Test262Error();
     73  }
     74 
     75  Inner = class {
     76    set #f(v) {
     77      throw new Test262Error();
     78    }
     79  }
     80 
     81  setAccess() {
     82    this.#f = 'Test262';
     83  }
     84 }
     85 
     86 let d = new D();
     87 assert.throws(TypeError, function() {
     88  d.setAccess();
     89 }, 'inner class private accessor should not be visible to outer class');
     90 
     91 
     92 reportCompare(0, 0);