Various API-related simplifications.

   * Simplified default fatal error handler.

   * Simplified Context::Exit and friends.

   * Inline API_ENTRY_CHECK.

R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/137963002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18577 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ffc12aa7
...@@ -118,31 +118,9 @@ namespace v8 { ...@@ -118,31 +118,9 @@ namespace v8 {
EXCEPTION_BAILOUT_CHECK_GENERIC(isolate, value, ;) 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 --- // --- 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<i::OTHER> state(isolate);
API_Fatal(location, message);
} else {
API_Fatal(location, message);
}
}
void i::FatalProcessOutOfMemory(const char* location) { void i::FatalProcessOutOfMemory(const char* location) {
i::V8::FatalProcessOutOfMemory(location, false); i::V8::FatalProcessOutOfMemory(location, false);
} }
...@@ -220,10 +198,14 @@ void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) { ...@@ -220,10 +198,14 @@ void i::V8::FatalProcessOutOfMemory(const char* location, bool take_snapshot) {
void Utils::ReportApiFailure(const char* location, const char* message) { void Utils::ReportApiFailure(const char* location, const char* message) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
FatalErrorCallback callback = isolate->exception_behavior() == NULL FatalErrorCallback callback = isolate->exception_behavior();
? DefaultFatalErrorHandler if (callback == NULL) {
: isolate->exception_behavior(); i::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n",
location, message);
i::OS::Abort();
} else {
callback(location, message); callback(location, message);
}
isolate->SignalFatalError(); isolate->SignalFatalError();
} }
...@@ -611,7 +593,13 @@ HandleScope::HandleScope(Isolate* isolate) { ...@@ -611,7 +593,13 @@ HandleScope::HandleScope(Isolate* isolate) {
void HandleScope::Initialize(Isolate* isolate) { void HandleScope::Initialize(Isolate* isolate) {
i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(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 = v8::ImplementationUtilities::HandleScopeData* current =
internal_isolate->handle_scope_data(); internal_isolate->handle_scope_data();
isolate_ = internal_isolate; isolate_ = internal_isolate;
...@@ -668,22 +656,24 @@ void Context::Enter() { ...@@ -668,22 +656,24 @@ void Context::Enter() {
i::Handle<i::Context> env = Utils::OpenHandle(this); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Isolate* isolate = env->GetIsolate(); i::Isolate* isolate = env->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
isolate->handle_scope_implementer()->EnterContext(env); i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
isolate->handle_scope_implementer()->SaveContext(isolate->context()); impl->EnterContext(env);
impl->SaveContext(isolate->context());
isolate->set_context(*env); isolate->set_context(*env);
} }
void Context::Exit() { void Context::Exit() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Handle<i::Context> env = Utils::OpenHandle(this);
i::Handle<i::Context> context = i::Handle<i::Context>::null(); i::Isolate* isolate = env->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
if (!Utils::ApiCheck(impl->LeaveContext(context), if (!Utils::ApiCheck(impl->LastEnteredContextWas(env),
"v8::Context::Exit()", "v8::Context::Exit()",
"Cannot exit non-entered context")) { "Cannot exit non-entered context")) {
return; return;
} }
impl->LeaveContext();
isolate->set_context(impl->RestoreContext()); isolate->set_context(impl->RestoreContext());
} }
......
...@@ -551,7 +551,8 @@ class HandleScopeImplementer { ...@@ -551,7 +551,8 @@ class HandleScopeImplementer {
inline bool CallDepthIsZero() { return call_depth_ == 0; } inline bool CallDepthIsZero() { return call_depth_ == 0; }
inline void EnterContext(Handle<Context> context); inline void EnterContext(Handle<Context> context);
inline bool LeaveContext(Handle<Context> context); inline void LeaveContext();
inline bool LastEnteredContextWas(Handle<Context> context);
// Returns the last entered context or an empty handle if no // Returns the last entered context or an empty handle if no
// contexts have been entered. // contexts have been entered.
...@@ -643,12 +644,13 @@ void HandleScopeImplementer::EnterContext(Handle<Context> context) { ...@@ -643,12 +644,13 @@ void HandleScopeImplementer::EnterContext(Handle<Context> context) {
} }
bool HandleScopeImplementer::LeaveContext(Handle<Context> context) { void HandleScopeImplementer::LeaveContext() {
if (entered_contexts_.is_empty()) return false;
// TODO(dcarney): figure out what's wrong here
// if (entered_contexts_.last() != *context) return false;
entered_contexts_.RemoveLast(); entered_contexts_.RemoveLast();
return true; }
bool HandleScopeImplementer::LastEnteredContextWas(Handle<Context> context) {
return !entered_contexts_.is_empty() && entered_contexts_.last() == *context;
} }
......
...@@ -138,17 +138,6 @@ void CheckNonEqualsHelper(const char* file, ...@@ -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 { namespace v8 { namespace internal {
intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
......
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include "checks.h" #include "checks.h"
void API_Fatal(const char* location, const char* format, ...);
namespace v8 { namespace v8 {
class Value; class Value;
template <class T> class Handle; template <class T> class Handle;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment