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