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; |
| 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 #define BUILTIN_LIST_CPP(V) \ |
| 225 BUILTIN_LIST(V, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ |
| 226 IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) |
| 227 BUILTIN_LIST_CPP(CASE) |
| 228 #undef BUILTIN_LIST_CPP |
| 229 #undef CASE |
| 230 default: |
| 231 return false; |
| 232 } |
| 233 UNREACHABLE(); |
| 234 } |
| 235 |
| 236 // static |
| 237 bool Builtins::IsApi(int index) { |
| 238 DCHECK(0 <= index && index < builtin_count); |
| 239 switch (index) { |
| 240 #define CASE(Name, ...) \ |
| 241 case k##Name: \ |
| 242 return true; |
| 243 #define BUILTIN_LIST_API(V) \ |
| 244 BUILTIN_LIST(IGNORE_BUILTIN, V, IGNORE_BUILTIN, IGNORE_BUILTIN, \ |
| 245 IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) |
| 246 BUILTIN_LIST_API(CASE); |
| 247 #undef BUILTIN_LIST_API |
| 248 #undef CASE |
| 249 default: |
| 250 return false; |
| 251 } |
| 252 UNREACHABLE(); |
| 253 } |
| 254 |
| 255 // static |
| 256 bool Builtins::HasCppImplementation(int index) { |
| 257 DCHECK(0 <= index && index < builtin_count); |
| 258 switch (index) { |
| 259 #define CASE(Name, ...) \ |
| 260 case k##Name: \ |
| 261 return true; |
| 262 BUILTIN_LIST_C(CASE) |
| 263 #undef CASE |
| 264 default: |
| 265 return false; |
| 266 } |
| 267 UNREACHABLE(); |
| 268 } |
| 269 |
201 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ | 270 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ |
202 Handle<Code> Builtins::Name() { \ | 271 Handle<Code> Builtins::Name() { \ |
203 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ | 272 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ |
204 return Handle<Code>(code_address); \ | 273 return Handle<Code>(code_address); \ |
205 } | 274 } |
206 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) | 275 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) |
207 #undef DEFINE_BUILTIN_ACCESSOR | 276 #undef DEFINE_BUILTIN_ACCESSOR |
208 | 277 |
209 // static | 278 // static |
210 bool Builtins::AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target, | 279 bool Builtins::AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target, |
211 Handle<JSObject> target_global_proxy) { | 280 Handle<JSObject> target_global_proxy) { |
212 if (FLAG_allow_unsafe_function_constructor) return true; | 281 if (FLAG_allow_unsafe_function_constructor) return true; |
213 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); | 282 HandleScopeImplementer* impl = isolate->handle_scope_implementer(); |
214 Handle<Context> responsible_context = impl->LastEnteredContext(); | 283 Handle<Context> responsible_context = impl->LastEnteredContext(); |
215 if (responsible_context.is_null()) { | 284 if (responsible_context.is_null()) { |
216 responsible_context = impl->MicrotaskContext(); | 285 responsible_context = impl->MicrotaskContext(); |
217 // TODO(jochen): Remove this. | 286 // TODO(jochen): Remove this. |
218 if (responsible_context.is_null()) { | 287 if (responsible_context.is_null()) { |
219 return true; | 288 return true; |
220 } | 289 } |
221 } | 290 } |
222 if (*responsible_context == target->context()) return true; | 291 if (*responsible_context == target->context()) return true; |
223 return isolate->MayAccess(responsible_context, target_global_proxy); | 292 return isolate->MayAccess(responsible_context, target_global_proxy); |
224 } | 293 } |
225 | 294 |
226 } // namespace internal | 295 } // namespace internal |
227 } // namespace v8 | 296 } // namespace v8 |
OLD | NEW |