| 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/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 PrintF("]\n"); | 51 PrintF("]\n"); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 MUST_USE_RESULT MaybeHandle<Object> Invoke(bool is_construct, | 58 MUST_USE_RESULT MaybeHandle<Object> Invoke(bool is_construct, |
| 59 Handle<JSFunction> function, | 59 Handle<JSFunction> function, |
| 60 Handle<Object> receiver, int argc, | 60 Handle<Object> receiver, int argc, |
| 61 Handle<Object> args[]) { | 61 Handle<Object> args[], |
| 62 Handle<Object> new_target) { |
| 62 Isolate* const isolate = function->GetIsolate(); | 63 Isolate* const isolate = function->GetIsolate(); |
| 63 | 64 |
| 64 // Convert calls on global objects to be calls on the global | 65 // Convert calls on global objects to be calls on the global |
| 65 // receiver instead to avoid having a 'this' pointer which refers | 66 // receiver instead to avoid having a 'this' pointer which refers |
| 66 // directly to a global object. | 67 // directly to a global object. |
| 67 if (receiver->IsGlobalObject()) { | 68 if (receiver->IsGlobalObject()) { |
| 68 receiver = | 69 receiver = |
| 69 handle(Handle<GlobalObject>::cast(receiver)->global_proxy(), isolate); | 70 handle(Handle<GlobalObject>::cast(receiver)->global_proxy(), isolate); |
| 70 } | 71 } |
| 71 | 72 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 101 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); | 102 CHECK(AllowJavascriptExecution::IsAllowed(isolate)); |
| 102 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { | 103 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) { |
| 103 isolate->ThrowIllegalOperation(); | 104 isolate->ThrowIllegalOperation(); |
| 104 isolate->ReportPendingMessages(); | 105 isolate->ReportPendingMessages(); |
| 105 return MaybeHandle<Object>(); | 106 return MaybeHandle<Object>(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Placeholder for return value. | 109 // Placeholder for return value. |
| 109 Object* value = NULL; | 110 Object* value = NULL; |
| 110 | 111 |
| 111 typedef Object* (*JSEntryFunction)(byte* entry, | 112 typedef Object* (*JSEntryFunction)(Object* new_target, Object* function, |
| 112 Object* function, | 113 Object* receiver, int argc, |
| 113 Object* receiver, | |
| 114 int argc, | |
| 115 Object*** args); | 114 Object*** args); |
| 116 | 115 |
| 117 Handle<Code> code = is_construct | 116 Handle<Code> code = is_construct |
| 118 ? isolate->factory()->js_construct_entry_code() | 117 ? isolate->factory()->js_construct_entry_code() |
| 119 : isolate->factory()->js_entry_code(); | 118 : isolate->factory()->js_entry_code(); |
| 120 | 119 |
| 121 // Make sure that the global object of the context we're about to | 120 // Make sure that the global object of the context we're about to |
| 122 // make the current one is indeed a global object. | 121 // make the current one is indeed a global object. |
| 123 DCHECK(function->context()->global_object()->IsGlobalObject()); | 122 DCHECK(function->context()->global_object()->IsGlobalObject()); |
| 124 | 123 |
| 125 { | 124 { |
| 126 // Save and restore context around invocation and block the | 125 // Save and restore context around invocation and block the |
| 127 // allocation of handles without explicit handle scopes. | 126 // allocation of handles without explicit handle scopes. |
| 128 SaveContext save(isolate); | 127 SaveContext save(isolate); |
| 129 SealHandleScope shs(isolate); | 128 SealHandleScope shs(isolate); |
| 130 JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); | 129 JSEntryFunction stub_entry = FUNCTION_CAST<JSEntryFunction>(code->entry()); |
| 131 | 130 |
| 132 // Call the function through the right JS entry stub. | 131 // Call the function through the right JS entry stub. |
| 133 byte* ignored = nullptr; // TODO(bmeurer): Remove this altogether. | 132 Object* orig_func = *new_target; |
| 134 JSFunction* func = *function; | 133 JSFunction* func = *function; |
| 135 Object* recv = *receiver; | 134 Object* recv = *receiver; |
| 136 Object*** argv = reinterpret_cast<Object***>(args); | 135 Object*** argv = reinterpret_cast<Object***>(args); |
| 137 if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function); | 136 if (FLAG_profile_deserialization) PrintDeserializedCodeInfo(function); |
| 138 value = CALL_GENERATED_CODE(stub_entry, ignored, func, recv, argc, argv); | 137 value = CALL_GENERATED_CODE(stub_entry, orig_func, func, recv, argc, argv); |
| 139 } | 138 } |
| 140 | 139 |
| 141 #ifdef VERIFY_HEAP | 140 #ifdef VERIFY_HEAP |
| 142 if (FLAG_verify_heap) { | 141 if (FLAG_verify_heap) { |
| 143 value->ObjectVerify(); | 142 value->ObjectVerify(); |
| 144 } | 143 } |
| 145 #endif | 144 #endif |
| 146 | 145 |
| 147 // Update the pending exception flag and return the value. | 146 // Update the pending exception flag and return the value. |
| 148 bool has_exception = value->IsException(); | 147 bool has_exception = value->IsException(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 165 | 164 |
| 166 | 165 |
| 167 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, | 166 MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable, |
| 168 Handle<Object> receiver, int argc, | 167 Handle<Object> receiver, int argc, |
| 169 Handle<Object> argv[]) { | 168 Handle<Object> argv[]) { |
| 170 if (!callable->IsJSFunction()) { | 169 if (!callable->IsJSFunction()) { |
| 171 ASSIGN_RETURN_ON_EXCEPTION(isolate, callable, | 170 ASSIGN_RETURN_ON_EXCEPTION(isolate, callable, |
| 172 GetFunctionDelegate(isolate, callable), Object); | 171 GetFunctionDelegate(isolate, callable), Object); |
| 173 } | 172 } |
| 174 Handle<JSFunction> func = Handle<JSFunction>::cast(callable); | 173 Handle<JSFunction> func = Handle<JSFunction>::cast(callable); |
| 175 | 174 return Invoke(false, func, receiver, argc, argv, |
| 176 return Invoke(false, func, receiver, argc, argv); | 175 isolate->factory()->undefined_value()); |
| 177 } | 176 } |
| 178 | 177 |
| 179 | 178 |
| 180 MaybeHandle<Object> Execution::New(Handle<JSFunction> func, | 179 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, int argc, |
| 181 int argc, | |
| 182 Handle<Object> argv[]) { | 180 Handle<Object> argv[]) { |
| 183 return Invoke(true, func, handle(func->global_proxy()), argc, argv); | 181 return New(constructor, constructor, argc, argv); |
| 184 } | 182 } |
| 185 | 183 |
| 186 | 184 |
| 185 MaybeHandle<Object> Execution::New(Handle<JSFunction> constructor, |
| 186 Handle<JSFunction> new_target, int argc, |
| 187 Handle<Object> argv[]) { |
| 188 return Invoke(true, constructor, handle(constructor->global_proxy()), argc, |
| 189 argv, new_target); |
| 190 } |
| 191 |
| 192 |
| 187 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func, | 193 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func, |
| 188 Handle<Object> receiver, int argc, | 194 Handle<Object> receiver, int argc, |
| 189 Handle<Object> args[], | 195 Handle<Object> args[], |
| 190 MaybeHandle<Object>* exception_out) { | 196 MaybeHandle<Object>* exception_out) { |
| 191 bool is_termination = false; | 197 bool is_termination = false; |
| 192 Isolate* isolate = func->GetIsolate(); | 198 Isolate* isolate = func->GetIsolate(); |
| 193 MaybeHandle<Object> maybe_result; | 199 MaybeHandle<Object> maybe_result; |
| 194 if (exception_out != NULL) *exception_out = MaybeHandle<Object>(); | 200 if (exception_out != NULL) *exception_out = MaybeHandle<Object>(); |
| 195 // Enter a try-block while executing the JavaScript code. To avoid | 201 // Enter a try-block while executing the JavaScript code. To avoid |
| 196 // duplicate error printing it must be non-verbose. Also, to avoid | 202 // duplicate error printing it must be non-verbose. Also, to avoid |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 646 |
| 641 isolate_->counters()->stack_interrupts()->Increment(); | 647 isolate_->counters()->stack_interrupts()->Increment(); |
| 642 isolate_->counters()->runtime_profiler_ticks()->Increment(); | 648 isolate_->counters()->runtime_profiler_ticks()->Increment(); |
| 643 isolate_->runtime_profiler()->OptimizeNow(); | 649 isolate_->runtime_profiler()->OptimizeNow(); |
| 644 | 650 |
| 645 return isolate_->heap()->undefined_value(); | 651 return isolate_->heap()->undefined_value(); |
| 646 } | 652 } |
| 647 | 653 |
| 648 } // namespace internal | 654 } // namespace internal |
| 649 } // namespace v8 | 655 } // namespace v8 |
| OLD | NEW |