tor-browser

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

private-method-not-writable.js (724B)


      1 // Copyright (C) 2021 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: >
      6  Throws TypeError when attempting to overwrite a private method.
      7 esid: sec-privateset
      8 info: |
      9  7.3.30 PrivateSet ( P, O, value )
     10  1. Let entry be ! PrivateElementFind(P, O).
     11  2. If entry is empty, throw a TypeError exception.
     12  3. If entry.[[Kind]] is field, then
     13    ...
     14  4. Else if entry.[[Kind]] is method, then
     15    a. Throw a TypeError exception.
     16  5. ...
     17 
     18 features: [class, class-methods-private]
     19 ---*/
     20 
     21 class C {
     22  #m() {}
     23 
     24  assign() {
     25    this.#m = 0;
     26  }
     27 }
     28 
     29 var obj = new C();
     30 
     31 assert.throws(TypeError, function() {
     32  obj.assign();
     33 });
     34 
     35 reportCompare(0, 0);