tor-browser

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

private-static-field-multiple-evaluations-of-class-realm.js (2354B)


      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: Every new evaluation of a class creates a different Private Name (private static field)
      6 esid: sec-runtime-semantics-evaluate-name
      7 info: |
      8  ClassElementName : PrivateIdentifier
      9    1. Let privateIdentifier be StringValue of PrivateIdentifier.
     10    2. Let privateName be NewPrivateName(privateIdentifier).
     11    3. Let scope be the running execution context's PrivateEnvironment.
     12    4. Let scopeEnvRec be scope's EnvironmentRecord.
     13    5. Perform ! scopeEnvRec.InitializeBinding(privateIdentifier, privateName).
     14    6. Return privateName.
     15 
     16  ClassTail : ClassHeritage { ClassBody }
     17    ...
     18    27. Let staticFields be a new empty List.
     19    28. For each ClassElement e in order from elements,
     20      a. If IsStatic of e is false, then
     21        ...
     22      b. Else,
     23        i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
     24      c. If field is an abrupt completion, then
     25        ...
     26      d. If field is not empty,
     27        i. If IsStatic of e is false, append field to instanceFields.
     28        ii. Otherwise, append field to staticFields.
     29    ...
     30    34. For each item fieldRecord in order from staticFields,
     31      a. Perform ? DefineField(F, field).
     32    ...
     33 
     34  DefineField(receiver, fieldRecord)
     35    ...
     36    8. If fieldName is a Private Name,
     37      a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
     38 features: [class, class-static-fields-private, cross-realm]
     39 flags: [noStrict]
     40 ---*/
     41 
     42 let global1 = $262.createRealm().global;
     43 let global2 = $262.createRealm().global;
     44 let eval1 = global1.eval;
     45 let eval2 = global2.eval;
     46 
     47 let classStringExpression = `(
     48 class {
     49  static #m = 'test262';
     50 
     51  static access() {
     52    return this.#m;
     53  }
     54 }
     55 )`;
     56 
     57 let evalClass = function (_eval) {
     58  return _eval(classStringExpression);
     59 };
     60 
     61 let C1 = evalClass(eval1);
     62 let C2 = evalClass(eval2);
     63 
     64 assert.sameValue(C1.access(), 'test262');
     65 assert.sameValue(C2.access(), 'test262');
     66 
     67 assert.throws(global1.TypeError, function() {
     68  C1.access.call(C2);
     69 }, 'invalid access of c1 private static field');
     70 
     71 assert.throws(global2.TypeError, function() {
     72  C2.access.call(C1);
     73 }, 'invalid access of c2 private static field');
     74 
     75 reportCompare(0, 0);