Debian Codegraph @

js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence-order.js

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