diff --git a/src/api.cc b/src/api.cc index e8df210dac..7476e2b0b2 100644 --- a/src/api.cc +++ b/src/api.cc @@ -43,11 +43,12 @@ #ifdef ENABLE_HEAP_PROTECTION #define ENTER_V8 i::VMState __state__(i::OTHER) +#define LEAVE_V8 i::VMState __state__(i::EXTERNAL) #else #define ENTER_V8 ((void) 0) +#define LEAVE_V8 ((void) 0) #endif - namespace v8 { @@ -103,6 +104,7 @@ static FatalErrorCallback exception_behavior = NULL; static void DefaultFatalErrorHandler(const char* location, const char* message) { + ENTER_V8; API_Fatal(location, message); } @@ -122,7 +124,10 @@ static FatalErrorCallback& GetFatalErrorHandler() { void i::V8::FatalProcessOutOfMemory(const char* location) { has_shut_down = true; FatalErrorCallback callback = GetFatalErrorHandler(); - callback(location, "Allocation failed - process out of memory"); + { + LEAVE_V8; + callback(location, "Allocation failed - process out of memory"); + } // If the callback returns, we stop execution. UNREACHABLE(); } @@ -135,7 +140,10 @@ void V8::SetFatalErrorHandler(FatalErrorCallback that) { bool Utils::ReportApiFailure(const char* location, const char* message) { FatalErrorCallback callback = GetFatalErrorHandler(); - callback(location, message); + { + LEAVE_V8; + callback(location, message); + } has_shut_down = true; return false; } @@ -155,14 +163,20 @@ static inline bool ApiCheck(bool condition, static bool ReportV8Dead(const char* location) { FatalErrorCallback callback = GetFatalErrorHandler(); - callback(location, "V8 is no longer usable"); + { + LEAVE_V8; + callback(location, "V8 is no longer usable"); + } return true; } static bool ReportEmptyHandle(const char* location) { FatalErrorCallback callback = GetFatalErrorHandler(); - callback(location, "Reading from empty handle"); + { + LEAVE_V8; + callback(location, "Reading from empty handle"); + } return true; } @@ -200,6 +214,7 @@ static i::StringInputBuffer write_input_buffer; static void EnsureInitialized(const char* location) { + ENTER_V8; if (IsDeadCheck(location)) return; ApiCheck(v8::V8::Initialize(), location, "Error initializing V8"); } @@ -219,6 +234,7 @@ void ImplementationUtilities::ZapHandleRange(void** begin, void** end) { v8::Handle ImplementationUtilities::Undefined() { + ENTER_V8; if (IsDeadCheck("v8::Undefined()")) return v8::Handle(); EnsureInitialized("v8::Undefined()"); return v8::Handle(ToApi(i::Factory::undefined_value())); @@ -226,6 +242,7 @@ v8::Handle ImplementationUtilities::Undefined() { v8::Handle ImplementationUtilities::Null() { + ENTER_V8; if (IsDeadCheck("v8::Null()")) return v8::Handle(); EnsureInitialized("v8::Null()"); return v8::Handle(ToApi(i::Factory::null_value())); @@ -233,6 +250,7 @@ v8::Handle ImplementationUtilities::Null() { v8::Handle ImplementationUtilities::True() { + ENTER_V8; if (IsDeadCheck("v8::True()")) return v8::Handle(); EnsureInitialized("v8::True()"); return v8::Handle(ToApi(i::Factory::true_value())); @@ -240,6 +258,7 @@ v8::Handle ImplementationUtilities::True() { v8::Handle ImplementationUtilities::False() { + ENTER_V8; if (IsDeadCheck("v8::False()")) return v8::Handle(); EnsureInitialized("v8::False()"); return v8::Handle(ToApi(i::Factory::false_value())); @@ -257,6 +276,7 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) { v8::Handle ThrowException(v8::Handle value) { + ENTER_V8; if (IsDeadCheck("v8::ThrowException()")) return v8::Handle(); // If we're passed an empty handle, we throw an undefined exception // to deal more gracefully with out of memory situations. @@ -342,6 +362,7 @@ bool SetResourceConstraints(ResourceConstraints* constraints) { void** V8::GlobalizeReference(void** obj) { + ENTER_V8; LOG_API("Persistent::New"); if (IsDeadCheck("V8::Persistent::New")) return NULL; i::Handle result = @@ -413,6 +434,7 @@ void** v8::HandleScope::CreateHandle(void* value) { void Context::Enter() { + ENTER_V8; if (IsDeadCheck("v8::Context::Enter()")) return; i::Handle env = Utils::OpenHandle(this); thread_local.EnterContext(env); @@ -554,6 +576,7 @@ static void InitializeFunctionTemplate( Local FunctionTemplate::PrototypeTemplate() { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::PrototypeTemplate()")) { return Local(); } @@ -567,6 +590,7 @@ Local FunctionTemplate::PrototypeTemplate() { void FunctionTemplate::Inherit(v8::Handle value) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::Inherit()")) return; Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); } @@ -603,6 +627,7 @@ Local FunctionTemplate::New(InvocationCallback callback, Local Signature::New(Handle receiver, int argc, Handle argv[]) { + ENTER_V8; EnsureInitialized("v8::Signature::New()"); LOG_API("Signature::New"); i::Handle struct_obj = @@ -629,6 +654,7 @@ Local TypeSwitch::New(Handle type) { Local TypeSwitch::New(int argc, Handle types[]) { + ENTER_V8; EnsureInitialized("v8::TypeSwitch::New()"); LOG_API("TypeSwitch::New"); i::Handle vector = i::Factory::NewFixedArray(argc); @@ -658,6 +684,7 @@ int TypeSwitch::match(v8::Handle value) { void FunctionTemplate::SetCallHandler(InvocationCallback callback, v8::Handle data) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::SetCallHandler()")) return; HandleScope scope; i::Handle struct_obj = @@ -678,6 +705,7 @@ void FunctionTemplate::AddInstancePropertyAccessor( v8::Handle data, v8::AccessControl settings, v8::PropertyAttribute attributes) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::AddInstancePropertyAccessor()")) { return; } @@ -705,6 +733,7 @@ void FunctionTemplate::AddInstancePropertyAccessor( Local FunctionTemplate::InstanceTemplate() { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::InstanceTemplate()") || EmptyCheck("v8::FunctionTemplate::InstanceTemplate()", this)) return Local(); @@ -720,12 +749,14 @@ Local FunctionTemplate::InstanceTemplate() { void FunctionTemplate::SetClassName(Handle name) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::SetClassName()")) return; Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); } void FunctionTemplate::SetHiddenPrototype(bool value) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::SetHiddenPrototype()")) return; Utils::OpenHandle(this)->set_hidden_prototype(value); } @@ -738,6 +769,7 @@ void FunctionTemplate::SetNamedInstancePropertyHandler( NamedPropertyDeleter remover, NamedPropertyEnumerator enumerator, Handle data) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::SetNamedInstancePropertyHandler()")) { return; } @@ -764,6 +796,7 @@ void FunctionTemplate::SetIndexedInstancePropertyHandler( IndexedPropertyDeleter remover, IndexedPropertyEnumerator enumerator, Handle data) { + ENTER_V8; if (IsDeadCheck( "v8::FunctionTemplate::SetIndexedInstancePropertyHandler()")) { return; @@ -787,6 +820,7 @@ void FunctionTemplate::SetIndexedInstancePropertyHandler( void FunctionTemplate::SetInstanceCallAsFunctionHandler( InvocationCallback callback, Handle data) { + ENTER_V8; if (IsDeadCheck("v8::FunctionTemplate::SetInstanceCallAsFunctionHandler()")) { return; } @@ -846,6 +880,7 @@ void ObjectTemplate::SetAccessor(v8::Handle name, v8::Handle data, AccessControl settings, PropertyAttribute attribute) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetAccessor()")) return; HandleScope scope; EnsureConstructor(this); @@ -867,6 +902,7 @@ void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertyDeleter remover, NamedPropertyEnumerator enumerator, Handle data) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetNamedPropertyHandler()")) return; HandleScope scope; EnsureConstructor(this); @@ -883,6 +919,7 @@ void ObjectTemplate::SetNamedPropertyHandler(NamedPropertyGetter getter, void ObjectTemplate::MarkAsUndetectable() { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::MarkAsUndetectable()")) return; HandleScope scope; EnsureConstructor(this); @@ -898,6 +935,7 @@ void ObjectTemplate::SetAccessCheckCallbacks( IndexedSecurityCallback indexed_callback, Handle data, bool turned_on_by_default) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetAccessCheckCallbacks()")) return; HandleScope scope; EnsureConstructor(this); @@ -926,6 +964,7 @@ void ObjectTemplate::SetIndexedPropertyHandler( IndexedPropertyDeleter remover, IndexedPropertyEnumerator enumerator, Handle data) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetIndexedPropertyHandler()")) return; HandleScope scope; EnsureConstructor(this); @@ -943,6 +982,7 @@ void ObjectTemplate::SetIndexedPropertyHandler( void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, Handle data) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetCallAsFunctionHandler()")) return; HandleScope scope; EnsureConstructor(this); @@ -954,6 +994,7 @@ void ObjectTemplate::SetCallAsFunctionHandler(InvocationCallback callback, int ObjectTemplate::InternalFieldCount() { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::InternalFieldCount()")) { return 0; } @@ -962,6 +1003,7 @@ int ObjectTemplate::InternalFieldCount() { void ObjectTemplate::SetInternalFieldCount(int value) { + ENTER_V8; if (IsDeadCheck("v8::ObjectTemplate::SetInternalFieldCount()")) return; if (!ApiCheck(i::Smi::IsValid(value), "v8::ObjectTemplate::SetInternalFieldCount()", @@ -1047,6 +1089,7 @@ Local