tor-browser

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

fn-name-static-precedence.js (2021B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-runtime-semantics-classdefinitionevaluation
      6 description: >
      7    Function `name` attribute not inferred in presence of static `name` method
      8 info: |
      9    ClassTail : ClassHeritage_opt { ClassBody_opt }
     10 
     11    14. If constructor is empty, then [...]
     12      b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent).
     13    15. Else, [...]
     14      d. Perform ! SetFunctionName(F, className).
     15    25. For each ClassElement e of elements, do
     16      a. If IsStatic of e is false, then [...]
     17      b. Else,
     18        i. Let field be ClassElementEvaluation of e with arguments F and false.
     19           [ This overwrites the name property on F. ]
     20 features: [generators]
     21 ---*/
     22 
     23 class A {
     24  static method() {
     25    throw new Test262Error('Static method should not be executed during definition');
     26  }
     27  static name() {
     28    throw new Test262Error('Static method should not be executed during definition');
     29  }
     30 }
     31 
     32 assert.sameValue(typeof A.name, 'function');
     33 
     34 var attr = 'name';
     35 class B {
     36  static [attr]() {
     37    throw new Test262Error(
     38      'Static method defined via computed property should not be executed ' +
     39      'during definition'
     40    );
     41  }
     42 }
     43 
     44 assert.sameValue(typeof B.name, 'function');
     45 
     46 var isDefined = false;
     47 class C {
     48  static get name() {
     49    if (isDefined) {
     50      return 'pass';
     51    }
     52    throw new Test262Error('Static `get` accessor should not be executed during definition');
     53  }
     54 }
     55 
     56 isDefined = true;
     57 assert.sameValue(C.name, 'pass');
     58 
     59 class D {
     60  static set name(_) {
     61    throw new Test262Error('Static `set` accessor should not be executed during definition');
     62  }
     63 }
     64 
     65 assert.sameValue(D.name, undefined);
     66 
     67 class E {
     68  static *name() {
     69    throw new Test262Error('Static GeneratorMethod should not be executed during definition');
     70  }
     71 }
     72 
     73 assert.sameValue(typeof E.name, 'function');
     74 
     75 reportCompare(0, 0);