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

Side by Side Diff: src/top.cc

Issue 8050: Changed the message reporting for try { ... } finally { ... } statements to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 2 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/top.h ('k') | test/message/bugs/try-finally-linenum.js » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Handle<Object> exception = Copy(boilerplate); 587 Handle<Object> exception = Copy(boilerplate);
588 // TODO(1240995): To avoid having to call JavaScript code to compute 588 // TODO(1240995): To avoid having to call JavaScript code to compute
589 // the message for stack overflow exceptions which is very likely to 589 // the message for stack overflow exceptions which is very likely to
590 // double fault with another stack overflow exception, we use a 590 // double fault with another stack overflow exception, we use a
591 // precomputed message. This is somewhat problematic in that it 591 // precomputed message. This is somewhat problematic in that it
592 // doesn't use ReportUncaughtException to determine the location 592 // doesn't use ReportUncaughtException to determine the location
593 // from where the exception occurred. It should probably be 593 // from where the exception occurred. It should probably be
594 // reworked. 594 // reworked.
595 static const char* kMessage = 595 static const char* kMessage =
596 "Uncaught RangeError: Maximum call stack size exceeded"; 596 "Uncaught RangeError: Maximum call stack size exceeded";
597 DoThrow(*exception, NULL, kMessage, false); 597 DoThrow(*exception, NULL, kMessage);
598 return Failure::Exception(); 598 return Failure::Exception();
599 } 599 }
600 600
601 601
602 Failure* Top::Throw(Object* exception, MessageLocation* location) { 602 Failure* Top::Throw(Object* exception, MessageLocation* location) {
603 DoThrow(exception, location, NULL, false); 603 DoThrow(exception, location, NULL);
604 return Failure::Exception(); 604 return Failure::Exception();
605 } 605 }
606 606
607 607
608 Failure* Top::ReThrow(Object* exception, MessageLocation* location) { 608 Failure* Top::ReThrow(Object* exception, MessageLocation* location) {
609 DoThrow(exception, location, NULL, true); 609 // Check is this exception is externally caught.
610 bool is_caught_externally = false;
611 ShouldReportException(&is_caught_externally);
612 thread_local_.external_caught_exception_ = is_caught_externally;
613
614 // Set the exception beeing re-thrown.
615 set_pending_exception(exception);
610 return Failure::Exception(); 616 return Failure::Exception();
611 } 617 }
612 618
613 619
614 void Top::ScheduleThrow(Object* exception) { 620 void Top::ScheduleThrow(Object* exception) {
615 // When scheduling a throw we first throw the exception to get the 621 // When scheduling a throw we first throw the exception to get the
616 // error reporting if it is uncaught before rescheduling it. 622 // error reporting if it is uncaught before rescheduling it.
617 Throw(exception); 623 Throw(exception);
618 thread_local_.scheduled_exception_ = pending_exception(); 624 thread_local_.scheduled_exception_ = pending_exception();
619 thread_local_.external_caught_exception_ = false; 625 thread_local_.external_caught_exception_ = false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // address of the external handler so we can compare the address to 723 // address of the external handler so we can compare the address to
718 // determine which one is closer to the top of the stack. 724 // determine which one is closer to the top of the stack.
719 bool has_external_handler = (thread_local_.try_catch_handler_ != NULL); 725 bool has_external_handler = (thread_local_.try_catch_handler_ != NULL);
720 Address external_handler_address = 726 Address external_handler_address =
721 reinterpret_cast<Address>(thread_local_.try_catch_handler_); 727 reinterpret_cast<Address>(thread_local_.try_catch_handler_);
722 728
723 // NOTE: The stack is assumed to grown towards lower addresses. If 729 // NOTE: The stack is assumed to grown towards lower addresses. If
724 // the handler is at a higher address than the external address it 730 // the handler is at a higher address than the external address it
725 // means that it is below it on the stack. 731 // means that it is below it on the stack.
726 732
727 // Find the top-most try-catch or try-finally handler.
728 while (handler != NULL && handler->is_entry()) {
729 handler = handler->next();
730 }
731
732 // The exception has been externally caught if and only if there is
733 // an external handler which is above any JavaScript try-catch or
734 // try-finally handlers.
735 *is_caught_externally = has_external_handler &&
736 (handler == NULL || handler->address() > external_handler_address);
737
738 // Find the top-most try-catch handler. 733 // Find the top-most try-catch handler.
739 while (handler != NULL && !handler->is_try_catch()) { 734 while (handler != NULL && !handler->is_try_catch()) {
740 handler = handler->next(); 735 handler = handler->next();
741 } 736 }
742 737
738 // The exception has been externally caught if and only if there is
739 // an external handler which is above any JavaScript try-catch but NOT
740 // try-finally handlers.
741 *is_caught_externally = has_external_handler &&
742 (handler == NULL || handler->address() > external_handler_address);
743
743 // If we have a try-catch handler then the exception is caught in 744 // If we have a try-catch handler then the exception is caught in
744 // JavaScript code. 745 // JavaScript code.
745 bool is_uncaught_by_js = (handler == NULL); 746 bool is_uncaught_by_js = (handler == NULL);
746 747
747 // If there is no external try-catch handler, we report the 748 // If there is no external try-catch handler, we report the
748 // exception if it isn't caught by JavaScript code. 749 // exception if it isn't caught by JavaScript code.
749 if (!has_external_handler) return is_uncaught_by_js; 750 if (!has_external_handler) return is_uncaught_by_js;
750 751
751 if (is_uncaught_by_js || handler->address() > external_handler_address) { 752 if (is_uncaught_by_js || handler->address() > external_handler_address) {
752 // Only report the exception if the external handler is verbose. 753 // Only report the exception if the external handler is verbose.
753 return thread_local_.try_catch_handler_->is_verbose_; 754 return thread_local_.try_catch_handler_->is_verbose_;
754 } else { 755 } else {
755 // Report the exception if it isn't caught by JavaScript code. 756 // Report the exception if it isn't caught by JavaScript code.
756 return is_uncaught_by_js; 757 return is_uncaught_by_js;
757 } 758 }
758 } 759 }
759 760
760 761
761 void Top::DoThrow(Object* exception, 762 void Top::DoThrow(Object* exception,
762 MessageLocation* location, 763 MessageLocation* location,
763 const char* message, 764 const char* message) {
764 bool is_rethrow) {
765 ASSERT(!has_pending_exception()); 765 ASSERT(!has_pending_exception());
766 ASSERT(!external_caught_exception());
767 766
768 HandleScope scope; 767 HandleScope scope;
769 Handle<Object> exception_handle(exception); 768 Handle<Object> exception_handle(exception);
770 769
770 // Determine reporting and whether the exception is caught externally.
771 bool is_caught_externally = false; 771 bool is_caught_externally = false;
772 bool report_exception = (exception != Failure::OutOfMemoryException()) && 772 bool report_exception = (exception != Failure::OutOfMemoryException()) &&
773 ShouldReportException(&is_caught_externally); 773 ShouldReportException(&is_caught_externally);
774 if (is_rethrow) report_exception = false;
775 774
775 // Generate the message.
776 Handle<Object> message_obj; 776 Handle<Object> message_obj;
777 MessageLocation potential_computed_location; 777 MessageLocation potential_computed_location;
778 bool try_catch_needs_message = 778 bool try_catch_needs_message =
779 is_caught_externally && thread_local_.try_catch_handler_->capture_message_; 779 is_caught_externally &&
780 thread_local_.try_catch_handler_->capture_message_;
780 if (report_exception || try_catch_needs_message) { 781 if (report_exception || try_catch_needs_message) {
781 if (location == NULL) { 782 if (location == NULL) {
782 // If no location was specified we use a computed one instead 783 // If no location was specified we use a computed one instead
783 ComputeLocation(&potential_computed_location); 784 ComputeLocation(&potential_computed_location);
784 location = &potential_computed_location; 785 location = &potential_computed_location;
785 } 786 }
786 Handle<String> stack_trace; 787 Handle<String> stack_trace;
787 if (FLAG_trace_exception) stack_trace = StackTrace(); 788 if (FLAG_trace_exception) stack_trace = StackTrace();
788 message_obj = MessageHandler::MakeMessageObject("uncaught_exception", 789 message_obj = MessageHandler::MakeMessageObject("uncaught_exception",
789 location, HandleVector<Object>(&exception_handle, 1), stack_trace); 790 location, HandleVector<Object>(&exception_handle, 1), stack_trace);
(...skipping 15 matching lines...) Expand all
805 Debugger::OnException(exception_handle, report_exception); 806 Debugger::OnException(exception_handle, report_exception);
806 807
807 if (report_exception) { 808 if (report_exception) {
808 if (message != NULL) { 809 if (message != NULL) {
809 MessageHandler::ReportMessage(message); 810 MessageHandler::ReportMessage(message);
810 } else { 811 } else {
811 MessageHandler::ReportMessage(location, message_obj); 812 MessageHandler::ReportMessage(location, message_obj);
812 } 813 }
813 } 814 }
814 thread_local_.external_caught_exception_ = is_caught_externally; 815 thread_local_.external_caught_exception_ = is_caught_externally;
816
815 // NOTE: Notifying the debugger or reporting the exception may have caused 817 // NOTE: Notifying the debugger or reporting the exception may have caused
816 // new exceptions. For now, we just ignore that and set the pending exception 818 // new exceptions. For now, we just ignore that and set the pending exception
817 // to the original one. 819 // to the original one.
818 set_pending_exception(*exception_handle); 820 set_pending_exception(*exception_handle);
819 } 821 }
820 822
821 823
822 void Top::TraceException(bool flag) { 824 void Top::TraceException(bool flag) {
823 FLAG_trace_exception = flag; 825 FLAG_trace_exception = flag;
824 } 826 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 Top::break_access_->Lock(); 896 Top::break_access_->Lock();
895 } 897 }
896 898
897 899
898 ExecutionAccess::~ExecutionAccess() { 900 ExecutionAccess::~ExecutionAccess() {
899 Top::break_access_->Unlock(); 901 Top::break_access_->Unlock();
900 } 902 }
901 903
902 904
903 } } // namespace v8::internal 905 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/top.h ('k') | test/message/bugs/try-finally-linenum.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698