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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "src/v8.h" | 65 #include "src/v8.h" |
66 #include "src/v8threads.h" | 66 #include "src/v8threads.h" |
67 #include "src/version.h" | 67 #include "src/version.h" |
68 #include "src/vm-state-inl.h" | 68 #include "src/vm-state-inl.h" |
69 | 69 |
70 namespace v8 { | 70 namespace v8 { |
71 | 71 |
72 #define LOG_API(isolate, class_name, function_name) \ | 72 #define LOG_API(isolate, class_name, function_name) \ |
73 i::RuntimeCallTimerScope _runtime_timer( \ | 73 i::RuntimeCallTimerScope _runtime_timer( \ |
74 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ | 74 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ |
| 75 TRACE_RUNTIME_CALL(#class_name "::" #function_name); \ |
75 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) | 76 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) |
76 | 77 |
77 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) | 78 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
78 | 79 |
79 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ | 80 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ |
80 function_name, bailout_value, \ | 81 function_name, bailout_value, \ |
81 HandleScopeClass, do_callback) \ | 82 HandleScopeClass, do_callback) \ |
82 if (IsExecutionTerminatingCheck(isolate)) { \ | 83 if (IsExecutionTerminatingCheck(isolate)) { \ |
83 return bailout_value; \ | 84 return bailout_value; \ |
84 } \ | 85 } \ |
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 } | 1739 } |
1739 } | 1740 } |
1740 | 1741 |
1741 | 1742 |
1742 MaybeLocal<Value> Script::Run(Local<Context> context) { | 1743 MaybeLocal<Value> Script::Run(Local<Context> context) { |
1743 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) | 1744 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) |
1744 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 1745 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
1745 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1746 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
1746 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 1747 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
1747 TRACE_EVENT0("v8", "V8.Execute"); | 1748 TRACE_EVENT0("v8", "V8.Execute"); |
| 1749 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
1748 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); | 1750 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); |
1749 i::Handle<i::Object> receiver = isolate->global_proxy(); | 1751 i::Handle<i::Object> receiver = isolate->global_proxy(); |
1750 Local<Value> result; | 1752 Local<Value> result; |
1751 has_pending_exception = | 1753 has_pending_exception = |
1752 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), | 1754 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), |
1753 &result); | 1755 &result); |
1754 RETURN_ON_FAILED_EXECUTION(Value); | 1756 RETURN_ON_FAILED_EXECUTION(Value); |
1755 RETURN_ESCAPED(result); | 1757 RETURN_ESCAPED(result); |
1756 } | 1758 } |
1757 | 1759 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 // ScriptData takes care of pointer-aligning the data. | 1794 // ScriptData takes care of pointer-aligning the data. |
1793 script_data = new i::ScriptData(source->cached_data->data, | 1795 script_data = new i::ScriptData(source->cached_data->data, |
1794 source->cached_data->length); | 1796 source->cached_data->length); |
1795 } | 1797 } |
1796 | 1798 |
1797 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); | 1799 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
1798 i::Handle<i::SharedFunctionInfo> result; | 1800 i::Handle<i::SharedFunctionInfo> result; |
1799 { | 1801 { |
1800 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); | 1802 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); |
1801 TRACE_EVENT0("v8", "V8.CompileScript"); | 1803 TRACE_EVENT0("v8", "V8.CompileScript"); |
| 1804 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
1802 i::Handle<i::Object> name_obj; | 1805 i::Handle<i::Object> name_obj; |
1803 i::Handle<i::Object> source_map_url; | 1806 i::Handle<i::Object> source_map_url; |
1804 int line_offset = 0; | 1807 int line_offset = 0; |
1805 int column_offset = 0; | 1808 int column_offset = 0; |
1806 if (!source->resource_name.IsEmpty()) { | 1809 if (!source->resource_name.IsEmpty()) { |
1807 name_obj = Utils::OpenHandle(*(source->resource_name)); | 1810 name_obj = Utils::OpenHandle(*(source->resource_name)); |
1808 } | 1811 } |
1809 if (!source->resource_line_offset.IsEmpty()) { | 1812 if (!source->resource_line_offset.IsEmpty()) { |
1810 line_offset = static_cast<int>(source->resource_line_offset->Value()); | 1813 line_offset = static_cast<int>(source->resource_line_offset->Value()); |
1811 } | 1814 } |
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4316 return self->IsConstructor(); | 4319 return self->IsConstructor(); |
4317 } | 4320 } |
4318 | 4321 |
4319 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, | 4322 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, |
4320 Local<Value> recv, int argc, | 4323 Local<Value> recv, int argc, |
4321 Local<Value> argv[]) { | 4324 Local<Value> argv[]) { |
4322 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); | 4325 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); |
4323 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4326 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4324 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4327 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4325 TRACE_EVENT0("v8", "V8.Execute"); | 4328 TRACE_EVENT0("v8", "V8.Execute"); |
| 4329 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4326 auto self = Utils::OpenHandle(this); | 4330 auto self = Utils::OpenHandle(this); |
4327 auto recv_obj = Utils::OpenHandle(*recv); | 4331 auto recv_obj = Utils::OpenHandle(*recv); |
4328 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4332 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4329 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4333 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4330 Local<Value> result; | 4334 Local<Value> result; |
4331 has_pending_exception = !ToLocal<Value>( | 4335 has_pending_exception = !ToLocal<Value>( |
4332 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); | 4336 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); |
4333 RETURN_ON_FAILED_EXECUTION(Value); | 4337 RETURN_ON_FAILED_EXECUTION(Value); |
4334 RETURN_ESCAPED(result); | 4338 RETURN_ESCAPED(result); |
4335 } | 4339 } |
4336 | 4340 |
4337 | 4341 |
4338 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, | 4342 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, |
4339 v8::Local<v8::Value> argv[]) { | 4343 v8::Local<v8::Value> argv[]) { |
4340 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4344 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4341 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); | 4345 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
4342 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), | 4346 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), |
4343 Value); | 4347 Value); |
4344 } | 4348 } |
4345 | 4349 |
4346 | 4350 |
4347 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, | 4351 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, |
4348 Local<Value> argv[]) { | 4352 Local<Value> argv[]) { |
4349 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, | 4353 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, |
4350 Value); | 4354 Value); |
4351 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4355 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4352 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4356 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4353 TRACE_EVENT0("v8", "V8.Execute"); | 4357 TRACE_EVENT0("v8", "V8.Execute"); |
| 4358 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4354 auto self = Utils::OpenHandle(this); | 4359 auto self = Utils::OpenHandle(this); |
4355 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4360 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4356 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4361 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4357 Local<Value> result; | 4362 Local<Value> result; |
4358 has_pending_exception = !ToLocal<Value>( | 4363 has_pending_exception = !ToLocal<Value>( |
4359 i::Execution::New(isolate, self, self, argc, args), &result); | 4364 i::Execution::New(isolate, self, self, argc, args), &result); |
4360 RETURN_ON_FAILED_EXECUTION(Value); | 4365 RETURN_ON_FAILED_EXECUTION(Value); |
4361 RETURN_ESCAPED(result); | 4366 RETURN_ESCAPED(result); |
4362 } | 4367 } |
4363 | 4368 |
(...skipping 30 matching lines...) Expand all Loading... |
4394 .FromMaybe(Local<Object>()); | 4399 .FromMaybe(Local<Object>()); |
4395 } | 4400 } |
4396 | 4401 |
4397 | 4402 |
4398 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, | 4403 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, |
4399 v8::Local<v8::Value> argv[]) const { | 4404 v8::Local<v8::Value> argv[]) const { |
4400 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); | 4405 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); |
4401 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4406 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4402 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4407 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4403 TRACE_EVENT0("v8", "V8.Execute"); | 4408 TRACE_EVENT0("v8", "V8.Execute"); |
| 4409 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4404 auto self = Utils::OpenHandle(this); | 4410 auto self = Utils::OpenHandle(this); |
4405 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4411 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4406 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4412 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4407 Local<Object> result; | 4413 Local<Object> result; |
4408 has_pending_exception = !ToLocal<Object>( | 4414 has_pending_exception = !ToLocal<Object>( |
4409 i::Execution::New(isolate, self, self, argc, args), &result); | 4415 i::Execution::New(isolate, self, self, argc, args), &result); |
4410 RETURN_ON_FAILED_EXECUTION(Object); | 4416 RETURN_ON_FAILED_EXECUTION(Object); |
4411 RETURN_ESCAPED(result); | 4417 RETURN_ESCAPED(result); |
4412 } | 4418 } |
4413 | 4419 |
4414 | 4420 |
4415 Local<v8::Object> Function::NewInstance(int argc, | 4421 Local<v8::Object> Function::NewInstance(int argc, |
4416 v8::Local<v8::Value> argv[]) const { | 4422 v8::Local<v8::Value> argv[]) const { |
4417 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4423 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4418 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); | 4424 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); |
4419 } | 4425 } |
4420 | 4426 |
4421 | 4427 |
4422 MaybeLocal<v8::Value> Function::Call(Local<Context> context, | 4428 MaybeLocal<v8::Value> Function::Call(Local<Context> context, |
4423 v8::Local<v8::Value> recv, int argc, | 4429 v8::Local<v8::Value> recv, int argc, |
4424 v8::Local<v8::Value> argv[]) { | 4430 v8::Local<v8::Value> argv[]) { |
4425 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); | 4431 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); |
4426 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4432 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4427 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4433 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4428 TRACE_EVENT0("v8", "V8.Execute"); | 4434 TRACE_EVENT0("v8", "V8.Execute"); |
| 4435 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4429 auto self = Utils::OpenHandle(this); | 4436 auto self = Utils::OpenHandle(this); |
4430 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); | 4437 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
4431 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4438 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4432 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4439 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4433 Local<Value> result; | 4440 Local<Value> result; |
4434 has_pending_exception = !ToLocal<Value>( | 4441 has_pending_exception = !ToLocal<Value>( |
4435 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); | 4442 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); |
4436 RETURN_ON_FAILED_EXECUTION(Value); | 4443 RETURN_ON_FAILED_EXECUTION(Value); |
4437 RETURN_ESCAPED(result); | 4444 RETURN_ESCAPED(result); |
4438 } | 4445 } |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5563 | 5570 |
5564 return env; | 5571 return env; |
5565 } | 5572 } |
5566 | 5573 |
5567 Local<Context> v8::Context::New(v8::Isolate* external_isolate, | 5574 Local<Context> v8::Context::New(v8::Isolate* external_isolate, |
5568 v8::ExtensionConfiguration* extensions, | 5575 v8::ExtensionConfiguration* extensions, |
5569 v8::Local<ObjectTemplate> global_template, | 5576 v8::Local<ObjectTemplate> global_template, |
5570 v8::Local<Value> global_object) { | 5577 v8::Local<Value> global_object) { |
5571 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 5578 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
5572 LOG_API(isolate, Context, New); | 5579 LOG_API(isolate, Context, New); |
| 5580 TRACE_EVENT0("v8", "V8.NewContext"); |
| 5581 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
5573 i::HandleScope scope(isolate); | 5582 i::HandleScope scope(isolate); |
5574 ExtensionConfiguration no_extensions; | 5583 ExtensionConfiguration no_extensions; |
5575 if (extensions == NULL) extensions = &no_extensions; | 5584 if (extensions == NULL) extensions = &no_extensions; |
5576 i::Handle<i::Context> env = | 5585 i::Handle<i::Context> env = |
5577 CreateEnvironment(isolate, extensions, global_template, global_object); | 5586 CreateEnvironment(isolate, extensions, global_template, global_object); |
5578 if (env.is_null()) { | 5587 if (env.is_null()) { |
5579 if (isolate->has_pending_exception()) { | 5588 if (isolate->has_pending_exception()) { |
5580 isolate->OptionalRescheduleException(true); | 5589 isolate->OptionalRescheduleException(true); |
5581 } | 5590 } |
5582 return Local<Context>(); | 5591 return Local<Context>(); |
(...skipping 3172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8755 | 8764 |
8756 | 8765 |
8757 void InvokeAccessorGetterCallback( | 8766 void InvokeAccessorGetterCallback( |
8758 v8::Local<v8::Name> property, | 8767 v8::Local<v8::Name> property, |
8759 const v8::PropertyCallbackInfo<v8::Value>& info, | 8768 const v8::PropertyCallbackInfo<v8::Value>& info, |
8760 v8::AccessorNameGetterCallback getter) { | 8769 v8::AccessorNameGetterCallback getter) { |
8761 // Leaving JavaScript. | 8770 // Leaving JavaScript. |
8762 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8771 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8763 RuntimeCallTimerScope timer(isolate, | 8772 RuntimeCallTimerScope timer(isolate, |
8764 &RuntimeCallStats::AccessorGetterCallback); | 8773 &RuntimeCallStats::AccessorGetterCallback); |
| 8774 TRACE_RUNTIME_CALL("AccessorGetterCallback"); |
8765 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( | 8775 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( |
8766 getter)); | 8776 getter)); |
8767 VMState<EXTERNAL> state(isolate); | 8777 VMState<EXTERNAL> state(isolate); |
8768 ExternalCallbackScope call_scope(isolate, getter_address); | 8778 ExternalCallbackScope call_scope(isolate, getter_address); |
8769 getter(property, info); | 8779 getter(property, info); |
8770 } | 8780 } |
8771 | 8781 |
8772 | 8782 |
8773 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, | 8783 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
8774 v8::FunctionCallback callback) { | 8784 v8::FunctionCallback callback) { |
8775 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8785 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8776 RuntimeCallTimerScope timer(isolate, | 8786 RuntimeCallTimerScope timer(isolate, |
8777 &RuntimeCallStats::InvokeFunctionCallback); | 8787 &RuntimeCallStats::InvokeFunctionCallback); |
| 8788 TRACE_RUNTIME_CALL("InvokeFunctionCallback"); |
8778 Address callback_address = | 8789 Address callback_address = |
8779 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8790 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8780 VMState<EXTERNAL> state(isolate); | 8791 VMState<EXTERNAL> state(isolate); |
8781 ExternalCallbackScope call_scope(isolate, callback_address); | 8792 ExternalCallbackScope call_scope(isolate, callback_address); |
8782 callback(info); | 8793 callback(info); |
8783 } | 8794 } |
8784 | 8795 |
8785 | 8796 |
8786 } // namespace internal | 8797 } // namespace internal |
8787 } // namespace v8 | 8798 } // namespace v8 |
OLD | NEW |