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