Chromium Code Reviews| 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 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 !(Script::cast(script)->source()->IsUndefined())) { | 1040 !(Script::cast(script)->source()->IsUndefined())) { |
| 1041 int pos = frame->LookupCode()->SourcePosition(frame->pc()); | 1041 int pos = frame->LookupCode()->SourcePosition(frame->pc()); |
| 1042 // Compute the location from the function and the reloc info. | 1042 // Compute the location from the function and the reloc info. |
| 1043 Handle<Script> casted_script(Script::cast(script)); | 1043 Handle<Script> casted_script(Script::cast(script)); |
| 1044 *target = MessageLocation(casted_script, pos, pos + 1); | 1044 *target = MessageLocation(casted_script, pos, pos + 1); |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 | 1049 |
| 1050 void Isolate::ComputeLocationFromStackTrace(MessageLocation* target, | 1050 bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, |
| 1051 Handle<Object> exception) { | 1051 Handle<Object> exception) { |
| 1052 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); | 1052 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1); |
| 1053 | 1053 |
| 1054 if (!exception->IsJSObject()) return; | 1054 if (!exception->IsJSObject()) return false; |
| 1055 Handle<Name> key = factory()->stack_trace_symbol(); | 1055 Handle<Name> key = factory()->stack_trace_symbol(); |
| 1056 Handle<Object> property = | 1056 Handle<Object> property = |
| 1057 JSObject::GetDataProperty(Handle<JSObject>::cast(exception), key); | 1057 JSObject::GetDataProperty(Handle<JSObject>::cast(exception), key); |
| 1058 if (!property->IsJSArray()) return; | 1058 if (!property->IsJSArray()) return false; |
| 1059 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property); | 1059 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property); |
| 1060 | 1060 |
| 1061 Handle<FixedArray> elements(FixedArray::cast(simple_stack_trace->elements())); | 1061 Handle<FixedArray> elements(FixedArray::cast(simple_stack_trace->elements())); |
| 1062 int elements_limit = Smi::cast(simple_stack_trace->length())->value(); | 1062 int elements_limit = Smi::cast(simple_stack_trace->length())->value(); |
| 1063 | 1063 |
| 1064 for (int i = 1; i < elements_limit; i += 4) { | 1064 for (int i = 1; i < elements_limit; i += 4) { |
| 1065 Handle<JSFunction> fun = | 1065 Handle<JSFunction> fun = |
| 1066 handle(JSFunction::cast(elements->get(i + 1)), this); | 1066 handle(JSFunction::cast(elements->get(i + 1)), this); |
| 1067 if (fun->IsFromNativeScript()) continue; | 1067 if (fun->IsFromNativeScript()) continue; |
| 1068 Handle<Code> code = handle(Code::cast(elements->get(i + 2)), this); | 1068 Handle<Code> code = handle(Code::cast(elements->get(i + 2)), this); |
| 1069 Handle<Smi> offset = handle(Smi::cast(elements->get(i + 3)), this); | 1069 Handle<Smi> offset = handle(Smi::cast(elements->get(i + 3)), this); |
| 1070 Address pc = code->address() + offset->value(); | 1070 Address pc = code->address() + offset->value(); |
| 1071 | 1071 |
| 1072 Object* script = fun->shared()->script(); | 1072 Object* script = fun->shared()->script(); |
| 1073 if (script->IsScript() && | 1073 if (script->IsScript() && |
| 1074 !(Script::cast(script)->source()->IsUndefined())) { | 1074 !(Script::cast(script)->source()->IsUndefined())) { |
| 1075 int pos = code->SourcePosition(pc); | 1075 int pos = code->SourcePosition(pc); |
| 1076 Handle<Script> casted_script(Script::cast(script)); | 1076 Handle<Script> casted_script(Script::cast(script)); |
| 1077 *target = MessageLocation(casted_script, pos, pos + 1); | 1077 *target = MessageLocation(casted_script, pos, pos + 1); |
| 1078 break; | 1078 return true; |
| 1079 } | 1079 } |
| 1080 } | 1080 } |
| 1081 return false; | |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1083 | 1084 |
| 1084 bool Isolate::ShouldReportException(bool* can_be_caught_externally, | 1085 bool Isolate::ShouldReportException(bool* can_be_caught_externally, |
| 1085 bool catchable_by_javascript) { | 1086 bool catchable_by_javascript) { |
| 1086 // Find the top-most try-catch handler. | 1087 // Find the top-most try-catch handler. |
| 1087 StackHandler* handler = | 1088 StackHandler* handler = |
| 1088 StackHandler::FromAddress(Isolate::handler(thread_local_top())); | 1089 StackHandler::FromAddress(Isolate::handler(thread_local_top())); |
| 1089 while (handler != NULL && !handler->is_catch()) { | 1090 while (handler != NULL && !handler->is_catch()) { |
| 1090 handler = handler->next(); | 1091 handler = handler->next(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1142 Handle<JSArray> stack_trace_object; | 1143 Handle<JSArray> stack_trace_object; |
| 1143 MessageLocation potential_computed_location; | 1144 MessageLocation potential_computed_location; |
| 1144 if (capture_stack_trace_for_uncaught_exceptions_) { | 1145 if (capture_stack_trace_for_uncaught_exceptions_) { |
| 1145 if (IsErrorObject(exception)) { | 1146 if (IsErrorObject(exception)) { |
| 1146 // We fetch the stack trace that corresponds to this error object. | 1147 // We fetch the stack trace that corresponds to this error object. |
| 1147 // If the lookup fails, the exception is probably not a valid Error | 1148 // If the lookup fails, the exception is probably not a valid Error |
| 1148 // object. In that case, we fall through and capture the stack trace | 1149 // object. In that case, we fall through and capture the stack trace |
| 1149 // at this throw site. | 1150 // at this throw site. |
| 1150 stack_trace_object = | 1151 stack_trace_object = |
| 1151 GetDetailedStackTrace(Handle<JSObject>::cast(exception)); | 1152 GetDetailedStackTrace(Handle<JSObject>::cast(exception)); |
| 1152 if (!location) { | |
| 1153 ComputeLocationFromStackTrace(&potential_computed_location, exception); | |
| 1154 location = &potential_computed_location; | |
| 1155 } | |
| 1156 } | 1153 } |
| 1157 if (stack_trace_object.is_null()) { | 1154 if (stack_trace_object.is_null()) { |
| 1158 // Not an error object, we capture stack and location at throw site. | 1155 // Not an error object, we capture stack and location at throw site. |
| 1159 stack_trace_object = CaptureCurrentStackTrace( | 1156 stack_trace_object = CaptureCurrentStackTrace( |
| 1160 stack_trace_for_uncaught_exceptions_frame_limit_, | 1157 stack_trace_for_uncaught_exceptions_frame_limit_, |
| 1161 stack_trace_for_uncaught_exceptions_options_); | 1158 stack_trace_for_uncaught_exceptions_options_); |
| 1162 } | 1159 } |
| 1163 } | 1160 } |
| 1164 if (!location) { | 1161 if (!location) { |
| 1165 ComputeLocation(&potential_computed_location); | 1162 if (!ComputeLocationFromStackTrace(&potential_computed_location, |
|
aandrey
2014/10/31 15:13:54
this was under the (capture_stack_trace_for_uncaug
| |
| 1163 exception)) { | |
| 1164 ComputeLocation(&potential_computed_location); | |
| 1165 } | |
| 1166 location = &potential_computed_location; | 1166 location = &potential_computed_location; |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 // If the exception argument is a custom object, turn it into a string | 1169 // If the exception argument is a custom object, turn it into a string |
| 1170 // before throwing as uncaught exception. Note that the pending | 1170 // before throwing as uncaught exception. Note that the pending |
| 1171 // exception object to be set later must not be turned into a string. | 1171 // exception object to be set later must not be turned into a string. |
| 1172 if (exception->IsJSObject() && !IsErrorObject(exception)) { | 1172 if (exception->IsJSObject() && !IsErrorObject(exception)) { |
| 1173 MaybeHandle<Object> maybe_exception = | 1173 MaybeHandle<Object> maybe_exception = |
| 1174 Execution::ToDetailString(this, exception); | 1174 Execution::ToDetailString(this, exception); |
| 1175 if (!maybe_exception.ToHandle(&exception)) { | 1175 if (!maybe_exception.ToHandle(&exception)) { |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2536 if (prev_ && prev_->Intercept(flag)) return true; | 2536 if (prev_ && prev_->Intercept(flag)) return true; |
| 2537 // Then check whether this scope intercepts. | 2537 // Then check whether this scope intercepts. |
| 2538 if ((flag & intercept_mask_)) { | 2538 if ((flag & intercept_mask_)) { |
| 2539 intercepted_flags_ |= flag; | 2539 intercepted_flags_ |= flag; |
| 2540 return true; | 2540 return true; |
| 2541 } | 2541 } |
| 2542 return false; | 2542 return false; |
| 2543 } | 2543 } |
| 2544 | 2544 |
| 2545 } } // namespace v8::internal | 2545 } } // namespace v8::internal |
| OLD | NEW |