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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 const Array& args = Array::Handle(Array::New(1)); | 559 const Array& args = Array::Handle(Array::New(1)); |
560 args.SetAt(0, arg); | 560 args.SetAt(0, arg); |
561 Exceptions::ThrowByType(Exceptions::kArgument, args); | 561 Exceptions::ThrowByType(Exceptions::kArgument, args); |
562 } | 562 } |
563 | 563 |
564 | 564 |
565 void Exceptions::ThrowRangeError(const char* argument_name, | 565 void Exceptions::ThrowRangeError(const char* argument_name, |
566 const Integer& argument_value, | 566 const Integer& argument_value, |
567 intptr_t expected_from, | 567 intptr_t expected_from, |
568 intptr_t expected_to) { | 568 intptr_t expected_to) { |
569 const Array& args = Array::Handle(Array::New(4)); | 569 const String& error = String::Handle(String::NewFormatted( |
570 args.SetAt(0, argument_value); | 570 "%s (%s) must be in the range [%" Pd "..%" Pd ")", |
571 args.SetAt(1, Integer::Handle(Integer::New(expected_from))); | 571 argument_name, |
572 args.SetAt(2, Integer::Handle(Integer::New(expected_to))); | 572 argument_value.ToCString(), |
573 args.SetAt(3, String::Handle(String::New(argument_name))); | 573 expected_from, |
574 Exceptions::ThrowByType(Exceptions::kRangeRange, args); | 574 expected_to)); |
| 575 |
| 576 const Array& args = Array::Handle(Array::New(1)); |
| 577 args.SetAt(0, error); |
| 578 Exceptions::ThrowByType(Exceptions::kRange, args); |
575 } | 579 } |
576 | 580 |
577 | 581 |
578 RawObject* Exceptions::Create(ExceptionType type, const Array& arguments) { | 582 RawObject* Exceptions::Create(ExceptionType type, const Array& arguments) { |
579 Library& library = Library::Handle(); | 583 Library& library = Library::Handle(); |
580 const String* class_name = NULL; | 584 const String* class_name = NULL; |
581 const String* constructor_name = &Symbols::Dot(); | 585 const String* constructor_name = &Symbols::Dot(); |
582 switch (type) { | 586 switch (type) { |
583 case kNone: | 587 case kNone: |
584 case kStackOverflow: | 588 case kStackOverflow: |
585 case kOutOfMemory: | 589 case kOutOfMemory: |
586 UNREACHABLE(); | 590 UNREACHABLE(); |
587 break; | 591 break; |
588 case kRange: | 592 case kRange: |
589 library = Library::CoreLibrary(); | 593 library = Library::CoreLibrary(); |
590 class_name = &Symbols::RangeError(); | 594 class_name = &Symbols::RangeError(); |
591 break; | 595 break; |
592 case kRangeRange: | |
593 library = Library::CoreLibrary(); | |
594 class_name = &Symbols::RangeError(); | |
595 constructor_name = &Symbols::DotRange(); | |
596 break; | |
597 case kArgument: | 596 case kArgument: |
598 library = Library::CoreLibrary(); | 597 library = Library::CoreLibrary(); |
599 class_name = &Symbols::ArgumentError(); | 598 class_name = &Symbols::ArgumentError(); |
600 break; | 599 break; |
601 case kNoSuchMethod: | 600 case kNoSuchMethod: |
602 library = Library::CoreLibrary(); | 601 library = Library::CoreLibrary(); |
603 class_name = &Symbols::NoSuchMethodError(); | 602 class_name = &Symbols::NoSuchMethodError(); |
604 constructor_name = &Symbols::DotWithType(); | 603 constructor_name = &Symbols::DotWithType(); |
605 break; | 604 break; |
606 case kFormat: | 605 case kFormat: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 | 669 |
671 // Throw JavascriptCompatibilityError exception. | 670 // Throw JavascriptCompatibilityError exception. |
672 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { | 671 void Exceptions::ThrowJavascriptCompatibilityError(const char* msg) { |
673 const Array& exc_args = Array::Handle(Array::New(1)); | 672 const Array& exc_args = Array::Handle(Array::New(1)); |
674 const String& msg_str = String::Handle(String::New(msg)); | 673 const String& msg_str = String::Handle(String::New(msg)); |
675 exc_args.SetAt(0, msg_str); | 674 exc_args.SetAt(0, msg_str); |
676 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); | 675 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); |
677 } | 676 } |
678 | 677 |
679 } // namespace dart | 678 } // namespace dart |
OLD | NEW |