diff --git a/src/api.cc b/src/api.cc index 5ef6e59249..0207eb57a6 100644 --- a/src/api.cc +++ b/src/api.cc @@ -118,31 +118,9 @@ namespace v8 { EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) -#define API_ENTRY_CHECK(isolate, msg) \ - do { \ - if (v8::Locker::IsActive()) { \ - Utils::ApiCheck(isolate->thread_manager()->IsLockedByCurrentThread(), \ - msg, \ - "Entering the V8 API without proper locking in place"); \ - } \ - } while (false) - - // --- E x c e p t i o n B e h a v i o r --- -static void DefaultFatalErrorHandler(const char* location, - const char* message) { - i::Isolate* isolate = i::Isolate::Current(); - if (isolate->IsInitialized()) { - i::VMState state(isolate); - API_Fatal(location, message); - } else { - API_Fatal(location, message); - } -} - - void i::FatalProcessOutOfMemory(const char* location) { i::V8::FatalProcessOutOfMemory(location, false); } @@ -220,10 +198,14 @@ void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { void Utils::ReportApiFailure(const char* location, const char* message) { i::Isolate* isolate = i::Isolate::Current(); - FatalErrorCallback callback = isolate->exception_behavior() == NULL - ? DefaultFatalErrorHandler - : isolate->exception_behavior(); - callback(location, message); + FatalErrorCallback callback = isolate->exception_behavior(); + if (callback == NULL) { + i::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", + location, message); + i::OS::Abort(); + } else { + callback(location, message); + } isolate->SignalFatalError(); } @@ -611,7 +593,13 @@ HandleScope::HandleScope(Isolate* isolate) { void HandleScope::Initialize(Isolate* isolate) { i::Isolate* internal_isolate = reinterpret_cast(isolate); - API_ENTRY_CHECK(internal_isolate, "HandleScope::HandleScope"); + // We do not want to check the correct usage of the Locker class all over the + // place, so we do it only here: Without a HandleScope, an embedder can do + // almost nothing, so it is enough to check in this central place. + Utils::ApiCheck(!v8::Locker::IsActive() || + internal_isolate->thread_manager()->IsLockedByCurrentThread(), + "HandleScope::HandleScope", + "Entering the V8 API without proper locking in place"); v8::ImplementationUtilities::HandleScopeData* current = internal_isolate->handle_scope_data(); isolate_ = internal_isolate; @@ -668,22 +656,24 @@ void Context::Enter() { i::Handle env = Utils::OpenHandle(this); i::Isolate* isolate = env->GetIsolate(); ENTER_V8(isolate); - isolate->handle_scope_implementer()->EnterContext(env); - isolate->handle_scope_implementer()->SaveContext(isolate->context()); + i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); + impl->EnterContext(env); + impl->SaveContext(isolate->context()); isolate->set_context(*env); } void Context::Exit() { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - i::Handle context = i::Handle::null(); + i::Handle env = Utils::OpenHandle(this); + i::Isolate* isolate = env->GetIsolate(); ENTER_V8(isolate); i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); - if (!Utils::ApiCheck(impl->LeaveContext(context), + if (!Utils::ApiCheck(impl->LastEnteredContextWas(env), "v8::Context::Exit()", "Cannot exit non-entered context")) { return; } + impl->LeaveContext(); isolate->set_context(impl->RestoreContext()); } diff --git a/src/api.h b/src/api.h index 6091aa1abb..2a43651ff3 100644 --- a/src/api.h +++ b/src/api.h @@ -551,7 +551,8 @@ class HandleScopeImplementer { inline bool CallDepthIsZero() { return call_depth_ == 0; } inline void EnterContext(Handle context); - inline bool LeaveContext(Handle context); + inline void LeaveContext(); + inline bool LastEnteredContextWas(Handle context); // Returns the last entered context or an empty handle if no // contexts have been entered. @@ -643,12 +644,13 @@ void HandleScopeImplementer::EnterContext(Handle context) { } -bool HandleScopeImplementer::LeaveContext(Handle context) { - if (entered_contexts_.is_empty()) return false; - // TODO(dcarney): figure out what's wrong here - // if (entered_contexts_.last() != *context) return false; +void HandleScopeImplementer::LeaveContext() { entered_contexts_.RemoveLast(); - return true; +} + + +bool HandleScopeImplementer::LastEnteredContextWas(Handle context) { + return !entered_contexts_.is_empty() && entered_contexts_.last() == *context; } diff --git a/src/checks.cc b/src/checks.cc index 2b1c76cb9b..62e04ff205 100644 --- a/src/checks.cc +++ b/src/checks.cc @@ -138,17 +138,6 @@ void CheckNonEqualsHelper(const char* file, } -void API_Fatal(const char* location, const char* format, ...) { - i::OS::PrintError("\n#\n# Fatal error in %s\n# ", location); - va_list arguments; - va_start(arguments, format); - i::OS::VPrintError(format, arguments); - va_end(arguments); - i::OS::PrintError("\n#\n\n"); - i::OS::Abort(); -} - - namespace v8 { namespace internal { intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } diff --git a/src/v8checks.h b/src/v8checks.h index 9857f73d17..76e16fd24e 100644 --- a/src/v8checks.h +++ b/src/v8checks.h @@ -30,8 +30,6 @@ #include "checks.h" -void API_Fatal(const char* location, const char* format, ...); - namespace v8 { class Value; template class Handle;