OLD | NEW |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 external_callback_ = NULL; | 63 external_callback_ = NULL; |
64 #endif | 64 #endif |
65 #ifdef ENABLE_VMSTATE_TRACKING | 65 #ifdef ENABLE_VMSTATE_TRACKING |
66 current_vm_state_ = EXTERNAL; | 66 current_vm_state_ = EXTERNAL; |
67 #endif | 67 #endif |
68 try_catch_handler_address_ = NULL; | 68 try_catch_handler_address_ = NULL; |
69 context_ = NULL; | 69 context_ = NULL; |
70 int id = Isolate::Current()->thread_manager()->CurrentId(); | 70 int id = Isolate::Current()->thread_manager()->CurrentId(); |
71 thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id; | 71 thread_id_ = (id == 0) ? ThreadManager::kInvalidId : id; |
72 external_caught_exception_ = false; | 72 external_caught_exception_ = false; |
| 73 in_exception_reporting_ = false; |
73 failed_access_check_callback_ = NULL; | 74 failed_access_check_callback_ = NULL; |
74 save_context_ = NULL; | 75 save_context_ = NULL; |
75 catcher_ = NULL; | 76 catcher_ = NULL; |
76 } | 77 } |
77 | 78 |
78 | 79 |
79 Address Isolate::get_address_from_id(Isolate::AddressId id) { | 80 Address Isolate::get_address_from_id(Isolate::AddressId id) { |
80 return isolate_addresses_[id]; | 81 return isolate_addresses_[id]; |
81 } | 82 } |
82 | 83 |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 | 790 |
790 handler = handler->next(); | 791 handler = handler->next(); |
791 } | 792 } |
792 | 793 |
793 return true; | 794 return true; |
794 } | 795 } |
795 | 796 |
796 | 797 |
797 void Isolate::ReportPendingMessages() { | 798 void Isolate::ReportPendingMessages() { |
798 ASSERT(has_pending_exception()); | 799 ASSERT(has_pending_exception()); |
| 800 PropagatePendingExceptionToExternalTryCatch(); |
| 801 |
799 // If the pending exception is OutOfMemoryException set out_of_memory in | 802 // If the pending exception is OutOfMemoryException set out_of_memory in |
800 // the global context. Note: We have to mark the global context here | 803 // the global context. Note: We have to mark the global context here |
801 // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to | 804 // since the GenerateThrowOutOfMemory stub cannot make a RuntimeCall to |
802 // set it. | 805 // set it. |
803 bool external_caught = IsExternallyCaught(); | 806 HandleScope scope; |
804 thread_local_top()->external_caught_exception_ = external_caught; | 807 if (thread_local_top_.pending_exception_ == Failure::OutOfMemoryException()) { |
805 HandleScope scope(this); | |
806 if (thread_local_top()->pending_exception_ == | |
807 Failure::OutOfMemoryException()) { | |
808 context()->mark_out_of_memory(); | 808 context()->mark_out_of_memory(); |
809 } else if (thread_local_top()->pending_exception_ == | 809 } else if (thread_local_top_.pending_exception_ == |
810 heap_.termination_exception()) { | 810 heap()->termination_exception()) { |
811 if (external_caught) { | 811 // Do nothing: if needed, the exception has been already propagated to |
812 try_catch_handler()->can_continue_ = false; | 812 // v8::TryCatch. |
813 try_catch_handler()->exception_ = heap_.null_value(); | |
814 } | |
815 } else { | 813 } else { |
816 // At this point all non-object (failure) exceptions have | 814 if (thread_local_top_.has_pending_message_) { |
817 // been dealt with so this shouldn't fail. | 815 thread_local_top_.has_pending_message_ = false; |
818 Object* pending_exception_object = pending_exception()->ToObjectUnchecked(); | 816 if (thread_local_top_.pending_message_ != NULL) { |
819 Handle<Object> exception(pending_exception_object); | 817 MessageHandler::ReportMessage(thread_local_top_.pending_message_); |
820 thread_local_top()->external_caught_exception_ = false; | 818 } else if (!thread_local_top_.pending_message_obj_->IsTheHole()) { |
821 if (external_caught) { | 819 HandleScope scope; |
822 try_catch_handler()->can_continue_ = true; | 820 Handle<Object> message_obj(thread_local_top_.pending_message_obj_); |
823 try_catch_handler()->exception_ = thread_local_top()->pending_exception_; | 821 if (thread_local_top_.pending_message_script_ != NULL) { |
824 if (!thread_local_top()->pending_message_obj_->IsTheHole()) { | 822 Handle<Script> script(thread_local_top_.pending_message_script_); |
825 try_catch_handler()->message_ = | 823 int start_pos = thread_local_top_.pending_message_start_pos_; |
826 thread_local_top()->pending_message_obj_; | 824 int end_pos = thread_local_top_.pending_message_end_pos_; |
827 } | |
828 } | |
829 if (thread_local_top()->has_pending_message_) { | |
830 thread_local_top()->has_pending_message_ = false; | |
831 if (thread_local_top()->pending_message_ != NULL) { | |
832 MessageHandler::ReportMessage(thread_local_top()->pending_message_); | |
833 } else if (!thread_local_top()->pending_message_obj_->IsTheHole()) { | |
834 Handle<Object> message_obj(thread_local_top()->pending_message_obj_); | |
835 if (thread_local_top()->pending_message_script_ != NULL) { | |
836 Handle<Script> script(thread_local_top()->pending_message_script_); | |
837 int start_pos = thread_local_top()->pending_message_start_pos_; | |
838 int end_pos = thread_local_top()->pending_message_end_pos_; | |
839 MessageLocation location(script, start_pos, end_pos); | 825 MessageLocation location(script, start_pos, end_pos); |
840 MessageHandler::ReportMessage(&location, message_obj); | 826 MessageHandler::ReportMessage(this, &location, message_obj); |
841 } else { | 827 } else { |
842 MessageHandler::ReportMessage(NULL, message_obj); | 828 MessageHandler::ReportMessage(this, NULL, message_obj); |
843 } | 829 } |
844 } | 830 } |
845 } | 831 } |
846 thread_local_top()->external_caught_exception_ = external_caught; | |
847 set_pending_exception(*exception); | |
848 } | 832 } |
849 clear_pending_message(); | 833 clear_pending_message(); |
850 } | 834 } |
851 | 835 |
852 | 836 |
853 void Isolate::TraceException(bool flag) { | 837 void Isolate::TraceException(bool flag) { |
854 FLAG_trace_exception = flag; // TODO(isolates): This is an unfortunate use. | 838 FLAG_trace_exception = flag; // TODO(isolates): This is an unfortunate use. |
855 } | 839 } |
856 | 840 |
857 | 841 |
858 bool Isolate::OptionalRescheduleException(bool is_bottom_call) { | 842 bool Isolate::OptionalRescheduleException(bool is_bottom_call) { |
| 843 ASSERT(has_pending_exception()); |
| 844 PropagatePendingExceptionToExternalTryCatch(); |
| 845 |
859 // Allways reschedule out of memory exceptions. | 846 // Allways reschedule out of memory exceptions. |
860 if (!is_out_of_memory()) { | 847 if (!is_out_of_memory()) { |
861 bool is_termination_exception = | 848 bool is_termination_exception = |
862 pending_exception() == heap_.termination_exception(); | 849 pending_exception() == heap_.termination_exception(); |
863 | 850 |
864 // Do not reschedule the exception if this is the bottom call. | 851 // Do not reschedule the exception if this is the bottom call. |
865 bool clear_exception = is_bottom_call; | 852 bool clear_exception = is_bottom_call; |
866 | 853 |
867 if (is_termination_exception) { | 854 if (is_termination_exception) { |
868 if (is_bottom_call) { | 855 if (is_bottom_call) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 sizeof(ThreadLocalTop)); | 948 sizeof(ThreadLocalTop)); |
962 InitializeThreadLocal(); | 949 InitializeThreadLocal(); |
963 return to + sizeof(ThreadLocalTop); | 950 return to + sizeof(ThreadLocalTop); |
964 } | 951 } |
965 | 952 |
966 | 953 |
967 char* Isolate::RestoreThread(char* from) { | 954 char* Isolate::RestoreThread(char* from) { |
968 memcpy(reinterpret_cast<char*>(thread_local_top()), from, | 955 memcpy(reinterpret_cast<char*>(thread_local_top()), from, |
969 sizeof(ThreadLocalTop)); | 956 sizeof(ThreadLocalTop)); |
970 // This might be just paranoia, but it seems to be needed in case a | 957 // This might be just paranoia, but it seems to be needed in case a |
971 // thread_local_ is restored on a separate OS thread. | 958 // thread_local_top_ is restored on a separate OS thread. |
972 #ifdef USE_SIMULATOR | 959 #ifdef USE_SIMULATOR |
973 #ifdef V8_TARGET_ARCH_ARM | 960 #ifdef V8_TARGET_ARCH_ARM |
974 thread_local_top()->simulator_ = Simulator::current(this); | 961 thread_local_top()->simulator_ = Simulator::current(this); |
975 #elif V8_TARGET_ARCH_MIPS | 962 #elif V8_TARGET_ARCH_MIPS |
976 thread_local_top()->simulator_ = Simulator::current(this); | 963 thread_local_top()->simulator_ = Simulator::current(this); |
977 #endif | 964 #endif |
978 #endif | 965 #endif |
979 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { | 966 if (RuntimeProfiler::IsEnabled() && current_vm_state() == JS) { |
980 RuntimeProfiler::IsolateEnteredJS(this); | 967 RuntimeProfiler::IsolateEnteredJS(this); |
981 } | 968 } |
982 return from + sizeof(ThreadLocalTop); | 969 return from + sizeof(ThreadLocalTop); |
983 } | 970 } |
984 | 971 |
985 } } // namespace v8::internal | 972 } } // namespace v8::internal |
OLD | NEW |