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

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

Issue 21832003: Fix VM implementation of CastError not to extend TypeError (issue 5280). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | « runtime/vm/code_generator.cc ('k') | runtime/vm/flow_graph_compiler_arm.cc » ('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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 const String& cls_name = String::Handle(Symbols::New(class_name)); 489 const String& cls_name = String::Handle(Symbols::New(class_name));
490 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 490 const Library& core_lib = Library::Handle(Library::CoreLibrary());
491 // No ambiguity error expected: passing NULL. 491 // No ambiguity error expected: passing NULL.
492 Class& cls = Class::Handle(core_lib.LookupClass(cls_name, NULL)); 492 Class& cls = Class::Handle(core_lib.LookupClass(cls_name, NULL));
493 ASSERT(!cls.IsNull()); 493 ASSERT(!cls.IsNull());
494 // There are no parameterized error types, so no need to set type arguments. 494 // There are no parameterized error types, so no need to set type arguments.
495 return Instance::New(cls); 495 return Instance::New(cls);
496 } 496 }
497 497
498 498
499 // Allocate, initialize, and throw a TypeError. 499 // Allocate, initialize, and throw a TypeError or CastError.
500 void Exceptions::CreateAndThrowTypeError(intptr_t location, 500 void Exceptions::CreateAndThrowTypeError(intptr_t location,
501 const String& src_type_name, 501 const String& src_type_name,
502 const String& dst_type_name, 502 const String& dst_type_name,
503 const String& dst_name, 503 const String& dst_name,
504 const String& malformed_error) { 504 const String& malformed_error) {
505 const Array& args = Array::Handle(Array::New(8)); 505 const Array& args = Array::Handle(Array::New(7));
506 506
507 ExceptionType exception_type = 507 ExceptionType exception_type =
508 dst_name.Equals(kCastErrorDstName) ? kCast : kType; 508 dst_name.Equals(kCastErrorDstName) ? kCast : kType;
509 509
510 // Initialize argument 'failedAssertion'.
511 // Printing the src_obj value would be possible, but ToString() is expensive
512 // and not meaningful for all classes, so we just print '$expr instanceof...'.
513 // Users should look at TypeError.ToString(), which contains more useful
514 // information than AssertionError.failedAssertion.
515 String& failed_assertion = String::Handle(String::New("$expr instanceof "));
516 failed_assertion = String::Concat(failed_assertion, dst_type_name);
517 args.SetAt(0, failed_assertion);
518
519 // Initialize 'url', 'line', and 'column' arguments.
520 DartFrameIterator iterator; 510 DartFrameIterator iterator;
521 const Script& script = Script::Handle(GetCallerScript(&iterator)); 511 const Script& script = Script::Handle(GetCallerScript(&iterator));
522 intptr_t line, column; 512 intptr_t line, column;
523 script.GetTokenLocation(location, &line, &column); 513 script.GetTokenLocation(location, &line, &column);
524 args.SetAt(1, String::Handle(script.url())); 514 // Initialize '_url', '_line', and '_column' arguments.
525 args.SetAt(2, Smi::Handle(Smi::New(line))); 515 args.SetAt(0, String::Handle(script.url()));
526 args.SetAt(3, Smi::Handle(Smi::New(column))); 516 args.SetAt(1, Smi::Handle(Smi::New(line)));
517 args.SetAt(2, Smi::Handle(Smi::New(column)));
527 518
528 // Initialize argument 'srcType'. 519 // Initialize '_srcType', '_dstType', '_dstName', and '_malformedError'.
529 args.SetAt(4, src_type_name); 520 args.SetAt(3, src_type_name);
530 args.SetAt(5, dst_type_name); 521 args.SetAt(4, dst_type_name);
531 args.SetAt(6, dst_name); 522 args.SetAt(5, dst_name);
532 args.SetAt(7, malformed_error); 523 args.SetAt(6, malformed_error);
533 524
534 // Type errors in the core library may be difficult to diagnose. 525 // Type errors in the core library may be difficult to diagnose.
535 // Print type error information before throwing the error when debugging. 526 // Print type error information before throwing the error when debugging.
536 if (FLAG_print_stacktrace_at_throw) { 527 if (FLAG_print_stacktrace_at_throw) {
537 if (!malformed_error.IsNull()) { 528 if (!malformed_error.IsNull()) {
538 OS::Print("%s\n", malformed_error.ToCString()); 529 OS::Print("%s\n", malformed_error.ToCString());
539 } 530 }
540 intptr_t line, column; 531 intptr_t line, column;
541 script.GetTokenLocation(location, &line, &column); 532 script.GetTokenLocation(location, &line, &column);
542 OS::Print("'%s': Failed type check: line %"Pd" pos %"Pd": ", 533 OS::Print("'%s': Failed type check: line %"Pd" pos %"Pd": ",
543 String::Handle(script.url()).ToCString(), line, column); 534 String::Handle(script.url()).ToCString(), line, column);
544 if (!dst_name.IsNull() && (dst_name.Length() > 0)) { 535 if (!dst_name.IsNull() && (dst_name.Length() > 0)) {
545 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n", 536 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n",
546 src_type_name.ToCString(), 537 src_type_name.ToCString(),
547 dst_type_name.ToCString(), 538 dst_type_name.ToCString(),
548 dst_name.ToCString()); 539 dst_name.ToCString());
549 } else { 540 } else {
550 OS::Print("malformed type used.\n"); 541 OS::Print("malformed type used.\n");
551 } 542 }
552 } 543 }
553 // Throw TypeError instance. 544 // Throw TypeError or CastError instance.
554 Exceptions::ThrowByType(exception_type, args); 545 Exceptions::ThrowByType(exception_type, args);
555 UNREACHABLE(); 546 UNREACHABLE();
556 } 547 }
557 548
558 549
559 void Exceptions::Throw(const Instance& exception) { 550 void Exceptions::Throw(const Instance& exception) {
560 Isolate* isolate = Isolate::Current(); 551 Isolate* isolate = Isolate::Current();
561 isolate->debugger()->SignalExceptionThrown(exception); 552 isolate->debugger()->SignalExceptionThrown(exception);
562 // Null object is a valid exception object. 553 // Null object is a valid exception object.
563 ThrowExceptionHelper(exception, Instance::Handle(isolate)); 554 ThrowExceptionHelper(exception, Instance::Handle(isolate));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 library = Library::CoreLibrary(); 629 library = Library::CoreLibrary();
639 class_name = &Symbols::RangeError(); 630 class_name = &Symbols::RangeError();
640 break; 631 break;
641 case kArgument: 632 case kArgument:
642 library = Library::CoreLibrary(); 633 library = Library::CoreLibrary();
643 class_name = &Symbols::ArgumentError(); 634 class_name = &Symbols::ArgumentError();
644 break; 635 break;
645 case kNoSuchMethod: 636 case kNoSuchMethod:
646 library = Library::CoreLibrary(); 637 library = Library::CoreLibrary();
647 class_name = &Symbols::NoSuchMethodError(); 638 class_name = &Symbols::NoSuchMethodError();
648 constructor_name = &String::Handle(Symbols::New("._withType")); 639 constructor_name = &Symbols::DotWithType();
649 break; 640 break;
650 case kFormat: 641 case kFormat:
651 library = Library::CoreLibrary(); 642 library = Library::CoreLibrary();
652 class_name = &Symbols::FormatException(); 643 class_name = &Symbols::FormatException();
653 break; 644 break;
654 case kUnsupported: 645 case kUnsupported:
655 library = Library::CoreLibrary(); 646 library = Library::CoreLibrary();
656 class_name = &Symbols::UnsupportedError(); 647 class_name = &Symbols::UnsupportedError();
657 break; 648 break;
658 case kInternalError: 649 case kInternalError:
(...skipping 12 matching lines...) Expand all
671 library = Library::IsolateLibrary(); 662 library = Library::IsolateLibrary();
672 class_name = &Symbols::IsolateUnhandledException(); 663 class_name = &Symbols::IsolateUnhandledException();
673 break; 664 break;
674 case kJavascriptIntegerOverflowError: 665 case kJavascriptIntegerOverflowError:
675 library = Library::CoreLibrary(); 666 library = Library::CoreLibrary();
676 class_name = &Symbols::JavascriptIntegerOverflowError(); 667 class_name = &Symbols::JavascriptIntegerOverflowError();
677 break; 668 break;
678 case kAssertion: 669 case kAssertion:
679 library = Library::CoreLibrary(); 670 library = Library::CoreLibrary();
680 class_name = &Symbols::AssertionError(); 671 class_name = &Symbols::AssertionError();
672 constructor_name = &Symbols::DotCreate();
681 break; 673 break;
682 case kCast: 674 case kCast:
683 library = Library::CoreLibrary(); 675 library = Library::CoreLibrary();
684 class_name = &Symbols::CastError(); 676 class_name = &Symbols::CastError();
677 constructor_name = &Symbols::DotCreate();
685 break; 678 break;
686 case kType: 679 case kType:
687 library = Library::CoreLibrary(); 680 library = Library::CoreLibrary();
688 class_name = &Symbols::TypeError(); 681 class_name = &Symbols::TypeError();
682 constructor_name = &Symbols::DotCreate();
689 break; 683 break;
690 case kFallThrough: 684 case kFallThrough:
691 library = Library::CoreLibrary(); 685 library = Library::CoreLibrary();
692 class_name = &Symbols::FallThroughError(); 686 class_name = &Symbols::FallThroughError();
687 constructor_name = &Symbols::DotCreate();
693 break; 688 break;
694 case kAbstractClassInstantiation: 689 case kAbstractClassInstantiation:
695 library = Library::CoreLibrary(); 690 library = Library::CoreLibrary();
696 class_name = &Symbols::AbstractClassInstantiationError(); 691 class_name = &Symbols::AbstractClassInstantiationError();
692 constructor_name = &Symbols::DotCreate();
697 break; 693 break;
698 case kMirroredUncaughtExceptionError: 694 case kMirroredUncaughtExceptionError:
699 library = Library::MirrorsLibrary(); 695 library = Library::MirrorsLibrary();
700 class_name = &Symbols::MirroredUncaughtExceptionError(); 696 class_name = &Symbols::MirroredUncaughtExceptionError();
701 break; 697 break;
702 case kMirroredCompilationError: 698 case kMirroredCompilationError:
703 library = Library::MirrorsLibrary(); 699 library = Library::MirrorsLibrary();
704 class_name = &Symbols::MirroredCompilationError(); 700 class_name = &Symbols::MirroredCompilationError();
705 break; 701 break;
706 } 702 }
707 703
708 return DartLibraryCalls::InstanceCreate(library, 704 return DartLibraryCalls::InstanceCreate(library,
709 *class_name, 705 *class_name,
710 *constructor_name, 706 *constructor_name,
711 arguments); 707 arguments);
712 } 708 }
713 709
714 } // namespace dart 710 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/flow_graph_compiler_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698