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 "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "ast.h" | 9 #include "ast.h" |
10 #include "bootstrapper.h" | 10 #include "bootstrapper.h" |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 // Only report the exception if the external handler is verbose. | 982 // Only report the exception if the external handler is verbose. |
983 return try_catch_handler()->is_verbose_; | 983 return try_catch_handler()->is_verbose_; |
984 } else { | 984 } else { |
985 // Report the exception if it isn't caught by JavaScript code. | 985 // Report the exception if it isn't caught by JavaScript code. |
986 return handler == NULL; | 986 return handler == NULL; |
987 } | 987 } |
988 } | 988 } |
989 | 989 |
990 | 990 |
991 bool Isolate::IsErrorObject(Handle<Object> obj) { | 991 bool Isolate::IsErrorObject(Handle<Object> obj) { |
992 return IsTypeObject(obj, | |
993 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error"))); | |
994 } | |
995 | |
996 | |
997 bool Isolate::IsSyntaxErrorObject(Handle<Object> obj) { | |
998 return IsTypeObject(obj, | |
999 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$SyntaxError"))); | |
1000 } | |
1001 | |
1002 | |
1003 bool Isolate::IsTypeObject(Handle<Object> obj, Handle<String> key) { | |
vsevik
2014/06/06 16:12:01
IsObjectOfType
vsevik
2014/06/06 16:12:01
key -> js_builtin_key
| |
992 if (!obj->IsJSObject()) return false; | 1004 if (!obj->IsJSObject()) return false; |
993 | 1005 |
994 Handle<String> error_key = | 1006 Handle<Object> constructor = Object::GetProperty( |
995 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("$Error")); | 1007 js_builtins_object(), key).ToHandleChecked(); |
996 Handle<Object> error_constructor = Object::GetProperty( | |
997 js_builtins_object(), error_key).ToHandleChecked(); | |
998 | 1008 |
999 DisallowHeapAllocation no_gc; | 1009 DisallowHeapAllocation no_gc; |
1000 for (Object* prototype = *obj; !prototype->IsNull(); | 1010 for (Object* prototype = *obj; !prototype->IsNull(); |
1001 prototype = prototype->GetPrototype(this)) { | 1011 prototype = prototype->GetPrototype(this)) { |
1002 if (!prototype->IsJSObject()) return false; | 1012 if (!prototype->IsJSObject()) return false; |
1003 if (JSObject::cast(prototype)->map()->constructor() == | 1013 if (JSObject::cast(prototype)->map()->constructor() == |
1004 *error_constructor) { | 1014 *constructor) { |
1005 return true; | 1015 return true; |
1006 } | 1016 } |
1007 } | 1017 } |
1008 return false; | 1018 return false; |
1009 } | 1019 } |
1010 | 1020 |
1011 static int fatal_exception_depth = 0; | 1021 static int fatal_exception_depth = 0; |
1012 | 1022 |
1013 void Isolate::DoThrow(Object* exception, MessageLocation* location) { | 1023 void Isolate::DoThrow(Object* exception, MessageLocation* location) { |
1014 ASSERT(!has_pending_exception()); | 1024 ASSERT(!has_pending_exception()); |
1015 | 1025 |
1016 HandleScope scope(this); | 1026 HandleScope scope(this); |
1017 Handle<Object> exception_handle(exception, this); | 1027 Handle<Object> exception_handle(exception, this); |
1018 | 1028 |
1019 // Determine reporting and whether the exception is caught externally. | 1029 // Determine reporting and whether the exception is caught externally. |
1020 bool catchable_by_javascript = is_catchable_by_javascript(exception); | 1030 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
1021 bool can_be_caught_externally = false; | 1031 bool can_be_caught_externally = false; |
1022 bool should_report_exception = | 1032 bool should_report_exception = |
1023 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); | 1033 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
1024 bool report_exception = catchable_by_javascript && should_report_exception; | 1034 bool report_exception = catchable_by_javascript && should_report_exception; |
1025 bool try_catch_needs_message = | 1035 bool try_catch_needs_message = |
1026 can_be_caught_externally && try_catch_handler()->capture_message_ && | 1036 can_be_caught_externally && try_catch_handler()->capture_message_ && |
1027 !thread_local_top()->rethrowing_message_; | 1037 !thread_local_top()->rethrowing_message_; |
1028 bool bootstrapping = bootstrapper()->IsActive(); | 1038 bool bootstrapping = bootstrapper()->IsActive(); |
1029 | 1039 |
1030 thread_local_top()->rethrowing_message_ = false; | 1040 thread_local_top()->rethrowing_message_ = false; |
1031 | 1041 |
1042 // notify debugger of SyntaxError | |
1043 if (location != NULL && IsSyntaxErrorObject(exception_handle)) { | |
1044 debugger_->OnSyntaxError(location->script()); | |
1045 } | |
1046 | |
1032 // Notify debugger of exception. | 1047 // Notify debugger of exception. |
1033 if (catchable_by_javascript) { | 1048 if (catchable_by_javascript) { |
1034 debugger_->OnException( | 1049 debugger_->OnException( |
1035 exception_handle, report_exception, factory()->undefined_value()); | 1050 exception_handle, report_exception, factory()->undefined_value()); |
1036 } | 1051 } |
1037 | 1052 |
1038 // Generate the message if required. | 1053 // Generate the message if required. |
1039 if (report_exception || try_catch_needs_message) { | 1054 if (report_exception || try_catch_needs_message) { |
1040 MessageLocation potential_computed_location; | 1055 MessageLocation potential_computed_location; |
1041 if (location == NULL) { | 1056 if (location == NULL) { |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2247 handle_scope_implementer()->IncrementCallDepth(); | 2262 handle_scope_implementer()->IncrementCallDepth(); |
2248 if (run_microtasks) Execution::RunMicrotasks(this); | 2263 if (run_microtasks) Execution::RunMicrotasks(this); |
2249 for (int i = 0; i < call_completed_callbacks_.length(); i++) { | 2264 for (int i = 0; i < call_completed_callbacks_.length(); i++) { |
2250 call_completed_callbacks_.at(i)(); | 2265 call_completed_callbacks_.at(i)(); |
2251 } | 2266 } |
2252 handle_scope_implementer()->DecrementCallDepth(); | 2267 handle_scope_implementer()->DecrementCallDepth(); |
2253 } | 2268 } |
2254 | 2269 |
2255 | 2270 |
2256 } } // namespace v8::internal | 2271 } } // namespace v8::internal |
OLD | NEW |