| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 | 144 |
| 145 MaybeHandle<Object> Execution::New(Handle<JSFunction> func, | 145 MaybeHandle<Object> Execution::New(Handle<JSFunction> func, |
| 146 int argc, | 146 int argc, |
| 147 Handle<Object> argv[]) { | 147 Handle<Object> argv[]) { |
| 148 return Invoke(true, func, handle(func->global_proxy()), argc, argv); | 148 return Invoke(true, func, handle(func->global_proxy()), argc, argv); |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func, | 152 MaybeHandle<Object> Execution::TryCall(Handle<JSFunction> func, |
| 153 Handle<Object> receiver, | 153 Handle<Object> receiver, int argc, |
| 154 int argc, | |
| 155 Handle<Object> args[], | 154 Handle<Object> args[], |
| 156 Handle<Object>* exception_out) { | 155 MaybeHandle<Object>* exception_out) { |
| 156 bool is_termination = false; |
| 157 Isolate* isolate = func->GetIsolate(); |
| 158 MaybeHandle<Object> maybe_result; |
| 159 if (exception_out != NULL) *exception_out = MaybeHandle<Object>(); |
| 157 // Enter a try-block while executing the JavaScript code. To avoid | 160 // Enter a try-block while executing the JavaScript code. To avoid |
| 158 // duplicate error printing it must be non-verbose. Also, to avoid | 161 // duplicate error printing it must be non-verbose. Also, to avoid |
| 159 // creating message objects during stack overflow we shouldn't | 162 // creating message objects during stack overflow we shouldn't |
| 160 // capture messages. | 163 // capture messages. |
| 161 v8::TryCatch catcher; | 164 { |
| 162 catcher.SetVerbose(false); | 165 v8::TryCatch catcher; |
| 163 catcher.SetCaptureMessage(false); | 166 catcher.SetVerbose(false); |
| 167 catcher.SetCaptureMessage(false); |
| 164 | 168 |
| 165 // Get isolate now, because handle might be persistent | 169 maybe_result = Invoke(false, func, receiver, argc, args); |
| 166 // and get destroyed in the next call. | |
| 167 Isolate* isolate = func->GetIsolate(); | |
| 168 MaybeHandle<Object> maybe_result = Invoke(false, func, receiver, argc, args); | |
| 169 | 170 |
| 170 if (maybe_result.is_null()) { | 171 if (maybe_result.is_null()) { |
| 171 DCHECK(catcher.HasCaught()); | 172 DCHECK(catcher.HasCaught()); |
| 172 DCHECK(isolate->has_pending_exception()); | 173 DCHECK(isolate->has_pending_exception()); |
| 173 DCHECK(isolate->external_caught_exception()); | 174 DCHECK(isolate->external_caught_exception()); |
| 174 if (exception_out != NULL) { | 175 if (exception_out != NULL) { |
| 175 if (isolate->pending_exception() == | 176 if (isolate->pending_exception() == |
| 176 isolate->heap()->termination_exception()) { | 177 isolate->heap()->termination_exception()) { |
| 177 *exception_out = isolate->factory()->termination_exception(); | 178 is_termination = true; |
| 178 } else { | 179 } else { |
| 179 *exception_out = v8::Utils::OpenHandle(*catcher.Exception()); | 180 *exception_out = v8::Utils::OpenHandle(*catcher.Exception()); |
| 181 } |
| 180 } | 182 } |
| 183 isolate->OptionalRescheduleException(true); |
| 181 } | 184 } |
| 182 isolate->OptionalRescheduleException(true); | 185 |
| 186 DCHECK(!isolate->has_pending_exception()); |
| 187 DCHECK(!isolate->external_caught_exception()); |
| 183 } | 188 } |
| 184 | 189 if (is_termination) isolate->TerminateExecution(); |
| 185 DCHECK(!isolate->has_pending_exception()); | |
| 186 DCHECK(!isolate->external_caught_exception()); | |
| 187 return maybe_result; | 190 return maybe_result; |
| 188 } | 191 } |
| 189 | 192 |
| 190 | 193 |
| 191 Handle<Object> Execution::GetFunctionDelegate(Isolate* isolate, | 194 Handle<Object> Execution::GetFunctionDelegate(Isolate* isolate, |
| 192 Handle<Object> object) { | 195 Handle<Object> object) { |
| 193 DCHECK(!object->IsJSFunction()); | 196 DCHECK(!object->IsJSFunction()); |
| 194 Factory* factory = isolate->factory(); | 197 Factory* factory = isolate->factory(); |
| 195 | 198 |
| 196 // If you return a function from here, it will be called when an | 199 // If you return a function from here, it will be called when an |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // Objects created through the API can have an instance-call handler | 232 // Objects created through the API can have an instance-call handler |
| 230 // that should be used when calling the object as a function. | 233 // that should be used when calling the object as a function. |
| 231 if (fun->IsHeapObject() && | 234 if (fun->IsHeapObject() && |
| 232 HeapObject::cast(fun)->map()->has_instance_call_handler()) { | 235 HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
| 233 return Handle<JSFunction>( | 236 return Handle<JSFunction>( |
| 234 isolate->native_context()->call_as_function_delegate()); | 237 isolate->native_context()->call_as_function_delegate()); |
| 235 } | 238 } |
| 236 | 239 |
| 237 // If the Object doesn't have an instance-call handler we should | 240 // If the Object doesn't have an instance-call handler we should |
| 238 // throw a non-callable exception. | 241 // throw a non-callable exception. |
| 239 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError( | 242 THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable", |
| 240 "called_non_callable", i::HandleVector<i::Object>(&object, 1)); | 243 i::HandleVector<i::Object>(&object, 1)), |
| 241 | 244 Object); |
| 242 return isolate->Throw<Object>(error_obj); | |
| 243 } | 245 } |
| 244 | 246 |
| 245 | 247 |
| 246 Handle<Object> Execution::GetConstructorDelegate(Isolate* isolate, | 248 Handle<Object> Execution::GetConstructorDelegate(Isolate* isolate, |
| 247 Handle<Object> object) { | 249 Handle<Object> object) { |
| 248 DCHECK(!object->IsJSFunction()); | 250 DCHECK(!object->IsJSFunction()); |
| 249 | 251 |
| 250 // If you return a function from here, it will be called when an | 252 // If you return a function from here, it will be called when an |
| 251 // attempt is made to call the given object as a constructor. | 253 // attempt is made to call the given object as a constructor. |
| 252 | 254 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Objects created through the API can have an instance-call handler | 288 // Objects created through the API can have an instance-call handler |
| 287 // that should be used when calling the object as a function. | 289 // that should be used when calling the object as a function. |
| 288 if (fun->IsHeapObject() && | 290 if (fun->IsHeapObject() && |
| 289 HeapObject::cast(fun)->map()->has_instance_call_handler()) { | 291 HeapObject::cast(fun)->map()->has_instance_call_handler()) { |
| 290 return Handle<JSFunction>( | 292 return Handle<JSFunction>( |
| 291 isolate->native_context()->call_as_constructor_delegate()); | 293 isolate->native_context()->call_as_constructor_delegate()); |
| 292 } | 294 } |
| 293 | 295 |
| 294 // If the Object doesn't have an instance-call handler we should | 296 // If the Object doesn't have an instance-call handler we should |
| 295 // throw a non-callable exception. | 297 // throw a non-callable exception. |
| 296 i::Handle<i::Object> error_obj = isolate->factory()->NewTypeError( | 298 THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable", |
| 297 "called_non_callable", i::HandleVector<i::Object>(&object, 1)); | 299 i::HandleVector<i::Object>(&object, 1)), |
| 298 return isolate->Throw<Object>(error_obj); | 300 Object); |
| 299 } | 301 } |
| 300 | 302 |
| 301 | 303 |
| 302 void StackGuard::EnableInterrupts() { | 304 void StackGuard::EnableInterrupts() { |
| 303 ExecutionAccess access(isolate_); | 305 ExecutionAccess access(isolate_); |
| 304 if (has_pending_interrupts(access)) { | 306 if (has_pending_interrupts(access)) { |
| 305 set_interrupt_limits(access); | 307 set_interrupt_limits(access); |
| 306 } | 308 } |
| 307 } | 309 } |
| 308 | 310 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 700 } |
| 699 | 701 |
| 700 isolate_->counters()->stack_interrupts()->Increment(); | 702 isolate_->counters()->stack_interrupts()->Increment(); |
| 701 isolate_->counters()->runtime_profiler_ticks()->Increment(); | 703 isolate_->counters()->runtime_profiler_ticks()->Increment(); |
| 702 isolate_->runtime_profiler()->OptimizeNow(); | 704 isolate_->runtime_profiler()->OptimizeNow(); |
| 703 | 705 |
| 704 return isolate_->heap()->undefined_value(); | 706 return isolate_->heap()->undefined_value(); |
| 705 } | 707 } |
| 706 | 708 |
| 707 } } // namespace v8::internal | 709 } } // namespace v8::internal |
| OLD | NEW |