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
This commit is contained in:
parent
ffc12aa7f0
commit
111e604e72
54
src/api.cc
54
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<i::OTHER> 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<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 =
|
||||
internal_isolate->handle_scope_data();
|
||||
isolate_ = internal_isolate;
|
||||
@ -668,22 +656,24 @@ void Context::Enter() {
|
||||
i::Handle<i::Context> 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<i::Context> context = i::Handle<i::Context>::null();
|
||||
i::Handle<i::Context> 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());
|
||||
}
|
||||
|
||||
|
14
src/api.h
14
src/api.h
@ -551,7 +551,8 @@ class HandleScopeImplementer {
|
||||
inline bool CallDepthIsZero() { return call_depth_ == 0; }
|
||||
|
||||
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
|
||||
// contexts have been entered.
|
||||
@ -643,12 +644,13 @@ void HandleScopeImplementer::EnterContext(Handle<Context> context) {
|
||||
}
|
||||
|
||||
|
||||
bool HandleScopeImplementer::LeaveContext(Handle<Context> 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> context) {
|
||||
return !entered_contexts_.is_empty() && entered_contexts_.last() == *context;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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; }
|
||||
|
@ -30,8 +30,6 @@
|
||||
|
||||
#include "checks.h"
|
||||
|
||||
void API_Fatal(const char* location, const char* format, ...);
|
||||
|
||||
namespace v8 {
|
||||
class Value;
|
||||
template <class T> class Handle;
|
||||
|
Loading…
Reference in New Issue
Block a user