Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: src/api.cc

Issue 17694002: Restore message when rethrowing in TryCatch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2069 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 } 2080 }
2081 } 2081 }
2082 2082
2083 2083
2084 // --- E x c e p t i o n s --- 2084 // --- E x c e p t i o n s ---
2085 2085
2086 2086
2087 v8::TryCatch::TryCatch() 2087 v8::TryCatch::TryCatch()
2088 : isolate_(i::Isolate::Current()), 2088 : isolate_(i::Isolate::Current()),
2089 next_(isolate_->try_catch_handler_address()), 2089 next_(isolate_->try_catch_handler_address()),
2090 exception_(isolate_->heap()->the_hole_value()),
2091 message_(i::Smi::FromInt(0)),
2092 is_verbose_(false), 2090 is_verbose_(false),
2093 can_continue_(true), 2091 can_continue_(true),
2094 capture_message_(true), 2092 capture_message_(true),
2095 rethrow_(false), 2093 rethrow_(false),
2096 has_terminated_(false) { 2094 has_terminated_(false) {
2095 Reset();
2097 isolate_->RegisterTryCatchHandler(this); 2096 isolate_->RegisterTryCatchHandler(this);
2098 } 2097 }
2099 2098
2100 2099
2101 v8::TryCatch::~TryCatch() { 2100 v8::TryCatch::~TryCatch() {
2102 ASSERT(isolate_ == i::Isolate::Current()); 2101 ASSERT(isolate_ == i::Isolate::Current());
2103 if (rethrow_) { 2102 if (rethrow_) {
2104 v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate_)); 2103 v8::HandleScope scope(reinterpret_cast<Isolate*>(isolate_));
2105 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception()); 2104 v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(Exception());
2105 if (HasCaught() && capture_message_) {
2106 // If an exception was caught and rethrow_ is indicated, the saved
2107 // message, script, and location need to be restored to Isolate TLS
2108 // for reuse. capture_message_ needs to be disabled so that DoThrow()
2109 // does not create a new message.
2110 isolate_->thread_local_top()->rethrowing_message_ = true;
2111 isolate_->RestorePendingMessageFromTryCatch(this);
2112 }
2106 isolate_->UnregisterTryCatchHandler(this); 2113 isolate_->UnregisterTryCatchHandler(this);
2107 v8::ThrowException(exc); 2114 v8::ThrowException(exc);
2115 ASSERT(!isolate_->thread_local_top()->rethrowing_message_);
2108 } else { 2116 } else {
2109 isolate_->UnregisterTryCatchHandler(this); 2117 isolate_->UnregisterTryCatchHandler(this);
2110 } 2118 }
2111 } 2119 }
2112 2120
2113 2121
2114 bool v8::TryCatch::HasCaught() const { 2122 bool v8::TryCatch::HasCaught() const {
2115 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(); 2123 return !reinterpret_cast<i::Object*>(exception_)->IsTheHole();
2116 } 2124 }
2117 2125
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 if (value.is_null()) return v8::Local<Value>(); 2166 if (value.is_null()) return v8::Local<Value>();
2159 return v8::Utils::ToLocal(scope.CloseAndEscape(value)); 2167 return v8::Utils::ToLocal(scope.CloseAndEscape(value));
2160 } else { 2168 } else {
2161 return v8::Local<Value>(); 2169 return v8::Local<Value>();
2162 } 2170 }
2163 } 2171 }
2164 2172
2165 2173
2166 v8::Local<v8::Message> v8::TryCatch::Message() const { 2174 v8::Local<v8::Message> v8::TryCatch::Message() const {
2167 ASSERT(isolate_ == i::Isolate::Current()); 2175 ASSERT(isolate_ == i::Isolate::Current());
2168 if (HasCaught() && message_ != i::Smi::FromInt(0)) { 2176 i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
2169 i::Object* message = reinterpret_cast<i::Object*>(message_); 2177 ASSERT(message->IsJSMessageObject() || message->IsTheHole());
2178 if (HasCaught() && !message->IsTheHole()) {
2170 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); 2179 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
2171 } else { 2180 } else {
2172 return v8::Local<v8::Message>(); 2181 return v8::Local<v8::Message>();
2173 } 2182 }
2174 } 2183 }
2175 2184
2176 2185
2177 void v8::TryCatch::Reset() { 2186 void v8::TryCatch::Reset() {
2178 ASSERT(isolate_ == i::Isolate::Current()); 2187 ASSERT(isolate_ == i::Isolate::Current());
2179 exception_ = isolate_->heap()->the_hole_value(); 2188 i::Object* the_hole = isolate_->heap()->the_hole_value();
2180 message_ = i::Smi::FromInt(0); 2189 exception_ = the_hole;
2190 message_obj_ = the_hole;
2191 message_script_ = the_hole;
2192 message_start_pos_ = 0;
2193 message_end_pos_ = 0;
2181 } 2194 }
2182 2195
2183 2196
2184 void v8::TryCatch::SetVerbose(bool value) { 2197 void v8::TryCatch::SetVerbose(bool value) {
2185 is_verbose_ = value; 2198 is_verbose_ = value;
2186 } 2199 }
2187 2200
2188 2201
2189 void v8::TryCatch::SetCaptureMessage(bool value) { 2202 void v8::TryCatch::SetCaptureMessage(bool value) {
2190 capture_message_ = value; 2203 capture_message_ = value;
(...skipping 5800 matching lines...) Expand 10 before | Expand all | Expand 10 after
7991 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8004 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7992 Address callback_address = 8005 Address callback_address =
7993 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8006 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7994 VMState<EXTERNAL> state(isolate); 8007 VMState<EXTERNAL> state(isolate);
7995 ExternalCallbackScope call_scope(isolate, callback_address); 8008 ExternalCallbackScope call_scope(isolate, callback_address);
7996 return callback(info); 8009 return callback(info);
7997 } 8010 }
7998 8011
7999 8012
8000 } } // namespace v8::internal 8013 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698