tor-browser

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

private-static-method-visible-to-direct-eval.js (2113B)


      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: Private static method is visible to direct eval code
      6 esid: sec-privatefieldget
      7 info: |
      8  PrivateFieldGet (P, O)
      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. Return entry.[[PrivateFieldValue]].
     15    4. Perform ? PrivateBrandCheck(O, P).
     16    5. If P.[[Kind]] is "method",
     17      a. Return P.[[Value]].
     18    6. Else,
     19      a. Assert: P.[[Kind]] is "accessor".
     20      b. If P does not have a [[Get]] field, throw a TypeError exception.
     21      c. Let getter be P.[[Get]].
     22      d. Return ? Call(getter, O).
     23 
     24  ClassElementName : PrivateIdentifier
     25    1. Let privateIdentifier be StringValue of PrivateIdentifier.
     26    2. Let privateName be NewPrivateName(privateIdentifier).
     27    3. Let scope be the running execution context's PrivateEnvironment.
     28    4. Let scopeEnvRec be scope's EnvironmentRecord.
     29    5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName).
     30    6. Return privateName.
     31 
     32  MakePrivateReference ( baseValue, privateIdentifier )
     33    1. Let env be the running execution context's PrivateEnvironment.
     34    2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
     35    3. Let privateName be GetValue(privateNameBinding).
     36    4. Assert: privateName is a Private Name.
     37    5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
     38 features: [class-static-methods-private, class]
     39 ---*/
     40 
     41 class C {
     42  static #m() {
     43    return "Test262";
     44  }
     45 
     46  static accessWithEval() {
     47    return eval("this.#m()");
     48  }
     49 }
     50 
     51 class D {
     52  static #m() {
     53    throw new Test262Error();
     54  }
     55 }
     56 
     57 assert.sameValue(C.accessWithEval(), "Test262");
     58 
     59 assert.throws(TypeError, function() {
     60  C.accessWithEval.call(D);
     61 }, "invalid access to a private field");
     62 
     63 reportCompare(0, 0);