Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 014d82ee4f0aab86c5f16ca339c22b335c42753b..ca6e1722d75ccfe00155d306591ff8342adb6774 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -2087,13 +2087,12 @@ void Script::SetData(v8::Handle<String> data) { |
v8::TryCatch::TryCatch() |
: isolate_(i::Isolate::Current()), |
next_(isolate_->try_catch_handler_address()), |
- exception_(isolate_->heap()->the_hole_value()), |
- message_(i::Smi::FromInt(0)), |
is_verbose_(false), |
can_continue_(true), |
capture_message_(true), |
rethrow_(false), |
has_terminated_(false) { |
+ Reset(); |
isolate_->RegisterTryCatchHandler(this); |
} |
@@ -2103,8 +2102,17 @@ v8::TryCatch::~TryCatch() { |
if (rethrow_) { |
v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate_)); |
v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); |
+ if (HasCaught() && capture_message_) { |
+ // If an exception was caught and rethrow_ is indicated, the saved |
+ // message, script, and location need to be restored to Isolate TLS |
+ // for reuse. capture_message_ needs to be disabled so that DoThrow() |
+ // does not create a new message. |
+ isolate_->thread_local_top()->rethrowing_message_ = true; |
+ isolate_->RestorePendingMessageFromTryCatch(this); |
+ } |
isolate_->UnregisterTryCatchHandler(this); |
v8::ThrowException(exc); |
+ ASSERT(!isolate_->thread_local_top()->rethrowing_message_); |
} else { |
isolate_->UnregisterTryCatchHandler(this); |
} |
@@ -2165,8 +2173,9 @@ v8::Local<Value> v8::TryCatch::StackTrace() const { |
v8::Local<v8::Message> v8::TryCatch::Message() const { |
ASSERT(isolate_ == i::Isolate::Current()); |
- if (HasCaught() && message_ != i::Smi::FromInt(0)) { |
- i::Object* message = reinterpret_cast<i::Object*>(message_); |
+ i::Object* message = reinterpret_cast<i::Object*>(message_obj_); |
+ ASSERT(message->IsJSMessageObject() || message->IsTheHole()); |
+ if (HasCaught() && !message->IsTheHole()) { |
return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
} else { |
return v8::Local<v8::Message>(); |
@@ -2176,8 +2185,12 @@ v8::Local<v8::Message> v8::TryCatch::Message() const { |
void v8::TryCatch::Reset() { |
ASSERT(isolate_ == i::Isolate::Current()); |
- exception_ = isolate_->heap()->the_hole_value(); |
- message_ = i::Smi::FromInt(0); |
+ i::Object* the_hole = isolate_->heap()->the_hole_value(); |
+ exception_ = the_hole; |
+ message_obj_ = the_hole; |
+ message_script_ = the_hole; |
+ message_start_pos_ = 0; |
+ message_end_pos_ = 0; |
} |