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

Side by Side Diff: runtime/vm/exceptions.cc

Issue 342473006: Don't add the catch frame at a rethrow to the stacktrace. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/exceptions.h" 5 #include "vm/exceptions.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/debugger.h" 9 #include "vm/debugger.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 const Stacktrace& full_stacktrace = Stacktrace::Handle( 368 const Stacktrace& full_stacktrace = Stacktrace::Handle(
369 Stacktrace::New(full_code_array, full_pc_offset_array)); 369 Stacktrace::New(full_code_array, full_pc_offset_array));
370 full_stacktrace.SetCatchStacktrace(full_catch_code_array, 370 full_stacktrace.SetCatchStacktrace(full_catch_code_array,
371 full_catch_pc_offset_array); 371 full_catch_pc_offset_array);
372 return full_stacktrace.raw(); 372 return full_stacktrace.raw();
373 } 373 }
374 374
375 375
376 static void ThrowExceptionHelper(Isolate* isolate, 376 static void ThrowExceptionHelper(Isolate* isolate,
377 const Instance& incoming_exception, 377 const Instance& incoming_exception,
378 const Instance& existing_stacktrace) { 378 const Instance& existing_stacktrace,
379 const bool is_rethrow) {
379 bool use_preallocated_stacktrace = false; 380 bool use_preallocated_stacktrace = false;
380 Instance& exception = Instance::Handle(isolate, incoming_exception.raw()); 381 Instance& exception = Instance::Handle(isolate, incoming_exception.raw());
381 if (exception.IsNull()) { 382 if (exception.IsNull()) {
382 exception ^= Exceptions::Create(Exceptions::kNullThrown, 383 exception ^= Exceptions::Create(Exceptions::kNullThrown,
383 Object::empty_array()); 384 Object::empty_array());
384 } else if (exception.raw() == isolate->object_store()->out_of_memory() || 385 } else if (exception.raw() == isolate->object_store()->out_of_memory() ||
385 exception.raw() == isolate->object_store()->stack_overflow()) { 386 exception.raw() == isolate->object_store()->stack_overflow()) {
386 use_preallocated_stacktrace = true; 387 use_preallocated_stacktrace = true;
387 } 388 }
388 uword handler_pc = 0; 389 uword handler_pc = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 RegularStacktraceBuilder frame_builder(false); 431 RegularStacktraceBuilder frame_builder(false);
431 BuildStackTrace(isolate, &frame_builder); 432 BuildStackTrace(isolate, &frame_builder);
432 433
433 // Create arrays for code and pc_offset tuples of each frame. 434 // Create arrays for code and pc_offset tuples of each frame.
434 code_array = Array::MakeArray(frame_builder.code_list()); 435 code_array = Array::MakeArray(frame_builder.code_list());
435 pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list()); 436 pc_offset_array = Array::MakeArray(frame_builder.pc_offset_list());
436 } 437 }
437 if (existing_stacktrace.IsNull()) { 438 if (existing_stacktrace.IsNull()) {
438 stacktrace = Stacktrace::New(code_array, pc_offset_array); 439 stacktrace = Stacktrace::New(code_array, pc_offset_array);
439 } else { 440 } else {
441 ASSERT(is_rethrow);
440 stacktrace ^= existing_stacktrace.raw(); 442 stacktrace ^= existing_stacktrace.raw();
441 if (pc_offset_array.Length() != 0) { 443 if (pc_offset_array.Length() != 0) {
442 stacktrace.Append(code_array, pc_offset_array); 444 // Skip the first frame during a rethrow. This is the catch clause with
445 // the rethrow statement, which is not part of the original trace a
446 // rethrow is supposed to preserve.
447 stacktrace.Append(code_array, pc_offset_array, 1);
443 } 448 }
444 // Since we are re throwing and appending to the existing stack trace 449 // Since we are re throwing and appending to the existing stack trace
445 // we clear out the catch trace collected in the existing stack trace 450 // we clear out the catch trace collected in the existing stack trace
446 // as that trace will not be valid anymore. 451 // as that trace will not be valid anymore.
447 stacktrace.SetCatchStacktrace(Object::empty_array(), 452 stacktrace.SetCatchStacktrace(Object::empty_array(),
448 Object::empty_array()); 453 Object::empty_array());
449 } 454 }
450 } 455 }
451 // We expect to find a handler_pc, if the exception is unhandled 456 // We expect to find a handler_pc, if the exception is unhandled
452 // then we expect to at least have the dart entry frame on the 457 // then we expect to at least have the dart entry frame on the
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 572 }
568 // Throw TypeError or CastError instance. 573 // Throw TypeError or CastError instance.
569 Exceptions::ThrowByType(exception_type, args); 574 Exceptions::ThrowByType(exception_type, args);
570 UNREACHABLE(); 575 UNREACHABLE();
571 } 576 }
572 577
573 578
574 void Exceptions::Throw(Isolate* isolate, const Instance& exception) { 579 void Exceptions::Throw(Isolate* isolate, const Instance& exception) {
575 isolate->debugger()->SignalExceptionThrown(exception); 580 isolate->debugger()->SignalExceptionThrown(exception);
576 // Null object is a valid exception object. 581 // Null object is a valid exception object.
577 ThrowExceptionHelper(isolate, exception, Instance::Handle(isolate)); 582 ThrowExceptionHelper(isolate, exception, Instance::Handle(isolate), false);
578 } 583 }
579 584
580 585
581 void Exceptions::ReThrow(Isolate* isolate, 586 void Exceptions::ReThrow(Isolate* isolate,
582 const Instance& exception, 587 const Instance& exception,
583 const Instance& stacktrace) { 588 const Instance& stacktrace) {
584 // Null object is a valid exception object. 589 // Null object is a valid exception object.
585 ThrowExceptionHelper(isolate, exception, stacktrace); 590 ThrowExceptionHelper(isolate, exception, stacktrace, true);
586 } 591 }
587 592
588 593
589 void Exceptions::PropagateError(const Error& error) { 594 void Exceptions::PropagateError(const Error& error) {
590 Isolate* isolate = Isolate::Current(); 595 Isolate* isolate = Isolate::Current();
591 ASSERT(isolate->top_exit_frame_info() != 0); 596 ASSERT(isolate->top_exit_frame_info() != 0);
592 if (error.IsUnhandledException()) { 597 if (error.IsUnhandledException()) {
593 // If the error object represents an unhandled exception, then 598 // If the error object represents an unhandled exception, then
594 // rethrow the exception in the normal fashion. 599 // rethrow the exception in the normal fashion.
595 const UnhandledException& uhe = UnhandledException::Cast(error); 600 const UnhandledException& uhe = UnhandledException::Cast(error);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 748
744 // Throw JavascriptCompatibilityError exception. 749 // Throw JavascriptCompatibilityError exception.
745 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { 750 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) {
746 const Array& exc_args = Array::Handle(Array::New(1)); 751 const Array& exc_args = Array::Handle(Array::New(1));
747 const String& msg_str = String::Handle(String::New(msg)); 752 const String& msg_str = String::Handle(String::New(msg));
748 exc_args.SetAt(0, msg_str); 753 exc_args.SetAt(0, msg_str);
749 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); 754 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args);
750 } 755 }
751 756
752 } // namespace dart 757 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698