fn-name-static-precedence-order.js (2184B)
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 includes: [compareArray.js] 21 features: [generators] 22 ---*/ 23 24 class A { 25 static method() { 26 throw new Test262Error('Static method should not be executed during definition'); 27 } 28 static name() { 29 throw new Test262Error('Static method should not be executed during definition'); 30 } 31 } 32 33 assert.compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method']) 34 35 var attr = 'name'; 36 class B { 37 static [attr]() { 38 throw new Test262Error( 39 'Static method defined via computed property should not be executed ' + 40 'during definition' 41 ); 42 } 43 } 44 45 assert.compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype']) 46 47 class C { 48 static get name() { 49 throw new Test262Error('Static `get` accessor should not be executed during definition'); 50 } 51 } 52 53 assert.compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype']) 54 55 class D { 56 static set name(_) { 57 throw new Test262Error('Static `set` accessor should not be executed during definition'); 58 } 59 } 60 61 assert.compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype']) 62 63 class E { 64 static *name() { 65 throw new Test262Error('Static GeneratorMethod should not be executed during definition'); 66 } 67 } 68 69 assert.compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype']) 70 71 reportCompare(0, 0);