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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 const String& msg_str = String::Handle(String::New(msg)); | 743 const String& msg_str = String::Handle(String::New(msg)); |
744 exc_args.SetAt(0, msg_str); | 744 exc_args.SetAt(0, msg_str); |
745 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); | 745 Exceptions::ThrowByType(Exceptions::kJavascriptCompatibilityError, exc_args); |
746 } | 746 } |
747 | 747 |
748 | 748 |
749 void Exceptions::JSWarning(StackFrame* caller_frame, const char* format, ...) { | 749 void Exceptions::JSWarning(StackFrame* caller_frame, const char* format, ...) { |
750 ASSERT(caller_frame != NULL); | 750 ASSERT(caller_frame != NULL); |
751 ASSERT(FLAG_warn_on_javascript_compatibility); | 751 ASSERT(FLAG_warn_on_javascript_compatibility); |
752 if (FLAG_silent_warnings) return; | 752 if (FLAG_silent_warnings) return; |
753 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | 753 Isolate* isolate = Isolate::Current(); |
| 754 const Code& caller_code = Code::Handle(isolate, |
| 755 caller_frame->LookupDartCode()); |
754 ASSERT(!caller_code.IsNull()); | 756 ASSERT(!caller_code.IsNull()); |
755 const uword caller_pc = caller_frame->pc(); | 757 const uword caller_pc = caller_frame->pc(); |
756 const intptr_t token_pos = caller_code.GetTokenIndexOfPC(caller_pc); | 758 const intptr_t token_pos = caller_code.GetTokenIndexOfPC(caller_pc); |
757 const Function& caller = Function::Handle(caller_code.function()); | 759 const Function& caller = Function::Handle(isolate, caller_code.function()); |
758 const Script& script = Script::Handle(caller.script()); | 760 const Script& script = Script::Handle(isolate, caller.script()); |
759 va_list args; | 761 va_list args; |
760 va_start(args, format); | 762 va_start(args, format); |
761 const Error& error = Error::Handle( | 763 const Error& error = Error::Handle(isolate, |
762 LanguageError::NewFormattedV(Error::Handle(), // No previous error. | 764 LanguageError::NewFormattedV(Error::Handle(isolate), // No prev error. |
763 script, token_pos, LanguageError::kWarning, | 765 script, token_pos, LanguageError::kWarning, |
764 Heap::kNew, format, args)); | 766 Heap::kNew, format, args)); |
765 va_end(args); | 767 va_end(args); |
766 if (FLAG_warning_as_error) { | 768 if (FLAG_warning_as_error) { |
767 ThrowJavascriptCompatibilityError(error.ToErrorCString()); | 769 ThrowJavascriptCompatibilityError(error.ToErrorCString()); |
768 } else { | 770 } else { |
769 OS::Print("javascript compatibility warning: %s", error.ToErrorCString()); | 771 OS::Print("javascript compatibility warning: %s", error.ToErrorCString()); |
| 772 va_start(args, format); |
| 773 TraceJSWarningV(script, token_pos, format, args); |
| 774 va_end(args); |
770 } | 775 } |
771 const Stacktrace& stacktrace = | 776 const Stacktrace& stacktrace = |
772 Stacktrace::Handle(Exceptions::CurrentStacktrace()); | 777 Stacktrace::Handle(isolate, Exceptions::CurrentStacktrace()); |
773 intptr_t idx = 0; | 778 intptr_t idx = 0; |
774 OS::Print("%s", | 779 OS::Print("%s", |
775 stacktrace.ToCStringInternal(&idx, | 780 stacktrace.ToCStringInternal(&idx, |
776 FLAG_stacktrace_depth_on_warning)); | 781 FLAG_stacktrace_depth_on_warning)); |
777 } | 782 } |
778 | 783 |
| 784 |
| 785 void Exceptions::TraceJSWarningF(const Script& script, intptr_t token_pos, |
| 786 const char* format, ...) { |
| 787 va_list args; |
| 788 va_start(args, format); |
| 789 TraceJSWarningV(script, token_pos, format, args); |
| 790 va_end(args); |
| 791 } |
| 792 |
| 793 |
| 794 void Exceptions::TraceJSWarningV(const Script& script, intptr_t token_pos, |
| 795 const char* format, va_list args) { |
| 796 const int64_t micros = OS::GetCurrentTimeMicros(); |
| 797 Isolate* isolate = Isolate::Current(); |
| 798 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
| 799 if (trace_buffer == NULL) { |
| 800 TraceBuffer::Init(isolate); |
| 801 trace_buffer = isolate->trace_buffer(); |
| 802 } |
| 803 JSONStream js; |
| 804 { |
| 805 JSONObject trace_warning(&js); |
| 806 trace_warning.AddProperty("type", "JSCompatibilityWarning"); |
| 807 trace_warning.AddProperty("script", script); |
| 808 trace_warning.AddProperty("tokenPos", token_pos); |
| 809 va_list args_copy; |
| 810 va_copy(args_copy, args); |
| 811 const intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); |
| 812 va_end(args_copy); |
| 813 char* msg = reinterpret_cast<char*>(malloc(len + 1)); |
| 814 va_copy(args_copy, args); |
| 815 OS::VSNPrint(msg, len + 1, format, args_copy); |
| 816 va_end(args_copy); |
| 817 trace_warning.AddProperty("message", msg); |
| 818 } |
| 819 trace_buffer->Trace(micros, js.ToCString(), true); // Already escaped. |
| 820 } |
| 821 |
779 } // namespace dart | 822 } // namespace dart |
OLD | NEW |