| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/execution.h" | 5 #include "src/execution.h" |
| 6 | 6 |
| 7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
| 8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // that the C++ stack grows faster than the JS stack, resulting in an overflow | 65 // that the C++ stack grows faster than the JS stack, resulting in an overflow |
| 66 // there. Add a check here to make that less likely. | 66 // there. Add a check here to make that less likely. |
| 67 StackLimitCheck check(isolate); | 67 StackLimitCheck check(isolate); |
| 68 if (check.HasOverflowed()) { | 68 if (check.HasOverflowed()) { |
| 69 isolate->StackOverflow(); | 69 isolate->StackOverflow(); |
| 70 isolate->ReportPendingMessages(); | 70 isolate->ReportPendingMessages(); |
| 71 return MaybeHandle<Object>(); | 71 return MaybeHandle<Object>(); |
| 72 } | 72 } |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 // api callbacks can be called directly. |
| 76 if (target->IsJSFunction()) { |
| 77 Handle<JSFunction> function = Handle<JSFunction>::cast(target); |
| 78 if ((!is_construct || function->IsConstructor()) && |
| 79 function->shared()->IsApiFunction()) { |
| 80 SaveContext save(isolate); |
| 81 isolate->set_context(function->context()); |
| 82 DCHECK(function->context()->global_object()->IsJSGlobalObject()); |
| 83 if (is_construct) receiver = isolate->factory()->the_hole_value(); |
| 84 auto value = Builtins::InvokeApiFunction( |
| 85 isolate, is_construct, function, receiver, argc, args, |
| 86 Handle<HeapObject>::cast(new_target)); |
| 87 bool has_exception = value.is_null(); |
| 88 DCHECK(has_exception == isolate->has_pending_exception()); |
| 89 if (has_exception) { |
| 90 isolate->ReportPendingMessages(); |
| 91 return MaybeHandle<Object>(); |
| 92 } else { |
| 93 isolate->clear_pending_message(); |
| 94 } |
| 95 return value; |
| 96 } |
| 97 } |
| 98 |
| 75 // Entering JavaScript. | 99 // Entering JavaScript. |
| 76 VMState<JS> state(isolate); | 100 VMState<JS> state(isolate); |
| 77 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); | 101 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); |
| 78 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { | 102 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { |
| 79 isolate->ThrowIllegalOperation(); | 103 isolate->ThrowIllegalOperation(); |
| 80 isolate->ReportPendingMessages(); | 104 isolate->ReportPendingMessages(); |
| 81 return MaybeHandle<Object>(); | 105 return MaybeHandle<Object>(); |
| 82 } | 106 } |
| 83 | 107 |
| 84 // Placeholder for return value. | 108 // Placeholder for return value. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, | 162 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, |
| 139 Handle<Object> receiver, int argc, | 163 Handle<Object> receiver, int argc, |
| 140 Handle<Object> argv[]) { | 164 Handle<Object> argv[]) { |
| 141 // Convert calls on global objects to be calls on the global | 165 // Convert calls on global objects to be calls on the global |
| 142 // receiver instead to avoid having a 'this' pointer which refers | 166 // receiver instead to avoid having a 'this' pointer which refers |
| 143 // directly to a global object. | 167 // directly to a global object. |
| 144 if (receiver->IsJSGlobalObject()) { | 168 if (receiver->IsJSGlobalObject()) { |
| 145 receiver = | 169 receiver = |
| 146 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); | 170 handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); |
| 147 } | 171 } |
| 148 | |
| 149 // api callbacks can be called directly. | |
| 150 if (callable->IsJSFunction() && | |
| 151 Handle<JSFunction>::cast(callable)->shared()->IsApiFunction()) { | |
| 152 Handle<JSFunction> function = Handle<JSFunction>::cast(callable); | |
| 153 SaveContext save(isolate); | |
| 154 isolate->set_context(function->context()); | |
| 155 DCHECK(function->context()->global_object()->IsJSGlobalObject()); | |
| 156 auto value = | |
| 157 Builtins::InvokeApiFunction(isolate, function, receiver, argc, argv); | |
| 158 bool has_exception = value.is_null(); | |
| 159 DCHECK(has_exception == isolate->has_pending_exception()); | |
| 160 if (has_exception) { | |
| 161 isolate->ReportPendingMessages(); | |
| 162 return MaybeHandle<Object>(); | |
| 163 } else { | |
| 164 isolate->clear_pending_message(); | |
| 165 } | |
| 166 return value; | |
| 167 } | |
| 168 return Invoke(isolate, false, callable, receiver, argc, argv, | 172 return Invoke(isolate, false, callable, receiver, argc, argv, |
| 169 isolate->factory()->undefined_value()); | 173 isolate->factory()->undefined_value()); |
| 170 } | 174 } |
| 171 | 175 |
| 172 | 176 |
| 173 // static | 177 // static |
| 174 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, | 178 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, |
| 175 Handle<Object> argv[]) { | 179 Handle<Object> argv[]) { |
| 176 return New(constructor->GetIsolate(), constructor, constructor, argc, argv); | 180 return New(constructor->GetIsolate(), constructor, constructor, argc, argv); |
| 177 } | 181 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 496 |
| 493 isolate_->counters()->stack_interrupts()->Increment(); | 497 isolate_->counters()->stack_interrupts()->Increment(); |
| 494 isolate_->counters()->runtime_profiler_ticks()->Increment(); | 498 isolate_->counters()->runtime_profiler_ticks()->Increment(); |
| 495 isolate_->runtime_profiler()->MarkCandidatesForOptimization(); | 499 isolate_->runtime_profiler()->MarkCandidatesForOptimization(); |
| 496 | 500 |
| 497 return isolate_->heap()->undefined_value(); | 501 return isolate_->heap()->undefined_value(); |
| 498 } | 502 } |
| 499 | 503 |
| 500 } // namespace internal | 504 } // namespace internal |
| 501 } // namespace v8 | 505 } // namespace v8 |
| OLD | NEW |