| OLD | NEW |
| 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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 VMState<EXTERNAL> state(this); | 800 VMState<EXTERNAL> state(this); |
| 801 return callback( | 801 return callback( |
| 802 v8::Utils::ToLocal(receiver), index, type, v8::Utils::ToLocal(data)); | 802 v8::Utils::ToLocal(receiver), index, type, v8::Utils::ToLocal(data)); |
| 803 } | 803 } |
| 804 | 804 |
| 805 | 805 |
| 806 const char* const Isolate::kStackOverflowMessage = | 806 const char* const Isolate::kStackOverflowMessage = |
| 807 "Uncaught RangeError: Maximum call stack size exceeded"; | 807 "Uncaught RangeError: Maximum call stack size exceeded"; |
| 808 | 808 |
| 809 | 809 |
| 810 Failure* Isolate::StackOverflow() { | 810 Object* Isolate::StackOverflow() { |
| 811 HandleScope scope(this); | 811 HandleScope scope(this); |
| 812 // At this point we cannot create an Error object using its javascript | 812 // At this point we cannot create an Error object using its javascript |
| 813 // constructor. Instead, we copy the pre-constructed boilerplate and | 813 // constructor. Instead, we copy the pre-constructed boilerplate and |
| 814 // attach the stack trace as a hidden property. | 814 // attach the stack trace as a hidden property. |
| 815 Handle<String> key = factory()->stack_overflow_string(); | 815 Handle<String> key = factory()->stack_overflow_string(); |
| 816 Handle<JSObject> boilerplate = Handle<JSObject>::cast( | 816 Handle<JSObject> boilerplate = Handle<JSObject>::cast( |
| 817 Object::GetProperty(js_builtins_object(), key).ToHandleChecked()); | 817 Object::GetProperty(js_builtins_object(), key).ToHandleChecked()); |
| 818 Handle<JSObject> exception = JSObject::Copy(boilerplate); | 818 Handle<JSObject> exception = JSObject::Copy(boilerplate); |
| 819 DoThrow(*exception, NULL); | 819 DoThrow(*exception, NULL); |
| 820 | 820 |
| 821 // Get stack trace limit. | 821 // Get stack trace limit. |
| 822 Handle<Object> error = Object::GetProperty( | 822 Handle<Object> error = Object::GetProperty( |
| 823 this, js_builtins_object(), "$Error").ToHandleChecked(); | 823 this, js_builtins_object(), "$Error").ToHandleChecked(); |
| 824 if (!error->IsJSObject()) return Failure::Exception(); | 824 if (!error->IsJSObject()) return heap()->exception(); |
| 825 | 825 |
| 826 Handle<String> stackTraceLimit = | 826 Handle<String> stackTraceLimit = |
| 827 factory()->InternalizeUtf8String("stackTraceLimit"); | 827 factory()->InternalizeUtf8String("stackTraceLimit"); |
| 828 ASSERT(!stackTraceLimit.is_null()); | 828 ASSERT(!stackTraceLimit.is_null()); |
| 829 Handle<Object> stack_trace_limit = | 829 Handle<Object> stack_trace_limit = |
| 830 JSObject::GetDataProperty(Handle<JSObject>::cast(error), | 830 JSObject::GetDataProperty(Handle<JSObject>::cast(error), |
| 831 stackTraceLimit); | 831 stackTraceLimit); |
| 832 if (!stack_trace_limit->IsNumber()) return Failure::Exception(); | 832 if (!stack_trace_limit->IsNumber()) return heap()->exception(); |
| 833 double dlimit = stack_trace_limit->Number(); | 833 double dlimit = stack_trace_limit->Number(); |
| 834 int limit = std::isnan(dlimit) ? 0 : static_cast<int>(dlimit); | 834 int limit = std::isnan(dlimit) ? 0 : static_cast<int>(dlimit); |
| 835 | 835 |
| 836 Handle<JSArray> stack_trace = CaptureSimpleStackTrace( | 836 Handle<JSArray> stack_trace = CaptureSimpleStackTrace( |
| 837 exception, factory()->undefined_value(), limit); | 837 exception, factory()->undefined_value(), limit); |
| 838 JSObject::SetHiddenProperty(exception, | 838 JSObject::SetHiddenProperty(exception, |
| 839 factory()->hidden_stack_trace_string(), | 839 factory()->hidden_stack_trace_string(), |
| 840 stack_trace); | 840 stack_trace); |
| 841 return Failure::Exception(); | 841 return heap()->exception(); |
| 842 } | 842 } |
| 843 | 843 |
| 844 | 844 |
| 845 Failure* Isolate::TerminateExecution() { | 845 Object* Isolate::TerminateExecution() { |
| 846 DoThrow(heap_.termination_exception(), NULL); | 846 DoThrow(heap_.termination_exception(), NULL); |
| 847 return Failure::Exception(); | 847 return heap()->exception(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 | 850 |
| 851 void Isolate::CancelTerminateExecution() { | 851 void Isolate::CancelTerminateExecution() { |
| 852 if (try_catch_handler()) { | 852 if (try_catch_handler()) { |
| 853 try_catch_handler()->has_terminated_ = false; | 853 try_catch_handler()->has_terminated_ = false; |
| 854 } | 854 } |
| 855 if (has_pending_exception() && | 855 if (has_pending_exception() && |
| 856 pending_exception() == heap_.termination_exception()) { | 856 pending_exception() == heap_.termination_exception()) { |
| 857 thread_local_top()->external_caught_exception_ = false; | 857 thread_local_top()->external_caught_exception_ = false; |
| 858 clear_pending_exception(); | 858 clear_pending_exception(); |
| 859 } | 859 } |
| 860 if (has_scheduled_exception() && | 860 if (has_scheduled_exception() && |
| 861 scheduled_exception() == heap_.termination_exception()) { | 861 scheduled_exception() == heap_.termination_exception()) { |
| 862 thread_local_top()->external_caught_exception_ = false; | 862 thread_local_top()->external_caught_exception_ = false; |
| 863 clear_scheduled_exception(); | 863 clear_scheduled_exception(); |
| 864 } | 864 } |
| 865 } | 865 } |
| 866 | 866 |
| 867 | 867 |
| 868 Failure* Isolate::Throw(Object* exception, MessageLocation* location) { | 868 Object* Isolate::Throw(Object* exception, MessageLocation* location) { |
| 869 DoThrow(exception, location); | 869 DoThrow(exception, location); |
| 870 return Failure::Exception(); | 870 return heap()->exception(); |
| 871 } | 871 } |
| 872 | 872 |
| 873 | 873 |
| 874 Failure* Isolate::ReThrow(Object* exception) { | 874 Object* Isolate::ReThrow(Object* exception) { |
| 875 bool can_be_caught_externally = false; | 875 bool can_be_caught_externally = false; |
| 876 bool catchable_by_javascript = is_catchable_by_javascript(exception); | 876 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 877 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); | 877 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 878 | 878 |
| 879 thread_local_top()->catcher_ = can_be_caught_externally ? | 879 thread_local_top()->catcher_ = can_be_caught_externally ? |
| 880 try_catch_handler() : NULL; | 880 try_catch_handler() : NULL; |
| 881 | 881 |
| 882 // Set the exception being re-thrown. | 882 // Set the exception being re-thrown. |
| 883 set_pending_exception(exception); | 883 set_pending_exception(exception); |
| 884 return Failure::Exception(); | 884 return heap()->exception(); |
| 885 } | 885 } |
| 886 | 886 |
| 887 | 887 |
| 888 Failure* Isolate::ThrowIllegalOperation() { | 888 Object* Isolate::ThrowIllegalOperation() { |
| 889 if (FLAG_stack_trace_on_illegal) PrintStack(stdout); | 889 if (FLAG_stack_trace_on_illegal) PrintStack(stdout); |
| 890 return Throw(heap_.illegal_access_string()); | 890 return Throw(heap_.illegal_access_string()); |
| 891 } | 891 } |
| 892 | 892 |
| 893 | 893 |
| 894 Failure* Isolate::ThrowInvalidStringLength() { | 894 Object* Isolate::ThrowInvalidStringLength() { |
| 895 return Throw(*factory()->NewRangeError( | 895 return Throw(*factory()->NewRangeError( |
| 896 "invalid_string_length", HandleVector<Object>(NULL, 0))); | 896 "invalid_string_length", HandleVector<Object>(NULL, 0))); |
| 897 } | 897 } |
| 898 | 898 |
| 899 | 899 |
| 900 void Isolate::ScheduleThrow(Object* exception) { | 900 void Isolate::ScheduleThrow(Object* exception) { |
| 901 // When scheduling a throw we first throw the exception to get the | 901 // When scheduling a throw we first throw the exception to get the |
| 902 // error reporting if it is uncaught before rescheduling it. | 902 // error reporting if it is uncaught before rescheduling it. |
| 903 Throw(exception); | 903 Throw(exception); |
| 904 PropagatePendingExceptionToExternalTryCatch(); | 904 PropagatePendingExceptionToExternalTryCatch(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 919 Object* script = reinterpret_cast<Object*>(handler->message_script_); | 919 Object* script = reinterpret_cast<Object*>(handler->message_script_); |
| 920 ASSERT(message->IsJSMessageObject() || message->IsTheHole()); | 920 ASSERT(message->IsJSMessageObject() || message->IsTheHole()); |
| 921 ASSERT(script->IsScript() || script->IsTheHole()); | 921 ASSERT(script->IsScript() || script->IsTheHole()); |
| 922 thread_local_top()->pending_message_obj_ = message; | 922 thread_local_top()->pending_message_obj_ = message; |
| 923 thread_local_top()->pending_message_script_ = script; | 923 thread_local_top()->pending_message_script_ = script; |
| 924 thread_local_top()->pending_message_start_pos_ = handler->message_start_pos_; | 924 thread_local_top()->pending_message_start_pos_ = handler->message_start_pos_; |
| 925 thread_local_top()->pending_message_end_pos_ = handler->message_end_pos_; | 925 thread_local_top()->pending_message_end_pos_ = handler->message_end_pos_; |
| 926 } | 926 } |
| 927 | 927 |
| 928 | 928 |
| 929 Failure* Isolate::PromoteScheduledException() { | 929 Object* Isolate::PromoteScheduledException() { |
| 930 Object* thrown = scheduled_exception(); | 930 Object* thrown = scheduled_exception(); |
| 931 clear_scheduled_exception(); | 931 clear_scheduled_exception(); |
| 932 // Re-throw the exception to avoid getting repeated error reporting. | 932 // Re-throw the exception to avoid getting repeated error reporting. |
| 933 return ReThrow(thrown); | 933 return ReThrow(thrown); |
| 934 } | 934 } |
| 935 | 935 |
| 936 | 936 |
| 937 void Isolate::PrintCurrentStackTrace(FILE* out) { | 937 void Isolate::PrintCurrentStackTrace(FILE* out) { |
| 938 StackTraceFrameIterator it(this); | 938 StackTraceFrameIterator it(this); |
| 939 while (!it.done()) { | 939 while (!it.done()) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 return true; | 1209 return true; |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 | 1212 |
| 1213 void Isolate::ReportPendingMessages() { | 1213 void Isolate::ReportPendingMessages() { |
| 1214 ASSERT(has_pending_exception()); | 1214 ASSERT(has_pending_exception()); |
| 1215 PropagatePendingExceptionToExternalTryCatch(); | 1215 PropagatePendingExceptionToExternalTryCatch(); |
| 1216 | 1216 |
| 1217 HandleScope scope(this); | 1217 HandleScope scope(this); |
| 1218 if (thread_local_top_.pending_exception_ == | 1218 if (thread_local_top_.pending_exception_ == |
| 1219 heap()->termination_exception()) { | 1219 heap()->termination_exception()) { |
| 1220 // Do nothing: if needed, the exception has been already propagated to | 1220 // Do nothing: if needed, the exception has been already propagated to |
| 1221 // v8::TryCatch. | 1221 // v8::TryCatch. |
| 1222 } else { | 1222 } else { |
| 1223 if (thread_local_top_.has_pending_message_) { | 1223 if (thread_local_top_.has_pending_message_) { |
| 1224 thread_local_top_.has_pending_message_ = false; | 1224 thread_local_top_.has_pending_message_ = false; |
| 1225 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { | 1225 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { |
| 1226 HandleScope scope(this); | 1226 HandleScope scope(this); |
| 1227 Handle<Object> message_obj(thread_local_top_.pending_message_obj_, | 1227 Handle<Object> message_obj(thread_local_top_.pending_message_obj_, |
| 1228 this); | 1228 this); |
| 1229 if (!thread_local_top_.pending_message_script_->IsTheHole()) { | 1229 if (!thread_local_top_.pending_message_script_->IsTheHole()) { |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 Handle<JSObject> obj = factory()->NewJSObjectFromMap(map); | 2250 Handle<JSObject> obj = factory()->NewJSObjectFromMap(map); |
| 2251 JSObject::NormalizeProperties(obj, KEEP_INOBJECT_PROPERTIES, 8); | 2251 JSObject::NormalizeProperties(obj, KEEP_INOBJECT_PROPERTIES, 8); |
| 2252 JSObject::SetProperty(registry, name, obj, NONE, STRICT).Assert(); | 2252 JSObject::SetProperty(registry, name, obj, NONE, STRICT).Assert(); |
| 2253 } | 2253 } |
| 2254 } | 2254 } |
| 2255 return Handle<JSObject>::cast(factory()->symbol_registry()); | 2255 return Handle<JSObject>::cast(factory()->symbol_registry()); |
| 2256 } | 2256 } |
| 2257 | 2257 |
| 2258 | 2258 |
| 2259 } } // namespace v8::internal | 2259 } } // namespace v8::internal |
| OLD | NEW |