| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_debugger_api.h" | 6 #include "include/dart_debugger_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. | 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. |
| 10 #include "vm/bootstrap_natives.h" | 10 #include "vm/bootstrap_natives.h" |
| (...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 | 1004 |
| 1005 void HandleMirrorsMessage(Isolate* isolate, | 1005 void HandleMirrorsMessage(Isolate* isolate, |
| 1006 Dart_Port reply_port, | 1006 Dart_Port reply_port, |
| 1007 const Instance& message) { | 1007 const Instance& message) { |
| 1008 UNIMPLEMENTED(); | 1008 UNIMPLEMENTED(); |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 | 1011 |
| 1012 // TODO(11742): This is transitional. | |
| 1013 static RawInstance* Reflect(const Instance& reflectee) { | |
| 1014 Isolate* isolate = Isolate::Current(); | |
| 1015 DARTSCOPE(isolate); | |
| 1016 return Instance::RawCast( | |
| 1017 Api::UnwrapHandle( | |
| 1018 CreateInstanceMirror( | |
| 1019 Api::NewHandle(isolate, reflectee.raw())))); | |
| 1020 } | |
| 1021 | |
| 1022 | |
| 1023 static void ThrowMirroredUnhandledError(const Error& original_error) { | |
| 1024 const UnhandledException& unhandled_ex = | |
| 1025 UnhandledException::Cast(original_error); | |
| 1026 Instance& exc = Instance::Handle(unhandled_ex.exception()); | |
| 1027 Instance& stack = Instance::Handle(unhandled_ex.stacktrace()); | |
| 1028 | |
| 1029 Object& exc_string_or_error = | |
| 1030 Object::Handle(DartLibraryCalls::ToString(exc)); | |
| 1031 String& exc_string = String::Handle(); | |
| 1032 // Ignore any errors that might occur in toString. | |
| 1033 if (exc_string_or_error.IsString()) { | |
| 1034 exc_string ^= exc_string_or_error.raw(); | |
| 1035 } | |
| 1036 | |
| 1037 Instance& mirror_on_exc = Instance::Handle(Reflect(exc)); | |
| 1038 | |
| 1039 Array& args = Array::Handle(Array::New(3)); | |
| 1040 args.SetAt(0, mirror_on_exc); | |
| 1041 args.SetAt(1, exc_string); | |
| 1042 args.SetAt(2, stack); | |
| 1043 | |
| 1044 Exceptions::ThrowByType(Exceptions::kMirroredUncaughtExceptionError, args); | |
| 1045 UNREACHABLE(); | |
| 1046 } | |
| 1047 | |
| 1048 | |
| 1049 static void ThrowMirroredCompilationError(const String& message) { | 1012 static void ThrowMirroredCompilationError(const String& message) { |
| 1050 Array& args = Array::Handle(Array::New(1)); | 1013 Array& args = Array::Handle(Array::New(1)); |
| 1051 args.SetAt(0, message); | 1014 args.SetAt(0, message); |
| 1052 | 1015 |
| 1053 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); | 1016 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
| 1054 UNREACHABLE(); | 1017 UNREACHABLE(); |
| 1055 } | 1018 } |
| 1056 | 1019 |
| 1057 | 1020 |
| 1058 static void ThrowInvokeError(const Error& error) { | 1021 static void ThrowInvokeError(const Error& error) { |
| 1059 if (error.IsUnhandledException()) { | |
| 1060 // An ordinary runtime error. | |
| 1061 ThrowMirroredUnhandledError(error); | |
| 1062 } | |
| 1063 if (error.IsLanguageError()) { | 1022 if (error.IsLanguageError()) { |
| 1064 // A compilation error that was delayed by lazy compilation. | 1023 // A compilation error that was delayed by lazy compilation. |
| 1065 const LanguageError& compilation_error = LanguageError::Cast(error); | 1024 const LanguageError& compilation_error = LanguageError::Cast(error); |
| 1066 String& message = String::Handle(compilation_error.message()); | 1025 String& message = String::Handle(compilation_error.message()); |
| 1067 ThrowMirroredCompilationError(message); | 1026 ThrowMirroredCompilationError(message); |
| 1027 UNREACHABLE(); |
| 1068 } | 1028 } |
| 1029 Exceptions::PropagateError(error); |
| 1069 UNREACHABLE(); | 1030 UNREACHABLE(); |
| 1070 } | 1031 } |
| 1071 | 1032 |
| 1072 | 1033 |
| 1073 static bool FieldIsUninitialized(const Field& field) { | 1034 static bool FieldIsUninitialized(const Field& field) { |
| 1074 ASSERT(!field.IsNull()); | 1035 ASSERT(!field.IsNull()); |
| 1075 | 1036 |
| 1076 // Return getter method for uninitialized fields, rather than the | 1037 // Return getter method for uninitialized fields, rather than the |
| 1077 // field object, since the value in the field object will not be | 1038 // field object, since the value in the field object will not be |
| 1078 // initialized until the first time the getter is invoked. | 1039 // initialized until the first time the getter is invoked. |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1809 | 1770 |
| 1810 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1771 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1811 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1772 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1812 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1773 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1813 | 1774 |
| 1814 const AbstractType& type = AbstractType::Handle(field.type()); | 1775 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1815 return CreateTypeMirror(type); | 1776 return CreateTypeMirror(type); |
| 1816 } | 1777 } |
| 1817 | 1778 |
| 1818 } // namespace dart | 1779 } // namespace dart |
| OLD | NEW |