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 16 matching lines...) Expand all Loading... |
27 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} | 27 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} |
28 #endif // defined(__has_feature) | 28 #endif // defined(__has_feature) |
29 | 29 |
30 | 30 |
31 namespace dart { | 31 namespace dart { |
32 | 32 |
33 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, | 33 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, |
34 "Prints a stack trace everytime a throw occurs."); | 34 "Prints a stack trace everytime a throw occurs."); |
35 DEFINE_FLAG(bool, verbose_stacktrace, false, | 35 DEFINE_FLAG(bool, verbose_stacktrace, false, |
36 "Stack traces will include methods marked invisible."); | 36 "Stack traces will include methods marked invisible."); |
| 37 DEFINE_FLAG(int, stacktrace_depth_on_warning, 5, |
| 38 "Maximal number of stack frames to print after a runtime warning."); |
| 39 DECLARE_FLAG(bool, silent_warnings); |
| 40 DECLARE_FLAG(bool, warning_as_error); |
| 41 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 42 |
37 | 43 |
38 const char* Exceptions::kCastErrorDstName = "type cast"; | 44 const char* Exceptions::kCastErrorDstName = "type cast"; |
39 | 45 |
40 | 46 |
41 class StacktraceBuilder : public ValueObject { | 47 class StacktraceBuilder : public ValueObject { |
42 public: | 48 public: |
43 StacktraceBuilder() { } | 49 StacktraceBuilder() { } |
44 virtual ~StacktraceBuilder() { } | 50 virtual ~StacktraceBuilder() { } |
45 | 51 |
46 virtual void AddFrame(const Code& code, | 52 virtual void AddFrame(const Code& code, |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // If instance class extends 'class Error' return '_stackTrace' field. | 340 // If instance class extends 'class Error' return '_stackTrace' field. |
335 Class& test_class = Class::Handle(isolate, instance.clazz()); | 341 Class& test_class = Class::Handle(isolate, instance.clazz()); |
336 AbstractType& type = AbstractType::Handle(isolate, AbstractType::null()); | 342 AbstractType& type = AbstractType::Handle(isolate, AbstractType::null()); |
337 while (true) { | 343 while (true) { |
338 if (test_class.raw() == error_class.raw()) { | 344 if (test_class.raw() == error_class.raw()) { |
339 return error_class.LookupInstanceField(Symbols::_stackTrace()); | 345 return error_class.LookupInstanceField(Symbols::_stackTrace()); |
340 } | 346 } |
341 type = test_class.super_type(); | 347 type = test_class.super_type(); |
342 if (type.IsNull()) return Field::null(); | 348 if (type.IsNull()) return Field::null(); |
343 test_class = type.type_class(); | 349 test_class = type.type_class(); |
344 }; | 350 } |
345 UNREACHABLE(); | 351 UNREACHABLE(); |
346 return Field::null(); | 352 return Field::null(); |
347 } | 353 } |
348 | 354 |
349 | 355 |
350 RawStacktrace* Exceptions::CurrentStacktrace() { | 356 RawStacktrace* Exceptions::CurrentStacktrace() { |
351 Isolate* isolate = Isolate::Current(); | 357 Isolate* isolate = Isolate::Current(); |
352 RegularStacktraceBuilder frame_builder(true); | 358 RegularStacktraceBuilder frame_builder(true); |
353 BuildStackTrace(&frame_builder); | 359 BuildStackTrace(&frame_builder); |
354 | 360 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 class_name = &Symbols::IsolateSpawnException(); | 688 class_name = &Symbols::IsolateSpawnException(); |
683 break; | 689 break; |
684 case kIsolateUnhandledException: | 690 case kIsolateUnhandledException: |
685 library = Library::IsolateLibrary(); | 691 library = Library::IsolateLibrary(); |
686 class_name = &Symbols::IsolateUnhandledException(); | 692 class_name = &Symbols::IsolateUnhandledException(); |
687 break; | 693 break; |
688 case kJavascriptIntegerOverflowError: | 694 case kJavascriptIntegerOverflowError: |
689 library = Library::CoreLibrary(); | 695 library = Library::CoreLibrary(); |
690 class_name = &Symbols::JavascriptIntegerOverflowError(); | 696 class_name = &Symbols::JavascriptIntegerOverflowError(); |
691 break; | 697 break; |
| 698 case kJavascriptCompatibilityError: |
| 699 library = Library::CoreLibrary(); |
| 700 class_name = &Symbols::JavascriptCompatibilityError(); |
| 701 break; |
692 case kAssertion: | 702 case kAssertion: |
693 library = Library::CoreLibrary(); | 703 library = Library::CoreLibrary(); |
694 class_name = &Symbols::AssertionError(); | 704 class_name = &Symbols::AssertionError(); |
695 constructor_name = &Symbols::DotCreate(); | 705 constructor_name = &Symbols::DotCreate(); |
696 break; | 706 break; |
697 case kCast: | 707 case kCast: |
698 library = Library::CoreLibrary(); | 708 library = Library::CoreLibrary(); |
699 class_name = &Symbols::CastError(); | 709 class_name = &Symbols::CastError(); |
700 constructor_name = &Symbols::DotCreate(); | 710 constructor_name = &Symbols::DotCreate(); |
701 break; | 711 break; |
(...skipping 17 matching lines...) Expand all Loading... |
719 class_name = &Symbols::MirroredCompilationError(); | 729 class_name = &Symbols::MirroredCompilationError(); |
720 break; | 730 break; |
721 } | 731 } |
722 | 732 |
723 return DartLibraryCalls::InstanceCreate(library, | 733 return DartLibraryCalls::InstanceCreate(library, |
724 *class_name, | 734 *class_name, |
725 *constructor_name, | 735 *constructor_name, |
726 arguments); | 736 arguments); |
727 } | 737 } |
728 | 738 |
| 739 |
| 740 // Throw JavascriptCompatibilityError exception. |
| 741 static void ThrowJavascriptCompatibilityError(const char* msg) { |
| 742 const Array& exc_args = Array::Handle(Array::New(1)); |
| 743 const String& msg_str = String::Handle(String::New(msg)); |
| 744 exc_args.SetAt(0, msg_str); |
| 745 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); |
| 746 } |
| 747 |
| 748 |
| 749 void Exceptions::JSWarning(StackFrame* caller_frame, const char* format, ...) { |
| 750 ASSERT(caller_frame != NULL); |
| 751 ASSERT(FLAG_warn_on_javascript_compatibility); |
| 752 if (FLAG_silent_warnings) return; |
| 753 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); |
| 754 ASSERT(!caller_code.IsNull()); |
| 755 const uword caller_pc = caller_frame->pc(); |
| 756 const intptr_t token_pos = caller_code.GetTokenIndexOfPC(caller_pc); |
| 757 const Function& caller = Function::Handle(caller_code.function()); |
| 758 const Script& script = Script::Handle(caller.script()); |
| 759 va_list args; |
| 760 va_start(args, format); |
| 761 const Error& error = Error::Handle( |
| 762 LanguageError::NewFormattedV(Error::Handle(), // No previous error. |
| 763 script, token_pos, LanguageError::kWarning, |
| 764 Heap::kNew, format, args)); |
| 765 va_end(args); |
| 766 if (FLAG_warning_as_error) { |
| 767 ThrowJavascriptCompatibilityError(error.ToErrorCString()); |
| 768 } else { |
| 769 OS::Print("javascript compatibility warning: %s", error.ToErrorCString()); |
| 770 } |
| 771 const Stacktrace& stacktrace = |
| 772 Stacktrace::Handle(Exceptions::CurrentStacktrace()); |
| 773 intptr_t idx = 0; |
| 774 OS::Print("%s", |
| 775 stacktrace.ToCStringInternal(&idx, |
| 776 FLAG_stacktrace_depth_on_warning)); |
| 777 } |
| 778 |
729 } // namespace dart | 779 } // namespace dart |
OLD | NEW |