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

Side by Side Diff: src/isolate.cc

Issue 15669003: Fix TryCatch.ReThrow() to not clobber Message. (Closed) Base URL: http://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 | « src/isolate.h ('k') | test/cctest/test-api.cc » ('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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 external_caught_exception_ = false; 100 external_caught_exception_ = false;
101 failed_access_check_callback_ = NULL; 101 failed_access_check_callback_ = NULL;
102 save_context_ = NULL; 102 save_context_ = NULL;
103 catcher_ = NULL; 103 catcher_ = NULL;
104 top_lookup_result_ = NULL; 104 top_lookup_result_ = NULL;
105 105
106 // These members are re-initialized later after deserialization 106 // These members are re-initialized later after deserialization
107 // is complete. 107 // is complete.
108 pending_exception_ = NULL; 108 pending_exception_ = NULL;
109 has_pending_message_ = false; 109 has_pending_message_ = false;
110 restoring_message_ = false;
110 pending_message_obj_ = NULL; 111 pending_message_obj_ = NULL;
111 pending_message_script_ = NULL; 112 pending_message_script_ = NULL;
112 scheduled_exception_ = NULL; 113 scheduled_exception_ = NULL;
113 } 114 }
114 115
115 116
116 void ThreadLocalTop::Initialize() { 117 void ThreadLocalTop::Initialize() {
117 InitializeInternal(); 118 InitializeInternal();
118 #ifdef USE_SIMULATOR 119 #ifdef USE_SIMULATOR
119 #ifdef V8_TARGET_ARCH_ARM 120 #ifdef V8_TARGET_ARCH_ARM
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 Object* scheduled; 474 Object* scheduled;
474 if (thread->scheduled_exception_->ToObject(&scheduled)) { 475 if (thread->scheduled_exception_->ToObject(&scheduled)) {
475 v->VisitPointer(&scheduled); 476 v->VisitPointer(&scheduled);
476 thread->scheduled_exception_ = scheduled; 477 thread->scheduled_exception_ = scheduled;
477 } 478 }
478 479
479 for (v8::TryCatch* block = thread->TryCatchHandler(); 480 for (v8::TryCatch* block = thread->TryCatchHandler();
480 block != NULL; 481 block != NULL;
481 block = TRY_CATCH_FROM_ADDRESS(block->next_)) { 482 block = TRY_CATCH_FROM_ADDRESS(block->next_)) {
482 v->VisitPointer(BitCast<Object**>(&(block->exception_))); 483 v->VisitPointer(BitCast<Object**>(&(block->exception_)));
483 v->VisitPointer(BitCast<Object**>(&(block->message_))); 484 v->VisitPointer(BitCast<Object**>(&(block->message_obj_)));
485 v->VisitPointer(BitCast<Object**>(&(block->message_script_)));
484 } 486 }
485 487
486 // Iterate over pointers on native execution stack. 488 // Iterate over pointers on native execution stack.
487 for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) { 489 for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) {
488 it.frame()->Iterate(v); 490 it.frame()->Iterate(v);
489 } 491 }
490 492
491 // Iterate pointers in live lookup results. 493 // Iterate pointers in live lookup results.
492 thread->top_lookup_result_->Iterate(v); 494 thread->top_lookup_result_->Iterate(v);
493 } 495 }
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 Throw(exception); 1151 Throw(exception);
1150 PropagatePendingExceptionToExternalTryCatch(); 1152 PropagatePendingExceptionToExternalTryCatch();
1151 if (has_pending_exception()) { 1153 if (has_pending_exception()) {
1152 thread_local_top()->scheduled_exception_ = pending_exception(); 1154 thread_local_top()->scheduled_exception_ = pending_exception();
1153 thread_local_top()->external_caught_exception_ = false; 1155 thread_local_top()->external_caught_exception_ = false;
1154 clear_pending_exception(); 1156 clear_pending_exception();
1155 } 1157 }
1156 } 1158 }
1157 1159
1158 1160
1161 void Isolate::RestoreMessage(Object* message, Script* script,
1162 int start_pos, int end_pos) {
1163 // Flag is checked in DoThrow(), which immediately follows.
1164 thread_local_top()->restoring_message_ = true;
1165 thread_local_top()->pending_message_obj_ = message;
1166 if (script) {
1167 thread_local_top()->pending_message_script_ = script;
1168 }
1169 thread_local_top()->pending_message_start_pos_ = start_pos;
1170 thread_local_top()->pending_message_end_pos_ = end_pos;
1171 }
1172
1173
1159 Failure* Isolate::PromoteScheduledException() { 1174 Failure* Isolate::PromoteScheduledException() {
1160 MaybeObject* thrown = scheduled_exception(); 1175 MaybeObject* thrown = scheduled_exception();
1161 clear_scheduled_exception(); 1176 clear_scheduled_exception();
1162 // Re-throw the exception to avoid getting repeated error reporting. 1177 // Re-throw the exception to avoid getting repeated error reporting.
1163 return ReThrow(thrown); 1178 return ReThrow(thrown);
1164 } 1179 }
1165 1180
1166 1181
1167 void Isolate::PrintCurrentStackTrace(FILE* out) { 1182 void Isolate::PrintCurrentStackTrace(FILE* out) {
1168 StackTraceFrameIterator it(this); 1183 StackTraceFrameIterator it(this);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 1281
1267 HandleScope scope(this); 1282 HandleScope scope(this);
1268 Handle<Object> exception_handle(exception, this); 1283 Handle<Object> exception_handle(exception, this);
1269 1284
1270 // Determine reporting and whether the exception is caught externally. 1285 // Determine reporting and whether the exception is caught externally.
1271 bool catchable_by_javascript = is_catchable_by_javascript(exception); 1286 bool catchable_by_javascript = is_catchable_by_javascript(exception);
1272 bool can_be_caught_externally = false; 1287 bool can_be_caught_externally = false;
1273 bool should_report_exception = 1288 bool should_report_exception =
1274 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); 1289 ShouldReportException(&can_be_caught_externally, catchable_by_javascript);
1275 bool report_exception = catchable_by_javascript && should_report_exception; 1290 bool report_exception = catchable_by_javascript && should_report_exception;
1291 // When determining if a message needs to be generated, make sure to check
1292 // restoring_message_. If an external TryCatch re-threw an exception, it
1293 // will have already called RestoreMessage() to put the original message,
1294 // script, and location back in place. In that case, this code must not
1295 // clobber the values computed from the original exception.
1276 bool try_catch_needs_message = 1296 bool try_catch_needs_message =
1277 can_be_caught_externally && try_catch_handler()->capture_message_; 1297 can_be_caught_externally && try_catch_handler()->capture_message_ &&
1298 !thread_local_top_.restoring_message_;
1278 bool bootstrapping = bootstrapper()->IsActive(); 1299 bool bootstrapping = bootstrapper()->IsActive();
1279 1300
1301 thread_local_top_.restoring_message_ = false;
1302
1280 #ifdef ENABLE_DEBUGGER_SUPPORT 1303 #ifdef ENABLE_DEBUGGER_SUPPORT
1281 // Notify debugger of exception. 1304 // Notify debugger of exception.
1282 if (catchable_by_javascript) { 1305 if (catchable_by_javascript) {
1283 debugger_->OnException(exception_handle, report_exception); 1306 debugger_->OnException(exception_handle, report_exception);
1284 } 1307 }
1285 #endif 1308 #endif
1286 1309
1287 // Generate the message if required. 1310 // Generate the message if required.
1288 if (report_exception || try_catch_needs_message) { 1311 if (report_exception || try_catch_needs_message) {
1289 MessageLocation potential_computed_location; 1312 MessageLocation potential_computed_location;
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 try_catch_handler()->has_terminated_ = true; 2057 try_catch_handler()->has_terminated_ = true;
2035 try_catch_handler()->exception_ = heap()->null_value(); 2058 try_catch_handler()->exception_ = heap()->null_value();
2036 } else { 2059 } else {
2037 // At this point all non-object (failure) exceptions have 2060 // At this point all non-object (failure) exceptions have
2038 // been dealt with so this shouldn't fail. 2061 // been dealt with so this shouldn't fail.
2039 ASSERT(!pending_exception()->IsFailure()); 2062 ASSERT(!pending_exception()->IsFailure());
2040 try_catch_handler()->can_continue_ = true; 2063 try_catch_handler()->can_continue_ = true;
2041 try_catch_handler()->has_terminated_ = false; 2064 try_catch_handler()->has_terminated_ = false;
2042 try_catch_handler()->exception_ = pending_exception(); 2065 try_catch_handler()->exception_ = pending_exception();
2043 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { 2066 if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
2044 try_catch_handler()->message_ = thread_local_top_.pending_message_obj_; 2067 try_catch_handler()->message_obj_ =
2068 thread_local_top_.pending_message_obj_;
2069 if (!thread_local_top_.pending_message_script_->IsTheHole()) {
2070 try_catch_handler()->message_script_ =
2071 thread_local_top_.pending_message_script_;
2072 }
2073 try_catch_handler()->message_start_pos_ =
2074 thread_local_top_.pending_message_start_pos_;
2075 try_catch_handler()->message_end_pos_ =
2076 thread_local_top_.pending_message_end_pos_;
2045 } 2077 }
2046 } 2078 }
2047 } 2079 }
2048 2080
2049 2081
2050 void Isolate::InitializeLoggingAndCounters() { 2082 void Isolate::InitializeLoggingAndCounters() {
2051 if (logger_ == NULL) { 2083 if (logger_ == NULL) {
2052 logger_ = new Logger(this); 2084 logger_ = new Logger(this);
2053 } 2085 }
2054 if (counters_ == NULL) { 2086 if (counters_ == NULL) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 2523
2492 #ifdef DEBUG 2524 #ifdef DEBUG
2493 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ 2525 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \
2494 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); 2526 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
2495 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) 2527 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
2496 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) 2528 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
2497 #undef ISOLATE_FIELD_OFFSET 2529 #undef ISOLATE_FIELD_OFFSET
2498 #endif 2530 #endif
2499 2531
2500 } } // namespace v8::internal 2532 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698