| OLD | NEW | 
|     1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file |     1 // Copyright (c) 2013, 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 "include/dart_api.h" |     5 #include "include/dart_api.h" | 
|     6 #include "include/dart_mirrors_api.h" |     6 #include "include/dart_mirrors_api.h" | 
|     7 #include "include/dart_native_api.h" |     7 #include "include/dart_native_api.h" | 
|     8  |     8  | 
|     9 #include "platform/assert.h" |     9 #include "platform/assert.h" | 
|    10 #include "lib/stacktrace.h" |    10 #include "lib/stacktrace.h" | 
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   819     const UnhandledException& error = UnhandledException::Cast(obj); |   819     const UnhandledException& error = UnhandledException::Cast(obj); | 
|   820     return Api::NewHandle(T, error.exception()); |   820     return Api::NewHandle(T, error.exception()); | 
|   821   } else if (obj.IsError()) { |   821   } else if (obj.IsError()) { | 
|   822     return Api::NewError("This error is not an unhandled exception error."); |   822     return Api::NewError("This error is not an unhandled exception error."); | 
|   823   } else { |   823   } else { | 
|   824     return Api::NewError("Can only get exceptions from error handles."); |   824     return Api::NewError("Can only get exceptions from error handles."); | 
|   825   } |   825   } | 
|   826 } |   826 } | 
|   827  |   827  | 
|   828  |   828  | 
|   829 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |   829 DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle) { | 
|   830   DARTSCOPE(Thread::Current()); |   830   DARTSCOPE(Thread::Current()); | 
|   831   const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |   831   const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 
|   832   if (obj.IsUnhandledException()) { |   832   if (obj.IsUnhandledException()) { | 
|   833     const UnhandledException& error = UnhandledException::Cast(obj); |   833     const UnhandledException& error = UnhandledException::Cast(obj); | 
|   834     return Api::NewHandle(T, error.stacktrace()); |   834     return Api::NewHandle(T, error.stacktrace()); | 
|   835   } else if (obj.IsError()) { |   835   } else if (obj.IsError()) { | 
|   836     return Api::NewError("This error is not an unhandled exception error."); |   836     return Api::NewError("This error is not an unhandled exception error."); | 
|   837   } else { |   837   } else { | 
|   838     return Api::NewError("Can only get stacktraces from error handles."); |   838     return Api::NewError("Can only get stacktraces from error handles."); | 
|   839   } |   839   } | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|   859   intptr_t class_id = Api::ClassId(exception); |   859   intptr_t class_id = Api::ClassId(exception); | 
|   860   if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { |   860   if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { | 
|   861     const Object& excp = Object::Handle(Z, Api::UnwrapHandle(exception)); |   861     const Object& excp = Object::Handle(Z, Api::UnwrapHandle(exception)); | 
|   862     obj = String::New(GetErrorString(T, excp)); |   862     obj = String::New(GetErrorString(T, excp)); | 
|   863   } else { |   863   } else { | 
|   864     obj = Api::UnwrapInstanceHandle(Z, exception).raw(); |   864     obj = Api::UnwrapInstanceHandle(Z, exception).raw(); | 
|   865     if (obj.IsNull()) { |   865     if (obj.IsNull()) { | 
|   866       RETURN_TYPE_ERROR(Z, exception, Instance); |   866       RETURN_TYPE_ERROR(Z, exception, Instance); | 
|   867     } |   867     } | 
|   868   } |   868   } | 
|   869   const Stacktrace& stacktrace = Stacktrace::Handle(Z); |   869   const StackTrace& stacktrace = StackTrace::Handle(Z); | 
|   870   return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); |   870   return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); | 
|   871 } |   871 } | 
|   872  |   872  | 
|   873  |   873  | 
|   874 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |   874 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 
|   875   Thread* thread = Thread::Current(); |   875   Thread* thread = Thread::Current(); | 
|   876   TransitionNativeToVM transition(thread); |   876   TransitionNativeToVM transition(thread); | 
|   877   const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(handle)); |   877   const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(handle)); | 
|   878   if (!obj.IsError()) { |   878   if (!obj.IsError()) { | 
|   879     return Api::NewError( |   879     return Api::NewError( | 
| (...skipping 3771 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4651     } |  4651     } | 
|  4652   } |  4652   } | 
|  4653   if (thread->top_exit_frame_info() == 0) { |  4653   if (thread->top_exit_frame_info() == 0) { | 
|  4654     // There are no dart frames on the stack so it would be illegal to |  4654     // There are no dart frames on the stack so it would be illegal to | 
|  4655     // throw an exception here. |  4655     // throw an exception here. | 
|  4656     return Api::NewError("No Dart frames on stack, cannot throw exception"); |  4656     return Api::NewError("No Dart frames on stack, cannot throw exception"); | 
|  4657   } |  4657   } | 
|  4658   // Unwind all the API scopes till the exit frame before throwing an |  4658   // Unwind all the API scopes till the exit frame before throwing an | 
|  4659   // exception. |  4659   // exception. | 
|  4660   const Instance* saved_exception; |  4660   const Instance* saved_exception; | 
|  4661   const Stacktrace* saved_stacktrace; |  4661   const StackTrace* saved_stacktrace; | 
|  4662   { |  4662   { | 
|  4663     NoSafepointScope no_safepoint; |  4663     NoSafepointScope no_safepoint; | 
|  4664     RawInstance* raw_exception = |  4664     RawInstance* raw_exception = | 
|  4665         Api::UnwrapInstanceHandle(zone, exception).raw(); |  4665         Api::UnwrapInstanceHandle(zone, exception).raw(); | 
|  4666     RawStacktrace* raw_stacktrace = |  4666     RawStackTrace* raw_stacktrace = | 
|  4667         Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); |  4667         Api::UnwrapStackTraceHandle(zone, stacktrace).raw(); | 
|  4668     thread->UnwindScopes(thread->top_exit_frame_info()); |  4668     thread->UnwindScopes(thread->top_exit_frame_info()); | 
|  4669     saved_exception = &Instance::Handle(raw_exception); |  4669     saved_exception = &Instance::Handle(raw_exception); | 
|  4670     saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); |  4670     saved_stacktrace = &StackTrace::Handle(raw_stacktrace); | 
|  4671   } |  4671   } | 
|  4672   Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); |  4672   Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); | 
|  4673   return Api::NewError("Exception was not re thrown, internal error"); |  4673   return Api::NewError("Exception was not re thrown, internal error"); | 
|  4674 } |  4674 } | 
|  4675  |  4675  | 
|  4676  |  4676  | 
|  4677 // --- Native fields and functions --- |  4677 // --- Native fields and functions --- | 
|  4678  |  4678  | 
|  4679 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |  4679 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 
|  4680                                                       Dart_Handle name, |  4680                                                       Dart_Handle name, | 
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  5022  |  5022  | 
|  5023  |  5023  | 
|  5024 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |  5024 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 
|  5025                                      Dart_Handle retval) { |  5025                                      Dart_Handle retval) { | 
|  5026   NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |  5026   NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 
|  5027   ASSERT(arguments->thread()->isolate() == Isolate::Current()); |  5027   ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 
|  5028   if ((retval != Api::Null()) && !Api::IsInstance(retval) && |  5028   if ((retval != Api::Null()) && !Api::IsInstance(retval) && | 
|  5029       !Api::IsError(retval)) { |  5029       !Api::IsError(retval)) { | 
|  5030     // Print the current stack trace to make the problematic caller |  5030     // Print the current stack trace to make the problematic caller | 
|  5031     // easier to find. |  5031     // easier to find. | 
|  5032     const Stacktrace& stacktrace = GetCurrentStacktrace(0); |  5032     const StackTrace& stacktrace = GetCurrentStackTrace(0); | 
|  5033     OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); |  5033     OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); | 
|  5034  |  5034  | 
|  5035     const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |  5035     const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 
|  5036     FATAL1( |  5036     FATAL1( | 
|  5037         "Return value check failed: saw '%s' expected a dart Instance or " |  5037         "Return value check failed: saw '%s' expected a dart Instance or " | 
|  5038         "an Error.", |  5038         "an Error.", | 
|  5039         ret_obj.ToCString()); |  5039         ret_obj.ToCString()); | 
|  5040   } |  5040   } | 
|  5041   ASSERT(retval != 0); |  5041   ASSERT(retval != 0); | 
|  5042   Api::SetReturnValue(arguments, retval); |  5042   Api::SetReturnValue(arguments, retval); | 
| (...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  6711 } |  6711 } | 
|  6712  |  6712  | 
|  6713  |  6713  | 
|  6714 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { |  6714 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { | 
|  6715 #ifndef PRODUCT |  6715 #ifndef PRODUCT | 
|  6716   Profiler::DumpStackTrace(context); |  6716   Profiler::DumpStackTrace(context); | 
|  6717 #endif |  6717 #endif | 
|  6718 } |  6718 } | 
|  6719  |  6719  | 
|  6720 }  // namespace dart |  6720 }  // namespace dart | 
| OLD | NEW |