1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_FUNCTION_KIND_H_
#define V8_OBJECTS_FUNCTION_KIND_H_
#include "src/base/bounds.h"
#include "src/base/macros.h"
namespace v8 {
namespace internal {
enum FunctionKind : uint8_t {
// BEGIN constructable functions
kNormalFunction,
kModule,
kAsyncModule,
// BEGIN class constructors
// BEGIN base constructors
kBaseConstructor,
// BEGIN default constructors
kDefaultBaseConstructor,
// END base constructors
// BEGIN derived constructors
kDefaultDerivedConstructor,
// END default constructors
kDerivedConstructor,
// END derived constructors
// END class constructors
// END constructable functions.
// BEGIN accessors
kGetterFunction,
kSetterFunction,
// END accessors
// BEGIN arrow functions
kArrowFunction,
// BEGIN async functions
kAsyncArrowFunction,
// END arrow functions
kAsyncFunction,
// BEGIN concise methods 1
kAsyncConciseMethod,
// BEGIN generators
kAsyncConciseGeneratorMethod,
// END concise methods 1
kAsyncGeneratorFunction,
// END async functions
kGeneratorFunction,
// BEGIN concise methods 2
kConciseGeneratorMethod,
// END generators
kConciseMethod,
kClassMembersInitializerFunction,
// END concise methods 2
kLastFunctionKind = kClassMembersInitializerFunction,
};
constexpr int kFunctionKindBitSize = 5;
STATIC_ASSERT(kLastFunctionKind < (1 << kFunctionKindBitSize));
inline bool IsArrowFunction(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kArrowFunction,
FunctionKind::kAsyncArrowFunction);
}
inline bool IsModule(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kModule,
FunctionKind::kAsyncModule);
}
inline bool IsAsyncModule(FunctionKind kind) {
return kind == FunctionKind::kAsyncModule;
}
inline bool IsAsyncGeneratorFunction(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
FunctionKind::kAsyncGeneratorFunction);
}
inline bool IsGeneratorFunction(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
FunctionKind::kConciseGeneratorMethod);
}
inline bool IsAsyncFunction(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kAsyncArrowFunction,
FunctionKind::kAsyncGeneratorFunction);
}
inline bool IsResumableFunction(FunctionKind kind) {
return IsGeneratorFunction(kind) || IsAsyncFunction(kind) || IsModule(kind);
}
inline bool IsConciseMethod(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kAsyncConciseMethod,
FunctionKind::kAsyncConciseGeneratorMethod) ||
base::IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
FunctionKind::kClassMembersInitializerFunction);
}
inline bool IsStrictFunctionWithoutPrototype(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kGetterFunction,
FunctionKind::kAsyncArrowFunction) ||
base::IsInRange(kind, FunctionKind::kAsyncConciseMethod,
FunctionKind::kAsyncConciseGeneratorMethod) ||
base::IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
FunctionKind::kClassMembersInitializerFunction);
}
inline bool IsGetterFunction(FunctionKind kind) {
return kind == FunctionKind::kGetterFunction;
}
inline bool IsSetterFunction(FunctionKind kind) {
return kind == FunctionKind::kSetterFunction;
}
inline bool IsAccessorFunction(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kGetterFunction,
FunctionKind::kSetterFunction);
}
inline bool IsDefaultConstructor(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kDefaultBaseConstructor,
FunctionKind::kDefaultDerivedConstructor);
}
inline bool IsBaseConstructor(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kBaseConstructor,
FunctionKind::kDefaultBaseConstructor);
}
inline bool IsDerivedConstructor(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kDefaultDerivedConstructor,
FunctionKind::kDerivedConstructor);
}
inline bool IsClassConstructor(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kBaseConstructor,
FunctionKind::kDerivedConstructor);
}
inline bool IsClassMembersInitializerFunction(FunctionKind kind) {
return kind == FunctionKind::kClassMembersInitializerFunction;
}
inline bool IsConstructable(FunctionKind kind) {
return base::IsInRange(kind, FunctionKind::kNormalFunction,
FunctionKind::kDerivedConstructor);
}
inline const char* FunctionKind2String(FunctionKind kind) {
switch (kind) {
case FunctionKind::kNormalFunction:
return "NormalFunction";
case FunctionKind::kArrowFunction:
return "ArrowFunction";
case FunctionKind::kGeneratorFunction:
return "GeneratorFunction";
case FunctionKind::kConciseMethod:
return "ConciseMethod";
case FunctionKind::kDerivedConstructor:
return "DerivedConstructor";
case FunctionKind::kBaseConstructor:
return "BaseConstructor";
case FunctionKind::kGetterFunction:
return "GetterFunction";
case FunctionKind::kSetterFunction:
return "SetterFunction";
case FunctionKind::kAsyncFunction:
return "AsyncFunction";
case FunctionKind::kModule:
return "Module";
case FunctionKind::kAsyncModule:
return "AsyncModule";
case FunctionKind::kClassMembersInitializerFunction:
return "ClassMembersInitializerFunction";
case FunctionKind::kDefaultBaseConstructor:
return "DefaultBaseConstructor";
case FunctionKind::kDefaultDerivedConstructor:
return "DefaultDerivedConstructor";
case FunctionKind::kAsyncArrowFunction:
return "AsyncArrowFunction";
case FunctionKind::kAsyncConciseMethod:
return "AsyncConciseMethod";
case FunctionKind::kConciseGeneratorMethod:
return "ConciseGeneratorMethod";
case FunctionKind::kAsyncConciseGeneratorMethod:
return "AsyncConciseGeneratorMethod";
case FunctionKind::kAsyncGeneratorFunction:
return "AsyncGeneratorFunction";
}
UNREACHABLE();
}
inline std::ostream& operator<<(std::ostream& os, FunctionKind kind) {
return os << FunctionKind2String(kind);
}
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_FUNCTION_KIND_H_
|