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

Unified Diff: runtime/vm/exceptions.cc

Issue 355823008: Avoid instantiating even a stub stacktrace when neither the catch clause nor the (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/exceptions.cc
diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc
index 6d27fe1f33a2840424d29f33ecc9c764aa292ac4..f927af1c47f55381174a1ac46bd90eebaec0440c 100644
--- a/runtime/vm/exceptions.cc
+++ b/runtime/vm/exceptions.cc
@@ -412,45 +412,47 @@ static void ThrowExceptionHelper(Isolate* isolate,
&handler_sp,
&handler_fp,
&handler_needs_stacktrace);
- Array& code_array = Array::Handle(isolate, Object::empty_array().raw());
- Array& pc_offset_array =
- Array::Handle(isolate, Object::empty_array().raw());
- // If we have an error with a stacktrace field then collect the full stack
- // trace and store it into the field.
- if (!stacktrace_field.IsNull()) {
- if (exception.GetField(stacktrace_field) == Object::null()) {
- // This is an error object and we need to capture the full stack trace
- // here implicitly, so we set up the stack trace. The stack trace
- // field is set only once, it is not overriden.
- const Stacktrace& full_stacktrace =
- Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace());
- exception.SetField(stacktrace_field, full_stacktrace);
+ if (!stacktrace_field.IsNull() || handler_needs_stacktrace) {
+ Array& code_array = Array::Handle(isolate, Object::empty_array().raw());
+ Array& pc_offset_array =
+ Array::Handle(isolate, Object::empty_array().raw());
+ // If we have an error with a stacktrace field then collect the full stack
+ // trace and store it into the field.
+ if (!stacktrace_field.IsNull()) {
+ if (exception.GetField(stacktrace_field) == Object::null()) {
+ // This is an error object and we need to capture the full stack trace
+ // here implicitly, so we set up the stack trace. The stack trace
+ // field is set only once, it is not overriden.
+ const Stacktrace& full_stacktrace =
+ Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace());
+ exception.SetField(stacktrace_field, full_stacktrace);
+ }
}
- }
- if (handler_needs_stacktrace) {
- RegularStacktraceBuilder frame_builder(false);
- BuildStackTrace(isolate, &frame_builder);
+ if (handler_needs_stacktrace) {
+ RegularStacktraceBuilder frame_builder(false);
+ BuildStackTrace(isolate, &frame_builder);
- // Create arrays for code and pc_offset tuples of each frame.
- code_array = Array::MakeArray(frame_builder.code_list());
- pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
- }
- if (existing_stacktrace.IsNull()) {
- stacktrace = Stacktrace::New(code_array, pc_offset_array);
- } else {
- ASSERT(is_rethrow);
- stacktrace ^= existing_stacktrace.raw();
- if (pc_offset_array.Length() != 0) {
- // Skip the first frame during a rethrow. This is the catch clause with
- // the rethrow statement, which is not part of the original trace a
- // rethrow is supposed to preserve.
- stacktrace.Append(code_array, pc_offset_array, 1);
+ // Create arrays for code and pc_offset tuples of each frame.
+ code_array = Array::MakeArray(frame_builder.code_list());
+ pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
+ }
+ if (existing_stacktrace.IsNull()) {
+ stacktrace = Stacktrace::New(code_array, pc_offset_array);
+ } else {
+ ASSERT(is_rethrow);
+ stacktrace ^= existing_stacktrace.raw();
+ if (pc_offset_array.Length() != 0) {
+ // Skip the first frame during a rethrow. This is the catch clause
+ // with the rethrow statement, which is not part of the original
+ // trace a rethrow is supposed to preserve.
+ stacktrace.Append(code_array, pc_offset_array, 1);
+ }
+ // Since we are re throwing and appending to the existing stack trace
+ // we clear out the catch trace collected in the existing stack trace
+ // as that trace will not be valid anymore.
+ stacktrace.SetCatchStacktrace(Object::empty_array(),
+ Object::empty_array());
}
- // Since we are re throwing and appending to the existing stack trace
- // we clear out the catch trace collected in the existing stack trace
- // as that trace will not be valid anymore.
- stacktrace.SetCatchStacktrace(Object::empty_array(),
- Object::empty_array());
}
}
// We expect to find a handler_pc, if the exception is unhandled
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698