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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "src/v8.h" | 66 #include "src/v8.h" |
67 #include "src/v8threads.h" | 67 #include "src/v8threads.h" |
68 #include "src/version.h" | 68 #include "src/version.h" |
69 #include "src/vm-state-inl.h" | 69 #include "src/vm-state-inl.h" |
70 | 70 |
71 namespace v8 { | 71 namespace v8 { |
72 | 72 |
73 #define LOG_API(isolate, class_name, function_name) \ | 73 #define LOG_API(isolate, class_name, function_name) \ |
74 i::RuntimeCallTimerScope _runtime_timer( \ | 74 i::RuntimeCallTimerScope _runtime_timer( \ |
75 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ | 75 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ |
| 76 TRACE_RUNTIME_CALL(#class_name "::" #function_name); \ |
76 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) | 77 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) |
77 | 78 |
78 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) | 79 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
79 | 80 |
80 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ | 81 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ |
81 function_name, bailout_value, \ | 82 function_name, bailout_value, \ |
82 HandleScopeClass, do_callback) \ | 83 HandleScopeClass, do_callback) \ |
83 if (IsExecutionTerminatingCheck(isolate)) { \ | 84 if (IsExecutionTerminatingCheck(isolate)) { \ |
84 return bailout_value; \ | 85 return bailout_value; \ |
85 } \ | 86 } \ |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 } | 1758 } |
1758 } | 1759 } |
1759 | 1760 |
1760 | 1761 |
1761 MaybeLocal<Value> Script::Run(Local<Context> context) { | 1762 MaybeLocal<Value> Script::Run(Local<Context> context) { |
1762 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) | 1763 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) |
1763 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 1764 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
1764 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 1765 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
1765 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 1766 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
1766 TRACE_EVENT0("v8", "V8.Execute"); | 1767 TRACE_EVENT0("v8", "V8.Execute"); |
| 1768 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
1767 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); | 1769 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); |
1768 i::Handle<i::Object> receiver = isolate->global_proxy(); | 1770 i::Handle<i::Object> receiver = isolate->global_proxy(); |
1769 Local<Value> result; | 1771 Local<Value> result; |
1770 has_pending_exception = | 1772 has_pending_exception = |
1771 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), | 1773 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), |
1772 &result); | 1774 &result); |
1773 RETURN_ON_FAILED_EXECUTION(Value); | 1775 RETURN_ON_FAILED_EXECUTION(Value); |
1774 RETURN_ESCAPED(result); | 1776 RETURN_ESCAPED(result); |
1775 } | 1777 } |
1776 | 1778 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 // ScriptData takes care of pointer-aligning the data. | 1813 // ScriptData takes care of pointer-aligning the data. |
1812 script_data = new i::ScriptData(source->cached_data->data, | 1814 script_data = new i::ScriptData(source->cached_data->data, |
1813 source->cached_data->length); | 1815 source->cached_data->length); |
1814 } | 1816 } |
1815 | 1817 |
1816 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); | 1818 i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
1817 i::Handle<i::SharedFunctionInfo> result; | 1819 i::Handle<i::SharedFunctionInfo> result; |
1818 { | 1820 { |
1819 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); | 1821 i::HistogramTimerScope total(isolate->counters()->compile_script(), true); |
1820 TRACE_EVENT0("v8", "V8.CompileScript"); | 1822 TRACE_EVENT0("v8", "V8.CompileScript"); |
| 1823 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
1821 i::Handle<i::Object> name_obj; | 1824 i::Handle<i::Object> name_obj; |
1822 i::Handle<i::Object> source_map_url; | 1825 i::Handle<i::Object> source_map_url; |
1823 int line_offset = 0; | 1826 int line_offset = 0; |
1824 int column_offset = 0; | 1827 int column_offset = 0; |
1825 if (!source->resource_name.IsEmpty()) { | 1828 if (!source->resource_name.IsEmpty()) { |
1826 name_obj = Utils::OpenHandle(*(source->resource_name)); | 1829 name_obj = Utils::OpenHandle(*(source->resource_name)); |
1827 } | 1830 } |
1828 if (!source->resource_line_offset.IsEmpty()) { | 1831 if (!source->resource_line_offset.IsEmpty()) { |
1829 line_offset = static_cast<int>(source->resource_line_offset->Value()); | 1832 line_offset = static_cast<int>(source->resource_line_offset->Value()); |
1830 } | 1833 } |
(...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4335 return self->IsConstructor(); | 4338 return self->IsConstructor(); |
4336 } | 4339 } |
4337 | 4340 |
4338 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, | 4341 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, |
4339 Local<Value> recv, int argc, | 4342 Local<Value> recv, int argc, |
4340 Local<Value> argv[]) { | 4343 Local<Value> argv[]) { |
4341 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); | 4344 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); |
4342 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4345 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4343 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4346 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4344 TRACE_EVENT0("v8", "V8.Execute"); | 4347 TRACE_EVENT0("v8", "V8.Execute"); |
| 4348 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4345 auto self = Utils::OpenHandle(this); | 4349 auto self = Utils::OpenHandle(this); |
4346 auto recv_obj = Utils::OpenHandle(*recv); | 4350 auto recv_obj = Utils::OpenHandle(*recv); |
4347 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4351 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4348 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4352 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4349 Local<Value> result; | 4353 Local<Value> result; |
4350 has_pending_exception = !ToLocal<Value>( | 4354 has_pending_exception = !ToLocal<Value>( |
4351 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); | 4355 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); |
4352 RETURN_ON_FAILED_EXECUTION(Value); | 4356 RETURN_ON_FAILED_EXECUTION(Value); |
4353 RETURN_ESCAPED(result); | 4357 RETURN_ESCAPED(result); |
4354 } | 4358 } |
4355 | 4359 |
4356 | 4360 |
4357 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, | 4361 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, |
4358 v8::Local<v8::Value> argv[]) { | 4362 v8::Local<v8::Value> argv[]) { |
4359 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4363 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4360 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); | 4364 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); |
4361 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), | 4365 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), |
4362 Value); | 4366 Value); |
4363 } | 4367 } |
4364 | 4368 |
4365 | 4369 |
4366 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, | 4370 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, |
4367 Local<Value> argv[]) { | 4371 Local<Value> argv[]) { |
4368 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, | 4372 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, |
4369 Value); | 4373 Value); |
4370 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4374 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4371 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4375 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4372 TRACE_EVENT0("v8", "V8.Execute"); | 4376 TRACE_EVENT0("v8", "V8.Execute"); |
| 4377 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4373 auto self = Utils::OpenHandle(this); | 4378 auto self = Utils::OpenHandle(this); |
4374 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4379 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4375 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4380 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4376 Local<Value> result; | 4381 Local<Value> result; |
4377 has_pending_exception = !ToLocal<Value>( | 4382 has_pending_exception = !ToLocal<Value>( |
4378 i::Execution::New(isolate, self, self, argc, args), &result); | 4383 i::Execution::New(isolate, self, self, argc, args), &result); |
4379 RETURN_ON_FAILED_EXECUTION(Value); | 4384 RETURN_ON_FAILED_EXECUTION(Value); |
4380 RETURN_ESCAPED(result); | 4385 RETURN_ESCAPED(result); |
4381 } | 4386 } |
4382 | 4387 |
(...skipping 30 matching lines...) Expand all Loading... |
4413 .FromMaybe(Local<Object>()); | 4418 .FromMaybe(Local<Object>()); |
4414 } | 4419 } |
4415 | 4420 |
4416 | 4421 |
4417 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, | 4422 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, |
4418 v8::Local<v8::Value> argv[]) const { | 4423 v8::Local<v8::Value> argv[]) const { |
4419 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); | 4424 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); |
4420 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4425 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4421 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4426 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4422 TRACE_EVENT0("v8", "V8.Execute"); | 4427 TRACE_EVENT0("v8", "V8.Execute"); |
| 4428 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4423 auto self = Utils::OpenHandle(this); | 4429 auto self = Utils::OpenHandle(this); |
4424 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4430 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4425 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4431 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4426 Local<Object> result; | 4432 Local<Object> result; |
4427 has_pending_exception = !ToLocal<Object>( | 4433 has_pending_exception = !ToLocal<Object>( |
4428 i::Execution::New(isolate, self, self, argc, args), &result); | 4434 i::Execution::New(isolate, self, self, argc, args), &result); |
4429 RETURN_ON_FAILED_EXECUTION(Object); | 4435 RETURN_ON_FAILED_EXECUTION(Object); |
4430 RETURN_ESCAPED(result); | 4436 RETURN_ESCAPED(result); |
4431 } | 4437 } |
4432 | 4438 |
4433 | 4439 |
4434 Local<v8::Object> Function::NewInstance(int argc, | 4440 Local<v8::Object> Function::NewInstance(int argc, |
4435 v8::Local<v8::Value> argv[]) const { | 4441 v8::Local<v8::Value> argv[]) const { |
4436 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 4442 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
4437 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); | 4443 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); |
4438 } | 4444 } |
4439 | 4445 |
4440 | 4446 |
4441 MaybeLocal<v8::Value> Function::Call(Local<Context> context, | 4447 MaybeLocal<v8::Value> Function::Call(Local<Context> context, |
4442 v8::Local<v8::Value> recv, int argc, | 4448 v8::Local<v8::Value> recv, int argc, |
4443 v8::Local<v8::Value> argv[]) { | 4449 v8::Local<v8::Value> argv[]) { |
4444 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); | 4450 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); |
4445 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); | 4451 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); |
4446 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); | 4452 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); |
4447 TRACE_EVENT0("v8", "V8.Execute"); | 4453 TRACE_EVENT0("v8", "V8.Execute"); |
| 4454 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
4448 auto self = Utils::OpenHandle(this); | 4455 auto self = Utils::OpenHandle(this); |
4449 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); | 4456 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); |
4450 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); | 4457 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); |
4451 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); | 4458 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); |
4452 Local<Value> result; | 4459 Local<Value> result; |
4453 has_pending_exception = !ToLocal<Value>( | 4460 has_pending_exception = !ToLocal<Value>( |
4454 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); | 4461 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); |
4455 RETURN_ON_FAILED_EXECUTION(Value); | 4462 RETURN_ON_FAILED_EXECUTION(Value); |
4456 RETURN_ESCAPED(result); | 4463 RETURN_ESCAPED(result); |
4457 } | 4464 } |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5582 | 5589 |
5583 return env; | 5590 return env; |
5584 } | 5591 } |
5585 | 5592 |
5586 Local<Context> v8::Context::New(v8::Isolate* external_isolate, | 5593 Local<Context> v8::Context::New(v8::Isolate* external_isolate, |
5587 v8::ExtensionConfiguration* extensions, | 5594 v8::ExtensionConfiguration* extensions, |
5588 v8::Local<ObjectTemplate> global_template, | 5595 v8::Local<ObjectTemplate> global_template, |
5589 v8::Local<Value> global_object) { | 5596 v8::Local<Value> global_object) { |
5590 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 5597 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
5591 LOG_API(isolate, Context, New); | 5598 LOG_API(isolate, Context, New); |
| 5599 TRACE_EVENT0("v8", "V8.NewContext"); |
| 5600 TRACE_CHECK_AND_SET_RUNTIME_CALLS_TRACING(); |
5592 i::HandleScope scope(isolate); | 5601 i::HandleScope scope(isolate); |
5593 ExtensionConfiguration no_extensions; | 5602 ExtensionConfiguration no_extensions; |
5594 if (extensions == NULL) extensions = &no_extensions; | 5603 if (extensions == NULL) extensions = &no_extensions; |
5595 i::Handle<i::Context> env = | 5604 i::Handle<i::Context> env = |
5596 CreateEnvironment(isolate, extensions, global_template, global_object); | 5605 CreateEnvironment(isolate, extensions, global_template, global_object); |
5597 if (env.is_null()) { | 5606 if (env.is_null()) { |
5598 if (isolate->has_pending_exception()) { | 5607 if (isolate->has_pending_exception()) { |
5599 isolate->OptionalRescheduleException(true); | 5608 isolate->OptionalRescheduleException(true); |
5600 } | 5609 } |
5601 return Local<Context>(); | 5610 return Local<Context>(); |
(...skipping 3169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8771 | 8780 |
8772 | 8781 |
8773 void InvokeAccessorGetterCallback( | 8782 void InvokeAccessorGetterCallback( |
8774 v8::Local<v8::Name> property, | 8783 v8::Local<v8::Name> property, |
8775 const v8::PropertyCallbackInfo<v8::Value>& info, | 8784 const v8::PropertyCallbackInfo<v8::Value>& info, |
8776 v8::AccessorNameGetterCallback getter) { | 8785 v8::AccessorNameGetterCallback getter) { |
8777 // Leaving JavaScript. | 8786 // Leaving JavaScript. |
8778 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8787 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8779 RuntimeCallTimerScope timer(isolate, | 8788 RuntimeCallTimerScope timer(isolate, |
8780 &RuntimeCallStats::AccessorGetterCallback); | 8789 &RuntimeCallStats::AccessorGetterCallback); |
| 8790 TRACE_RUNTIME_CALL("AccessorGetterCallback"); |
8781 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( | 8791 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( |
8782 getter)); | 8792 getter)); |
8783 VMState<EXTERNAL> state(isolate); | 8793 VMState<EXTERNAL> state(isolate); |
8784 ExternalCallbackScope call_scope(isolate, getter_address); | 8794 ExternalCallbackScope call_scope(isolate, getter_address); |
8785 getter(property, info); | 8795 getter(property, info); |
8786 } | 8796 } |
8787 | 8797 |
8788 | 8798 |
8789 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, | 8799 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, |
8790 v8::FunctionCallback callback) { | 8800 v8::FunctionCallback callback) { |
8791 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8801 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8792 RuntimeCallTimerScope timer(isolate, | 8802 RuntimeCallTimerScope timer(isolate, |
8793 &RuntimeCallStats::InvokeFunctionCallback); | 8803 &RuntimeCallStats::InvokeFunctionCallback); |
| 8804 TRACE_RUNTIME_CALL("InvokeFunctionCallback"); |
8794 Address callback_address = | 8805 Address callback_address = |
8795 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8806 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8796 VMState<EXTERNAL> state(isolate); | 8807 VMState<EXTERNAL> state(isolate); |
8797 ExternalCallbackScope call_scope(isolate, callback_address); | 8808 ExternalCallbackScope call_scope(isolate, callback_address); |
8798 callback(info); | 8809 callback(info); |
8799 } | 8810 } |
8800 | 8811 |
8801 | 8812 |
8802 } // namespace internal | 8813 } // namespace internal |
8803 } // namespace v8 | 8814 } // namespace v8 |
OLD | NEW |