OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 context_ = NULL; | 80 context_ = NULL; |
81 thread_id_ = ThreadId::Invalid(); | 81 thread_id_ = ThreadId::Invalid(); |
82 external_caught_exception_ = false; | 82 external_caught_exception_ = false; |
83 failed_access_check_callback_ = NULL; | 83 failed_access_check_callback_ = NULL; |
84 save_context_ = NULL; | 84 save_context_ = NULL; |
85 promise_on_stack_ = NULL; | 85 promise_on_stack_ = NULL; |
86 | 86 |
87 // These members are re-initialized later after deserialization | 87 // These members are re-initialized later after deserialization |
88 // is complete. | 88 // is complete. |
89 pending_exception_ = NULL; | 89 pending_exception_ = NULL; |
90 has_pending_message_ = false; | |
91 rethrowing_message_ = false; | 90 rethrowing_message_ = false; |
92 pending_message_obj_ = NULL; | 91 pending_message_obj_ = NULL; |
93 scheduled_exception_ = NULL; | 92 scheduled_exception_ = NULL; |
94 } | 93 } |
95 | 94 |
96 | 95 |
97 void ThreadLocalTop::Initialize() { | 96 void ThreadLocalTop::Initialize() { |
98 InitializeInternal(); | 97 InitializeInternal(); |
99 #ifdef USE_SIMULATOR | 98 #ifdef USE_SIMULATOR |
100 simulator_ = Simulator::current(isolate_); | 99 simulator_ = Simulator::current(isolate_); |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 (report_exception || can_be_caught_externally)) { | 992 (report_exception || can_be_caught_externally)) { |
994 fatal_exception_depth++; | 993 fatal_exception_depth++; |
995 PrintF(stderr, "%s\n\nFROM\n", | 994 PrintF(stderr, "%s\n\nFROM\n", |
996 MessageHandler::GetLocalizedMessage(this, message_obj).get()); | 995 MessageHandler::GetLocalizedMessage(this, message_obj).get()); |
997 PrintCurrentStackTrace(stderr); | 996 PrintCurrentStackTrace(stderr); |
998 base::OS::Abort(); | 997 base::OS::Abort(); |
999 } | 998 } |
1000 } | 999 } |
1001 } | 1000 } |
1002 | 1001 |
1003 // Save the message for reporting if the the exception remains uncaught. | |
1004 thread_local_top()->has_pending_message_ = report_exception; | |
1005 | |
1006 // Set the exception being thrown. | 1002 // Set the exception being thrown. |
1007 set_pending_exception(*exception_handle); | 1003 set_pending_exception(*exception_handle); |
1008 return heap()->exception(); | 1004 return heap()->exception(); |
1009 } | 1005 } |
1010 | 1006 |
1011 | 1007 |
1012 Object* Isolate::ReThrow(Object* exception) { | 1008 Object* Isolate::ReThrow(Object* exception) { |
1013 DCHECK(!has_pending_exception()); | 1009 DCHECK(!has_pending_exception()); |
1014 | 1010 |
1015 // Set the exception being re-thrown. | 1011 // Set the exception being re-thrown. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 if (handler->is_finally()) return true; | 1394 if (handler->is_finally()) return true; |
1399 | 1395 |
1400 handler = handler->next(); | 1396 handler = handler->next(); |
1401 } | 1397 } |
1402 | 1398 |
1403 return false; | 1399 return false; |
1404 } | 1400 } |
1405 | 1401 |
1406 | 1402 |
1407 void Isolate::ReportPendingMessages() { | 1403 void Isolate::ReportPendingMessages() { |
1408 DCHECK(has_pending_exception()); | 1404 Object* exception = pending_exception(); |
1409 bool can_clear_message = PropagatePendingExceptionToExternalTryCatch(); | |
1410 | 1405 |
1411 HandleScope scope(this); | 1406 // Try to propagate the exception to an external v8::TryCatch handler. If |
1412 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { | 1407 // propagation was unsuccessful, then we will get another chance at reporting |
| 1408 // the pending message if the exception is re-thrown. |
| 1409 bool has_been_propagated = PropagatePendingExceptionToExternalTryCatch(); |
| 1410 if (!has_been_propagated) return; |
| 1411 |
| 1412 // Clear the pending message object early to avoid endless recursion. |
| 1413 Object* message_obj = thread_local_top_.pending_message_obj_; |
| 1414 clear_pending_message(); |
| 1415 |
| 1416 bool can_be_caught_externally = false; |
| 1417 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 1418 bool should_report_exception = |
| 1419 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 1420 |
| 1421 if (!catchable_by_javascript) { |
1413 // Do nothing: if needed, the exception has been already propagated to | 1422 // Do nothing: if needed, the exception has been already propagated to |
1414 // v8::TryCatch. | 1423 // v8::TryCatch. |
1415 } else { | 1424 } else { |
1416 if (thread_local_top_.has_pending_message_) { | 1425 if (!message_obj->IsTheHole() && should_report_exception) { |
1417 thread_local_top_.has_pending_message_ = false; | 1426 HandleScope scope(this); |
1418 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { | 1427 Handle<JSMessageObject> message(JSMessageObject::cast(message_obj)); |
1419 HandleScope scope(this); | 1428 Handle<JSValue> script_wrapper(JSValue::cast(message->script())); |
1420 Handle<JSMessageObject> message_obj( | 1429 Handle<Script> script(Script::cast(script_wrapper->value())); |
1421 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); | 1430 int start_pos = message->start_position(); |
1422 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); | 1431 int end_pos = message->end_position(); |
1423 Handle<Script> script(Script::cast(script_wrapper->value())); | 1432 MessageLocation location(script, start_pos, end_pos); |
1424 int start_pos = message_obj->start_position(); | 1433 MessageHandler::ReportMessage(this, &location, message); |
1425 int end_pos = message_obj->end_position(); | |
1426 MessageLocation location(script, start_pos, end_pos); | |
1427 MessageHandler::ReportMessage(this, &location, message_obj); | |
1428 } | |
1429 } | 1434 } |
1430 } | 1435 } |
1431 if (can_clear_message) clear_pending_message(); | |
1432 } | 1436 } |
1433 | 1437 |
1434 | 1438 |
1435 MessageLocation Isolate::GetMessageLocation() { | 1439 MessageLocation Isolate::GetMessageLocation() { |
1436 DCHECK(has_pending_exception()); | 1440 DCHECK(has_pending_exception()); |
1437 | 1441 |
1438 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && | 1442 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && |
1439 thread_local_top_.has_pending_message_ && | |
1440 !thread_local_top_.pending_message_obj_->IsTheHole()) { | 1443 !thread_local_top_.pending_message_obj_->IsTheHole()) { |
1441 Handle<JSMessageObject> message_obj( | 1444 Handle<JSMessageObject> message_obj( |
1442 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); | 1445 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); |
1443 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); | 1446 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); |
1444 Handle<Script> script(Script::cast(script_wrapper->value())); | 1447 Handle<Script> script(Script::cast(script_wrapper->value())); |
1445 int start_pos = message_obj->start_position(); | 1448 int start_pos = message_obj->start_position(); |
1446 int end_pos = message_obj->end_position(); | 1449 int end_pos = message_obj->end_position(); |
1447 return MessageLocation(script, start_pos, end_pos); | 1450 return MessageLocation(script, start_pos, end_pos); |
1448 } | 1451 } |
1449 | 1452 |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2617 if (prev_ && prev_->Intercept(flag)) return true; | 2620 if (prev_ && prev_->Intercept(flag)) return true; |
2618 // Then check whether this scope intercepts. | 2621 // Then check whether this scope intercepts. |
2619 if ((flag & intercept_mask_)) { | 2622 if ((flag & intercept_mask_)) { |
2620 intercepted_flags_ |= flag; | 2623 intercepted_flags_ |= flag; |
2621 return true; | 2624 return true; |
2622 } | 2625 } |
2623 return false; | 2626 return false; |
2624 } | 2627 } |
2625 | 2628 |
2626 } } // namespace v8::internal | 2629 } } // namespace v8::internal |
OLD | NEW |