Chromium Code Reviews| 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/code_patcher.h" | |
| 7 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 8 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 9 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| 10 #include "vm/flags.h" | 11 #include "vm/flags.h" |
| 11 #include "vm/object.h" | 12 #include "vm/object.h" |
| 12 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
| 13 #include "vm/stack_frame.h" | 14 #include "vm/stack_frame.h" |
| 14 #include "vm/stub_code.h" | 15 #include "vm/stub_code.h" |
| 15 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 16 #include "vm/tags.h" | 17 #include "vm/tags.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 27 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} | 28 void __asan_unpoison_memory_region(void* ignore1, size_t ignore2) {} |
| 28 #endif // defined(__has_feature) | 29 #endif // defined(__has_feature) |
| 29 | 30 |
| 30 | 31 |
| 31 namespace dart { | 32 namespace dart { |
| 32 | 33 |
| 33 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, | 34 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, |
| 34 "Prints a stack trace everytime a throw occurs."); | 35 "Prints a stack trace everytime a throw occurs."); |
| 35 DEFINE_FLAG(bool, verbose_stacktrace, false, | 36 DEFINE_FLAG(bool, verbose_stacktrace, false, |
| 36 "Stack traces will include methods marked invisible."); | 37 "Stack traces will include methods marked invisible."); |
| 38 DEFINE_FLAG(int, stacktrace_depth_on_warning, 5, | |
| 39 "Maximal number of stack frames to print after a runtime warning."); | |
| 40 DECLARE_FLAG(bool, silent_warnings); | |
| 41 DECLARE_FLAG(bool, warning_as_error); | |
| 42 DECLARE_FLAG(bool, warn_on_javascript_incompatibility); | |
| 43 | |
| 37 | 44 |
| 38 const char* Exceptions::kCastErrorDstName = "type cast"; | 45 const char* Exceptions::kCastErrorDstName = "type cast"; |
| 39 | 46 |
| 40 | 47 |
| 41 class StacktraceBuilder : public ValueObject { | 48 class StacktraceBuilder : public ValueObject { |
| 42 public: | 49 public: |
| 43 StacktraceBuilder() { } | 50 StacktraceBuilder() { } |
| 44 virtual ~StacktraceBuilder() { } | 51 virtual ~StacktraceBuilder() { } |
| 45 | 52 |
| 46 virtual void AddFrame(const Code& code, | 53 virtual void AddFrame(const Code& code, |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 class_name = &Symbols::IsolateSpawnException(); | 689 class_name = &Symbols::IsolateSpawnException(); |
| 683 break; | 690 break; |
| 684 case kIsolateUnhandledException: | 691 case kIsolateUnhandledException: |
| 685 library = Library::IsolateLibrary(); | 692 library = Library::IsolateLibrary(); |
| 686 class_name = &Symbols::IsolateUnhandledException(); | 693 class_name = &Symbols::IsolateUnhandledException(); |
| 687 break; | 694 break; |
| 688 case kJavascriptIntegerOverflowError: | 695 case kJavascriptIntegerOverflowError: |
| 689 library = Library::CoreLibrary(); | 696 library = Library::CoreLibrary(); |
| 690 class_name = &Symbols::JavascriptIntegerOverflowError(); | 697 class_name = &Symbols::JavascriptIntegerOverflowError(); |
| 691 break; | 698 break; |
| 699 case kJavascriptCompatibilityError: | |
| 700 library = Library::CoreLibrary(); | |
| 701 class_name = &Symbols::JavascriptCompatibilityError(); | |
| 702 break; | |
| 692 case kAssertion: | 703 case kAssertion: |
| 693 library = Library::CoreLibrary(); | 704 library = Library::CoreLibrary(); |
| 694 class_name = &Symbols::AssertionError(); | 705 class_name = &Symbols::AssertionError(); |
| 695 constructor_name = &Symbols::DotCreate(); | 706 constructor_name = &Symbols::DotCreate(); |
| 696 break; | 707 break; |
| 697 case kCast: | 708 case kCast: |
| 698 library = Library::CoreLibrary(); | 709 library = Library::CoreLibrary(); |
| 699 class_name = &Symbols::CastError(); | 710 class_name = &Symbols::CastError(); |
| 700 constructor_name = &Symbols::DotCreate(); | 711 constructor_name = &Symbols::DotCreate(); |
| 701 break; | 712 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 719 class_name = &Symbols::MirroredCompilationError(); | 730 class_name = &Symbols::MirroredCompilationError(); |
| 720 break; | 731 break; |
| 721 } | 732 } |
| 722 | 733 |
| 723 return DartLibraryCalls::InstanceCreate(library, | 734 return DartLibraryCalls::InstanceCreate(library, |
| 724 *class_name, | 735 *class_name, |
| 725 *constructor_name, | 736 *constructor_name, |
| 726 arguments); | 737 arguments); |
| 727 } | 738 } |
| 728 | 739 |
| 740 | |
| 741 // Throw JavascriptCompatibilityError exception. | |
| 742 static void ThrowJavascriptCompatibilityError(const char* msg) { | |
| 743 const Array& exc_args = Array::Handle(Array::New(1)); | |
| 744 const String& msg_str = String::Handle(String::New(msg)); | |
| 745 exc_args.SetAt(0, msg_str); | |
| 746 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); | |
| 747 } | |
| 748 | |
| 749 | |
| 750 bool Exceptions::MayIssueJSWarning(const ICData& ic_data, bool check_issued) { | |
| 751 if (check_issued && ic_data.IssuedJSWarning()) { | |
| 752 return false; | |
| 753 } | |
| 754 const String& target_name = String::Handle(ic_data.target_name()); | |
| 755 if (target_name.Equals(Library::PrivateCoreLibName(Symbols::_instanceOf())) || | |
| 756 target_name.Equals(Library::PrivateCoreLibName(Symbols::_as())) || | |
| 757 target_name.Equals(Symbols::toString())) { | |
| 758 return true; | |
| 759 } | |
| 760 return false; | |
| 761 } | |
| 762 | |
| 763 | |
| 764 void Exceptions::JSWarning(const ICData& ic_data, const char* format, ...) { | |
|
srdjan
2014/05/08 18:11:05
Try always passing ICData and do the necessary cod
regis
2014/05/09 21:03:42
Done.
| |
| 765 ASSERT(FLAG_warn_on_javascript_incompatibility); | |
| 766 if (FLAG_silent_warnings) return; | |
| 767 if (!ic_data.IsNull()) { | |
| 768 // Report warning only if not already reported at this location. | |
| 769 if (ic_data.IssuedJSWarning()) { | |
| 770 // Warning was already reported at this location. | |
| 771 return; | |
| 772 } | |
| 773 ic_data.SetIssuedJSWarning(); | |
| 774 } | |
| 775 DartFrameIterator iterator; | |
| 776 if (ic_data.IsNull()) { | |
| 777 iterator.NextFrame(); // Skip native call. | |
| 778 } | |
| 779 StackFrame* caller_frame = iterator.NextFrame(); | |
| 780 ASSERT(caller_frame != NULL); | |
| 781 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | |
| 782 ASSERT(!caller_code.IsNull()); | |
| 783 const uword caller_pc = caller_frame->pc(); | |
| 784 if (ic_data.IsNull()) { | |
| 785 // Assume an instance call. | |
| 786 ICData& inst_call_ic_data = ICData::Handle(); | |
| 787 CodePatcher::GetInstanceCallAt(caller_pc, caller_code, &inst_call_ic_data); | |
| 788 ASSERT(!inst_call_ic_data.IsNull()); | |
| 789 // Report warning only if not already reported at this location. | |
| 790 if (inst_call_ic_data.IssuedJSWarning()) { | |
| 791 // Warning was already reported at this location. | |
| 792 return; | |
| 793 } | |
| 794 inst_call_ic_data.SetIssuedJSWarning(); | |
| 795 } | |
| 796 const intptr_t token_pos = caller_code.GetTokenIndexOfPC(caller_pc); | |
| 797 const Function& caller = Function::Handle(caller_code.function()); | |
| 798 const Script& script = Script::Handle(caller.script()); | |
| 799 va_list args; | |
| 800 va_start(args, format); | |
| 801 const Error& error = Error::Handle( | |
| 802 LanguageError::NewFormattedV(Error::Handle(), // No previous error. | |
| 803 script, token_pos, LanguageError::kWarning, | |
| 804 Heap::kNew, format, args)); | |
| 805 va_end(args); | |
| 806 if (FLAG_warning_as_error) { | |
| 807 ThrowJavascriptCompatibilityError(error.ToErrorCString()); | |
| 808 } else { | |
| 809 OS::Print("%s", error.ToErrorCString()); | |
| 810 } | |
| 811 const Stacktrace& stacktrace = | |
| 812 Stacktrace::Handle(Exceptions::CurrentStacktrace()); | |
| 813 intptr_t idx = 0; | |
| 814 OS::Print("%s", | |
| 815 stacktrace.ToCStringInternal(&idx, | |
| 816 FLAG_stacktrace_depth_on_warning)); | |
| 817 } | |
| 818 | |
| 729 } // namespace dart | 819 } // namespace dart |
| OLD | NEW |