| 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 "platform/address_sanitizer.h" | 7 #include "platform/address_sanitizer.h" |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 const Function& caller = Function::Handle(caller_frame->LookupDartFunction()); | 413 const Function& caller = Function::Handle(caller_frame->LookupDartFunction()); |
| 414 ASSERT(!caller.IsNull()); | 414 ASSERT(!caller.IsNull()); |
| 415 return caller.script(); | 415 return caller.script(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 | 418 |
| 419 // Allocate a new instance of the given class name. | 419 // Allocate a new instance of the given class name. |
| 420 // TODO(hausner): Rename this NewCoreInstance to call out the fact that | 420 // TODO(hausner): Rename this NewCoreInstance to call out the fact that |
| 421 // the class name is resolved in the core library implicitly? | 421 // the class name is resolved in the core library implicitly? |
| 422 RawInstance* Exceptions::NewInstance(const char* class_name) { | 422 RawInstance* Exceptions::NewInstance(const char* class_name) { |
| 423 const String& cls_name = String::Handle(Symbols::New(class_name)); | 423 Thread* thread = Thread::Current(); |
| 424 Zone* zone = thread->zone(); |
| 425 const String& cls_name = String::Handle(zone, |
| 426 Symbols::New(thread, class_name)); |
| 424 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 427 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 425 // No ambiguity error expected: passing NULL. | 428 // No ambiguity error expected: passing NULL. |
| 426 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); | 429 Class& cls = Class::Handle(core_lib.LookupClass(cls_name)); |
| 427 ASSERT(!cls.IsNull()); | 430 ASSERT(!cls.IsNull()); |
| 428 // There are no parameterized error types, so no need to set type arguments. | 431 // There are no parameterized error types, so no need to set type arguments. |
| 429 return Instance::New(cls); | 432 return Instance::New(cls); |
| 430 } | 433 } |
| 431 | 434 |
| 432 | 435 |
| 433 // Allocate, initialize, and throw a TypeError or CastError. | 436 // Allocate, initialize, and throw a TypeError or CastError. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 453 script.GetTokenLocation(location, &line, &column); | 456 script.GetTokenLocation(location, &line, &column); |
| 454 } else { | 457 } else { |
| 455 script.GetTokenLocation(location, &line, NULL); | 458 script.GetTokenLocation(location, &line, NULL); |
| 456 } | 459 } |
| 457 // Initialize '_url', '_line', and '_column' arguments. | 460 // Initialize '_url', '_line', and '_column' arguments. |
| 458 args.SetAt(0, String::Handle(zone, script.url())); | 461 args.SetAt(0, String::Handle(zone, script.url())); |
| 459 args.SetAt(1, Smi::Handle(zone, Smi::New(line))); | 462 args.SetAt(1, Smi::Handle(zone, Smi::New(line))); |
| 460 args.SetAt(2, Smi::Handle(zone, Smi::New(column))); | 463 args.SetAt(2, Smi::Handle(zone, Smi::New(column))); |
| 461 | 464 |
| 462 // Construct '_errorMsg'. | 465 // Construct '_errorMsg'. |
| 463 GrowableHandlePtrArray<const String> pieces(zone, 20); | 466 const GrowableObjectArray& pieces = GrowableObjectArray::Handle(zone, |
| 467 GrowableObjectArray::New(20)); |
| 464 | 468 |
| 465 // Print bound error first, if any. | 469 // Print bound error first, if any. |
| 466 if (!bound_error_msg.IsNull() && (bound_error_msg.Length() > 0)) { | 470 if (!bound_error_msg.IsNull() && (bound_error_msg.Length() > 0)) { |
| 467 pieces.Add(bound_error_msg); | 471 pieces.Add(bound_error_msg); |
| 468 pieces.Add(Symbols::NewLine()); | 472 pieces.Add(Symbols::NewLine()); |
| 469 } | 473 } |
| 470 | 474 |
| 471 // If dst_type is malformed or malbounded, only print the embedded error. | 475 // If dst_type is malformed or malbounded, only print the embedded error. |
| 472 if (!dst_type.IsNull()) { | 476 if (!dst_type.IsNull()) { |
| 473 const LanguageError& error = LanguageError::Handle(zone, dst_type.error()); | 477 const LanguageError& error = LanguageError::Handle(zone, dst_type.error()); |
| 474 if (!error.IsNull()) { | 478 if (!error.IsNull()) { |
| 475 // Print the embedded error only. | 479 // Print the embedded error only. |
| 476 pieces.Add(String::Handle(zone, Symbols::New(error.ToErrorCString()))); | 480 pieces.Add(String::Handle(zone, String::New(error.ToErrorCString()))); |
| 477 pieces.Add(Symbols::NewLine()); | 481 pieces.Add(Symbols::NewLine()); |
| 478 } else { | 482 } else { |
| 479 // Describe the type error. | 483 // Describe the type error. |
| 480 if (!src_type.IsNull()) { | 484 if (!src_type.IsNull()) { |
| 481 pieces.Add(Symbols::TypeQuote()); | 485 pieces.Add(Symbols::TypeQuote()); |
| 482 pieces.Add(String::Handle(zone, src_type.UserVisibleName())); | 486 pieces.Add(String::Handle(zone, src_type.UserVisibleName())); |
| 483 pieces.Add(Symbols::QuoteIsNotASubtypeOf()); | 487 pieces.Add(Symbols::QuoteIsNotASubtypeOf()); |
| 484 } | 488 } |
| 485 pieces.Add(Symbols::TypeQuote()); | 489 pieces.Add(Symbols::TypeQuote()); |
| 486 pieces.Add(String::Handle(zone, dst_type.UserVisibleName())); | 490 pieces.Add(String::Handle(zone, dst_type.UserVisibleName())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 508 const String& uris = String::Handle(zone, dst_type.EnumerateURIs()); | 512 const String& uris = String::Handle(zone, dst_type.EnumerateURIs()); |
| 509 if (uris.Length() > Symbols::SpaceIsFromSpace().Length()) { | 513 if (uris.Length() > Symbols::SpaceIsFromSpace().Length()) { |
| 510 if (!printed_where) { | 514 if (!printed_where) { |
| 511 pieces.Add(Symbols::SpaceWhereNewLine()); | 515 pieces.Add(Symbols::SpaceWhereNewLine()); |
| 512 } | 516 } |
| 513 pieces.Add(uris); | 517 pieces.Add(uris); |
| 514 } | 518 } |
| 515 } | 519 } |
| 516 } | 520 } |
| 517 } | 521 } |
| 518 const String& error_msg = | 522 const Array& arr = Array::Handle(zone, Array::MakeArray(pieces)); |
| 519 String::Handle(zone, Symbols::FromConcatAll(pieces)); | 523 const String& error_msg = String::Handle(zone, String::ConcatAll(arr)); |
| 520 args.SetAt(3, error_msg); | 524 args.SetAt(3, error_msg); |
| 521 | 525 |
| 522 // Type errors in the core library may be difficult to diagnose. | 526 // Type errors in the core library may be difficult to diagnose. |
| 523 // Print type error information before throwing the error when debugging. | 527 // Print type error information before throwing the error when debugging. |
| 524 if (FLAG_print_stacktrace_at_throw) { | 528 if (FLAG_print_stacktrace_at_throw) { |
| 525 THR_Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ", | 529 THR_Print("'%s': Failed type check: line %" Pd " pos %" Pd ": ", |
| 526 String::Handle(zone, script.url()).ToCString(), line, column); | 530 String::Handle(zone, script.url()).ToCString(), line, column); |
| 527 THR_Print("%s\n", error_msg.ToCString()); | 531 THR_Print("%s\n", error_msg.ToCString()); |
| 528 } | 532 } |
| 529 | 533 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 716 } |
| 713 | 717 |
| 714 return DartLibraryCalls::InstanceCreate(library, | 718 return DartLibraryCalls::InstanceCreate(library, |
| 715 *class_name, | 719 *class_name, |
| 716 *constructor_name, | 720 *constructor_name, |
| 717 arguments); | 721 arguments); |
| 718 } | 722 } |
| 719 | 723 |
| 720 | 724 |
| 721 } // namespace dart | 725 } // namespace dart |
| OLD | NEW |