tor-browser

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

fn-length-static-precedence.js (2231B)


      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 `length` attribute not inferred in presence of static `length` 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      a. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent.
     15         [ This sets the length property on constructorInfo.[[Closure]]. ]
     16      b. Let F be constructorInfo.[[Closure]].
     17      [...]
     18    25. For each ClassElement e of elements, do
     19      a. If IsStatic of e is false, then [...]
     20      b. Else,
     21        i. Let field be ClassElementEvaluation of e with arguments F and false.
     22           [ This overwrites the length property on F. ]
     23 features: [generators]
     24 ---*/
     25 
     26 class A {
     27  static method() {
     28    throw new Test262Error('Static method should not be executed during definition');
     29  }
     30  static length() {
     31    throw new Test262Error('Static method should not be executed during definition');
     32  }
     33 }
     34 
     35 assert.sameValue(typeof A.length, 'function');
     36 
     37 var attr = 'length';
     38 class B {
     39  static [attr]() {
     40    throw new Test262Error(
     41      'Static method defined via computed property should not be executed ' +
     42      'during definition'
     43    );
     44  }
     45 }
     46 
     47 assert.sameValue(typeof B.length, 'function');
     48 
     49 var isDefined = false;
     50 class C {
     51  static get length() {
     52    if (isDefined) {
     53      return 'pass';
     54    }
     55    throw new Test262Error('Static `get` accessor should not be executed during definition');
     56  }
     57 }
     58 
     59 isDefined = true;
     60 assert.sameValue(C.length, 'pass');
     61 
     62 class D {
     63  static set length(_) {
     64    throw new Test262Error('Static `set` accessor should not be executed during definition');
     65  }
     66 }
     67 
     68 assert.sameValue(D.length, undefined);
     69 
     70 class E {
     71  static *length() {
     72    throw new Test262Error('Static GeneratorMethod should not be executed during definition');
     73  }
     74 }
     75 
     76 assert.sameValue(typeof E.length, 'function');
     77 
     78 reportCompare(0, 0);