Commit 3726ba90 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Change exception type to Object.

R=ulan@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20571 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 48e0d812
...@@ -264,21 +264,11 @@ void Isolate::IterateThread(ThreadVisitor* v, char* t) { ...@@ -264,21 +264,11 @@ void Isolate::IterateThread(ThreadVisitor* v, char* t) {
void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) {
// Visit the roots from the top for a given thread. // Visit the roots from the top for a given thread.
Object* pending; v->VisitPointer(&thread->pending_exception_);
// The pending exception can sometimes be a failure. We can't show
// that to the GC, which only understands objects.
if (thread->pending_exception_->ToObject(&pending)) {
v->VisitPointer(&pending);
thread->pending_exception_ = pending; // In case GC updated it.
}
v->VisitPointer(&(thread->pending_message_obj_)); v->VisitPointer(&(thread->pending_message_obj_));
v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_)));
v->VisitPointer(BitCast<Object**>(&(thread->context_))); v->VisitPointer(BitCast<Object**>(&(thread->context_)));
Object* scheduled; v->VisitPointer(&thread->scheduled_exception_);
if (thread->scheduled_exception_->ToObject(&scheduled)) {
v->VisitPointer(&scheduled);
thread->scheduled_exception_ = scheduled;
}
for (v8::TryCatch* block = thread->TryCatchHandler(); for (v8::TryCatch* block = thread->TryCatchHandler();
block != NULL; block != NULL;
...@@ -912,7 +902,7 @@ Failure* Isolate::Throw(Object* exception, MessageLocation* location) { ...@@ -912,7 +902,7 @@ Failure* Isolate::Throw(Object* exception, MessageLocation* location) {
} }
Failure* Isolate::ReThrow(MaybeObject* exception) { Failure* Isolate::ReThrow(Object* exception) {
bool can_be_caught_externally = false; bool can_be_caught_externally = false;
bool catchable_by_javascript = is_catchable_by_javascript(exception); bool catchable_by_javascript = is_catchable_by_javascript(exception);
ShouldReportException(&can_be_caught_externally, catchable_by_javascript); ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
...@@ -969,7 +959,7 @@ void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) { ...@@ -969,7 +959,7 @@ void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) {
Failure* Isolate::PromoteScheduledException() { Failure* Isolate::PromoteScheduledException() {
MaybeObject* thrown = scheduled_exception(); Object* thrown = scheduled_exception();
clear_scheduled_exception(); clear_scheduled_exception();
// Re-throw the exception to avoid getting repeated error reporting. // Re-throw the exception to avoid getting repeated error reporting.
return ReThrow(thrown); return ReThrow(thrown);
...@@ -1813,9 +1803,6 @@ void Isolate::PropagatePendingExceptionToExternalTryCatch() { ...@@ -1813,9 +1803,6 @@ void Isolate::PropagatePendingExceptionToExternalTryCatch() {
try_catch_handler()->exception_ = heap()->null_value(); try_catch_handler()->exception_ = heap()->null_value();
} else { } else {
v8::TryCatch* handler = try_catch_handler(); v8::TryCatch* handler = try_catch_handler();
// At this point all non-object (failure) exceptions have
// been dealt with so this shouldn't fail.
ASSERT(!pending_exception()->IsFailure());
ASSERT(thread_local_top_.pending_message_obj_->IsJSMessageObject() || ASSERT(thread_local_top_.pending_message_obj_->IsJSMessageObject() ||
thread_local_top_.pending_message_obj_->IsTheHole()); thread_local_top_.pending_message_obj_->IsTheHole());
ASSERT(thread_local_top_.pending_message_script_->IsScript() || ASSERT(thread_local_top_.pending_message_script_->IsScript() ||
......
...@@ -292,7 +292,7 @@ class ThreadLocalTop BASE_EMBEDDED { ...@@ -292,7 +292,7 @@ class ThreadLocalTop BASE_EMBEDDED {
// lookups. // lookups.
Context* context_; Context* context_;
ThreadId thread_id_; ThreadId thread_id_;
MaybeObject* pending_exception_; Object* pending_exception_;
bool has_pending_message_; bool has_pending_message_;
bool rethrowing_message_; bool rethrowing_message_;
Object* pending_message_obj_; Object* pending_message_obj_;
...@@ -302,7 +302,7 @@ class ThreadLocalTop BASE_EMBEDDED { ...@@ -302,7 +302,7 @@ class ThreadLocalTop BASE_EMBEDDED {
// Use a separate value for scheduled exceptions to preserve the // Use a separate value for scheduled exceptions to preserve the
// invariants that hold about pending_exception. We may want to // invariants that hold about pending_exception. We may want to
// unify them later. // unify them later.
MaybeObject* scheduled_exception_; Object* scheduled_exception_;
bool external_caught_exception_; bool external_caught_exception_;
SaveContext* save_context_; SaveContext* save_context_;
v8::TryCatch* catcher_; v8::TryCatch* catcher_;
...@@ -608,24 +608,28 @@ class Isolate { ...@@ -608,24 +608,28 @@ class Isolate {
THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id) THREAD_LOCAL_TOP_ACCESSOR(ThreadId, thread_id)
// Interface to pending exception. // Interface to pending exception.
MaybeObject* pending_exception() { Object* pending_exception() {
ASSERT(has_pending_exception()); ASSERT(has_pending_exception());
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
return thread_local_top_.pending_exception_; return thread_local_top_.pending_exception_;
} }
void set_pending_exception(MaybeObject* exception) { void set_pending_exception(Object* exception) {
ASSERT(!exception->IsFailure());
thread_local_top_.pending_exception_ = exception; thread_local_top_.pending_exception_ = exception;
} }
void clear_pending_exception() { void clear_pending_exception() {
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
thread_local_top_.pending_exception_ = heap_.the_hole_value(); thread_local_top_.pending_exception_ = heap_.the_hole_value();
} }
MaybeObject** pending_exception_address() { Object** pending_exception_address() {
return &thread_local_top_.pending_exception_; return &thread_local_top_.pending_exception_;
} }
bool has_pending_exception() { bool has_pending_exception() {
ASSERT(!thread_local_top_.pending_exception_->IsFailure());
return !thread_local_top_.pending_exception_->IsTheHole(); return !thread_local_top_.pending_exception_->IsTheHole();
} }
...@@ -648,7 +652,7 @@ class Isolate { ...@@ -648,7 +652,7 @@ class Isolate {
THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher) THREAD_LOCAL_TOP_ACCESSOR(v8::TryCatch*, catcher)
MaybeObject** scheduled_exception_address() { Object** scheduled_exception_address() {
return &thread_local_top_.scheduled_exception_; return &thread_local_top_.scheduled_exception_;
} }
...@@ -665,20 +669,23 @@ class Isolate { ...@@ -665,20 +669,23 @@ class Isolate {
&thread_local_top_.pending_message_script_); &thread_local_top_.pending_message_script_);
} }
MaybeObject* scheduled_exception() { Object* scheduled_exception() {
ASSERT(has_scheduled_exception()); ASSERT(has_scheduled_exception());
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
return thread_local_top_.scheduled_exception_; return thread_local_top_.scheduled_exception_;
} }
bool has_scheduled_exception() { bool has_scheduled_exception() {
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
return thread_local_top_.scheduled_exception_ != heap_.the_hole_value(); return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
} }
void clear_scheduled_exception() { void clear_scheduled_exception() {
ASSERT(!thread_local_top_.scheduled_exception_->IsFailure());
thread_local_top_.scheduled_exception_ = heap_.the_hole_value(); thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
} }
bool IsExternallyCaught(); bool IsExternallyCaught();
bool is_catchable_by_javascript(MaybeObject* exception) { bool is_catchable_by_javascript(Object* exception) {
return exception != heap()->termination_exception(); return exception != heap()->termination_exception();
} }
...@@ -737,8 +744,7 @@ class Isolate { ...@@ -737,8 +744,7 @@ class Isolate {
// Scope currently can only be used for regular exceptions, not // Scope currently can only be used for regular exceptions, not
// failures like OOM or termination exception. // failures like OOM or termination exception.
isolate_(isolate), isolate_(isolate),
pending_exception_(isolate_->pending_exception()->ToObjectUnchecked(), pending_exception_(isolate_->pending_exception(), isolate_),
isolate_),
catcher_(isolate_->catcher()) catcher_(isolate_->catcher())
{ } { }
...@@ -819,7 +825,7 @@ class Isolate { ...@@ -819,7 +825,7 @@ class Isolate {
// Re-throw an exception. This involves no error reporting since // Re-throw an exception. This involves no error reporting since
// error reporting was handled when the exception was thrown // error reporting was handled when the exception was thrown
// originally. // originally.
Failure* ReThrow(MaybeObject* exception); Failure* ReThrow(Object* exception);
void ScheduleThrow(Object* exception); void ScheduleThrow(Object* exception);
// Re-set pending message, script and positions reported to the TryCatch // Re-set pending message, script and positions reported to the TryCatch
// back to the TLS for re-use when rethrowing. // back to the TLS for re-use when rethrowing.
......
...@@ -832,8 +832,7 @@ MaybeHandle<JSArray> LiveEdit::GatherCompileInfo(Handle<Script> script, ...@@ -832,8 +832,7 @@ MaybeHandle<JSArray> LiveEdit::GatherCompileInfo(Handle<Script> script,
// A logical 'catch' section. // A logical 'catch' section.
Handle<JSObject> rethrow_exception; Handle<JSObject> rethrow_exception;
if (isolate->has_pending_exception()) { if (isolate->has_pending_exception()) {
Handle<Object> exception(isolate->pending_exception()->ToObjectChecked(), Handle<Object> exception(isolate->pending_exception(), isolate);
isolate);
MessageLocation message_location = isolate->GetMessageLocation(); MessageLocation message_location = isolate->GetMessageLocation();
isolate->clear_pending_message(); isolate->clear_pending_message();
......
...@@ -107,7 +107,7 @@ void MessageHandler::ReportMessage(Isolate* isolate, ...@@ -107,7 +107,7 @@ void MessageHandler::ReportMessage(Isolate* isolate,
// We pass the exception object into the message handler callback though. // We pass the exception object into the message handler callback though.
Object* exception_object = isolate->heap()->undefined_value(); Object* exception_object = isolate->heap()->undefined_value();
if (isolate->has_pending_exception()) { if (isolate->has_pending_exception()) {
isolate->pending_exception()->ToObject(&exception_object); exception_object = isolate->pending_exception();
} }
Handle<Object> exception_handle(exception_object, isolate); Handle<Object> exception_handle(exception_object, isolate);
......
...@@ -10802,7 +10802,7 @@ static MaybeObject* DebugLookupResultValue(Heap* heap, ...@@ -10802,7 +10802,7 @@ static MaybeObject* DebugLookupResultValue(Heap* heap,
handle(name, isolate)); handle(name, isolate));
Handle<Object> value; Handle<Object> value;
if (maybe_value.ToHandle(&value)) return *value; if (maybe_value.ToHandle(&value)) return *value;
MaybeObject* exception = heap->isolate()->pending_exception(); Object* exception = heap->isolate()->pending_exception();
heap->isolate()->clear_pending_exception(); heap->isolate()->clear_pending_exception();
if (caught_exception != NULL) *caught_exception = true; if (caught_exception != NULL) *caught_exception = true;
return exception; return exception;
......
...@@ -220,7 +220,7 @@ TEST(UncaughtThrow) { ...@@ -220,7 +220,7 @@ TEST(UncaughtThrow) {
Handle<JSObject> global(isolate->context()->global_object()); Handle<JSObject> global(isolate->context()->global_object());
Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception);
CHECK(has_pending_exception); CHECK(has_pending_exception);
CHECK_EQ(42.0, isolate->pending_exception()->ToObjectChecked()->Number()); CHECK_EQ(42.0, isolate->pending_exception()->Number());
} }
......
...@@ -1339,10 +1339,8 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, ...@@ -1339,10 +1339,8 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
if (function == NULL) { if (function == NULL) {
// Extract exception from the parser. // Extract exception from the parser.
CHECK(isolate->has_pending_exception()); CHECK(isolate->has_pending_exception());
i::MaybeObject* maybe_object = isolate->pending_exception(); i::Handle<i::JSObject> exception_handle(
i::JSObject* exception = NULL; i::JSObject::cast(isolate->pending_exception()));
CHECK(maybe_object->To(&exception));
i::Handle<i::JSObject> exception_handle(exception);
i::Handle<i::String> message_string = i::Handle<i::String> message_string =
i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message")); i::Handle<i::String>::cast(i::GetProperty(exception_handle, "message"));
......
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