| OLD | NEW |
| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 484 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 485 // No ambiguity error expected: passing NULL. | 485 // No ambiguity error expected: passing NULL. |
| 486 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); | 486 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); |
| 487 ASSERT(!cls.IsNull()); | 487 ASSERT(!cls.IsNull()); |
| 488 // There are no parameterized error types, so no need to set type arguments. | 488 // There are no parameterized error types, so no need to set type arguments. |
| 489 return Instance::New(cls); | 489 return Instance::New(cls); |
| 490 } | 490 } |
| 491 | 491 |
| 492 | 492 |
| 493 // Allocate, initialize, and throw a TypeError or CastError. | 493 // Allocate, initialize, and throw a TypeError or CastError. |
| 494 // If bound_error is not null, throw a TypeError, even for a type cast. |
| 494 void Exceptions::CreateAndThrowTypeError(intptr_t location, | 495 void Exceptions::CreateAndThrowTypeError(intptr_t location, |
| 495 const String& src_type_name, | 496 const String& src_type_name, |
| 496 const String& dst_type_name, | 497 const String& dst_type_name, |
| 497 const String& dst_name, | 498 const String& dst_name, |
| 498 const String& malformed_error) { | 499 const String& bound_error) { |
| 499 const Array& args = Array::Handle(Array::New(7)); | 500 const Array& args = Array::Handle(Array::New(7)); |
| 500 | 501 |
| 501 ExceptionType exception_type = | 502 ExceptionType exception_type = |
| 502 dst_name.Equals(kCastErrorDstName) ? kCast : kType; | 503 (bound_error.IsNull() && dst_name.Equals(kCastErrorDstName)) ? |
| 504 kCast : kType; |
| 503 | 505 |
| 504 DartFrameIterator iterator; | 506 DartFrameIterator iterator; |
| 505 const Script& script = Script::Handle(GetCallerScript(&iterator)); | 507 const Script& script = Script::Handle(GetCallerScript(&iterator)); |
| 506 intptr_t line, column; | 508 intptr_t line, column; |
| 507 script.GetTokenLocation(location, &line, &column); | 509 script.GetTokenLocation(location, &line, &column); |
| 508 // Initialize '_url', '_line', and '_column' arguments. | 510 // Initialize '_url', '_line', and '_column' arguments. |
| 509 args.SetAt(0, String::Handle(script.url())); | 511 args.SetAt(0, String::Handle(script.url())); |
| 510 args.SetAt(1, Smi::Handle(Smi::New(line))); | 512 args.SetAt(1, Smi::Handle(Smi::New(line))); |
| 511 args.SetAt(2, Smi::Handle(Smi::New(column))); | 513 args.SetAt(2, Smi::Handle(Smi::New(column))); |
| 512 | 514 |
| 513 // Initialize '_srcType', '_dstType', '_dstName', and '_malformedError'. | 515 // Initialize '_srcType', '_dstType', '_dstName', and '_boundError'. |
| 514 args.SetAt(3, src_type_name); | 516 args.SetAt(3, src_type_name); |
| 515 args.SetAt(4, dst_type_name); | 517 args.SetAt(4, dst_type_name); |
| 516 args.SetAt(5, dst_name); | 518 args.SetAt(5, dst_name); |
| 517 args.SetAt(6, malformed_error); | 519 args.SetAt(6, bound_error); |
| 518 | 520 |
| 519 // Type errors in the core library may be difficult to diagnose. | 521 // Type errors in the core library may be difficult to diagnose. |
| 520 // Print type error information before throwing the error when debugging. | 522 // Print type error information before throwing the error when debugging. |
| 521 if (FLAG_print_stacktrace_at_throw) { | 523 if (FLAG_print_stacktrace_at_throw) { |
| 522 if (!malformed_error.IsNull()) { | 524 if (!bound_error.IsNull()) { |
| 523 OS::Print("%s\n", malformed_error.ToCString()); | 525 OS::Print("%s\n", bound_error.ToCString()); |
| 524 } | 526 } |
| 525 intptr_t line, column; | 527 intptr_t line, column; |
| 526 script.GetTokenLocation(location, &line, &column); | 528 script.GetTokenLocation(location, &line, &column); |
| 527 OS::Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ", | 529 OS::Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ", |
| 528 String::Handle(script.url()).ToCString(), line, column); | 530 String::Handle(script.url()).ToCString(), line, column); |
| 529 if (!dst_name.IsNull() && (dst_name.Length() > 0)) { | 531 if (!dst_name.IsNull() && (dst_name.Length() > 0)) { |
| 530 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n", | 532 OS::Print("type '%s' is not a subtype of type '%s' of '%s'.\n", |
| 531 src_type_name.ToCString(), | 533 src_type_name.ToCString(), |
| 532 dst_type_name.ToCString(), | 534 dst_type_name.ToCString(), |
| 533 dst_name.ToCString()); | 535 dst_name.ToCString()); |
| 534 } else { | 536 } else { |
| 535 OS::Print("malformed type used.\n"); | 537 OS::Print("malbounded type used.\n"); |
| 536 } | 538 } |
| 537 } | 539 } |
| 538 // Throw TypeError or CastError instance. | 540 // Throw TypeError or CastError instance. |
| 539 Exceptions::ThrowByType(exception_type, args); | 541 Exceptions::ThrowByType(exception_type, args); |
| 540 UNREACHABLE(); | 542 UNREACHABLE(); |
| 541 } | 543 } |
| 542 | 544 |
| 543 | 545 |
| 544 void Exceptions::Throw(const Instance& exception) { | 546 void Exceptions::Throw(const Instance& exception) { |
| 545 Isolate* isolate = Isolate::Current(); | 547 Isolate* isolate = Isolate::Current(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 break; | 704 break; |
| 703 } | 705 } |
| 704 | 706 |
| 705 return DartLibraryCalls::InstanceCreate(library, | 707 return DartLibraryCalls::InstanceCreate(library, |
| 706 *class_name, | 708 *class_name, |
| 707 *constructor_name, | 709 *constructor_name, |
| 708 arguments); | 710 arguments); |
| 709 } | 711 } |
| 710 | 712 |
| 711 } // namespace dart | 713 } // namespace dart |
| OLD | NEW |