OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/code-events.h" | 6 #include "src/code-events.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/ic/ic-state.h" | 8 #include "src/ic/ic-state.h" |
9 #include "src/interface-descriptors.h" | 9 #include "src/interface-descriptors.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // may be called during initialization (disassembler!) | 177 // may be called during initialization (disassembler!) |
178 if (initialized_) { | 178 if (initialized_) { |
179 for (int i = 0; i < builtin_count; i++) { | 179 for (int i = 0; i < builtin_count; i++) { |
180 Code* entry = Code::cast(builtins_[i]); | 180 Code* entry = Code::cast(builtins_[i]); |
181 if (entry->contains(pc)) return name(i); | 181 if (entry->contains(pc)) return name(i); |
182 } | 182 } |
183 } | 183 } |
184 return NULL; | 184 return NULL; |
185 } | 185 } |
186 | 186 |
187 // static | |
187 const char* Builtins::name(int index) { | 188 const char* Builtins::name(int index) { |
188 switch (index) { | 189 switch (index) { |
189 #define CASE(Name, ...) \ | 190 #define CASE(Name, ...) \ |
190 case k##Name: \ | 191 case k##Name: \ |
191 return #Name; | 192 return #Name; |
192 BUILTIN_LIST_ALL(CASE) | 193 BUILTIN_LIST_ALL(CASE) |
193 #undef CASE | 194 #undef CASE |
194 default: | 195 default: |
195 UNREACHABLE(); | 196 UNREACHABLE(); |
196 break; | 197 break; |
197 } | 198 } |
198 return ""; | 199 return ""; |
199 } | 200 } |
200 | 201 |
202 // static | |
203 Address Builtins::CppEntryOf(int index) { | |
204 DCHECK(0 <= index && index < builtin_count); | |
205 switch (index) { | |
206 #define CASE(Name, ...) \ | |
207 case k##Name: \ | |
208 return FUNCTION_ADDR(Builtin_##Name); | |
209 BUILTIN_LIST_C(CASE) | |
210 #undef CASE | |
211 default: | |
212 return nullptr; | |
Toon Verwaest
2016/08/19 13:37:05
Shouldn't this be unreachable already?
jgruber
2016/08/19 15:11:38
No, case statements are built only for CPP and API
| |
213 } | |
214 UNREACHABLE(); | |
215 } | |
216 | |
217 // static | |
218 bool Builtins::IsCpp(int index) { | |
219 DCHECK(0 <= index && index < builtin_count); | |
220 switch (index) { | |
221 #define CASE(Name, ...) \ | |
222 case k##Name: \ | |
223 return true; | |
224 BUILTIN_LIST(CASE, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, | |
225 IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) | |
Toon Verwaest
2016/08/19 13:37:05
Does it make sense to add a macro CPP_BUILTIN(V) B
jgruber
2016/08/19 15:11:38
Done.
| |
226 #undef CASE | |
227 default: | |
228 return false; | |
229 } | |
230 UNREACHABLE(); | |
231 } | |
232 | |
233 // static | |
234 bool Builtins::IsApi(int index) { | |
235 DCHECK(0 <= index && index < builtin_count); | |
236 switch (index) { | |
237 #define CASE(Name, ...) \ | |
238 case k##Name: \ | |
239 return true; | |
240 BUILTIN_LIST(IGNORE_BUILTIN, CASE, IGNORE_BUILTIN, IGNORE_BUILTIN, | |
241 IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) | |
242 #undef CASE | |
243 default: | |
244 return false; | |
245 } | |
246 UNREACHABLE(); | |
247 } | |
248 | |
249 // static | |
250 bool Builtins::HasCppImplementation(int index) { | |
251 DCHECK(0 <= index && index < builtin_count); | |
252 switch (index) { | |
253 #define CASE(Name, ...) \ | |
254 case k##Name: \ | |
255 return true; | |
256 BUILTIN_LIST_C(CASE) | |
257 #undef CASE | |
258 default: | |
259 return false; | |
260 } | |
261 UNREACHABLE(); | |
262 } | |
263 | |
201 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ | 264 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ |
202 Handle<Code> Builtins::Name() { \ | 265 Handle<Code> Builtins::Name() { \ |
203 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ | 266 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ |
204 return Handle<Code>(code_address); \ | 267 return Handle<Code>(code_address); \ |
205 } | 268 } |
206 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) | 269 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) |
207 #undef DEFINE_BUILTIN_ACCESSOR | 270 #undef DEFINE_BUILTIN_ACCESSOR |
208 | 271 |
209 // static | 272 // static |
210 bool Builtins::AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target, | 273 bool Builtins::AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target, |
211 Handle<JSObject> target_global_proxy) { | 274 Handle<JSObject> target_global_proxy) { |
212 if (FLAG_allow_unsafe_function_constructor) return true; | 275 if (FLAG_allow_unsafe_function_constructor) return true; |
213 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 276 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
214 Handle<Context> responsible_context = impl->LastEnteredContext(); | 277 Handle<Context> responsible_context = impl->LastEnteredContext(); |
215 if (responsible_context.is_null()) { | 278 if (responsible_context.is_null()) { |
216 responsible_context = impl->MicrotaskContext(); | 279 responsible_context = impl->MicrotaskContext(); |
217 // TODO(jochen): Remove this. | 280 // TODO(jochen): Remove this. |
218 if (responsible_context.is_null()) { | 281 if (responsible_context.is_null()) { |
219 return true; | 282 return true; |
220 } | 283 } |
221 } | 284 } |
222 if (*responsible_context == target->context()) return true; | 285 if (*responsible_context == target->context()) return true; |
223 return isolate->MayAccess(responsible_context, target_global_proxy); | 286 return isolate->MayAccess(responsible_context, target_global_proxy); |
224 } | 287 } |
225 | 288 |
226 } // namespace internal | 289 } // namespace internal |
227 } // namespace v8 | 290 } // namespace v8 |
OLD | NEW |