Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: runtime/lib/mirrors.cc

Issue 20458002: Wrap lazy compilation errors when parsing metadata. Addresses the poor error reporting in issue 120… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 name_handle, 974 name_handle,
975 lib_mirror); 975 lib_mirror);
976 if (Dart_IsError(result)) { 976 if (Dart_IsError(result)) {
977 Dart_PropagateError(result); 977 Dart_PropagateError(result);
978 } 978 }
979 Dart_SetReturnValue(args, result); 979 Dart_SetReturnValue(args, result);
980 Dart_ExitScope(); 980 Dart_ExitScope();
981 } 981 }
982 982
983 983
984 static void ThrowMirroredCompilationError(const String& message) {
985 Array& args = Array::Handle(Array::New(1));
986 args.SetAt(0, message);
987
988 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args);
989 UNREACHABLE();
990 }
991
992
993 static void ThrowInvokeError(const Error& error) {
994 if (error.IsLanguageError()) {
995 // A compilation error that was delayed by lazy compilation.
996 const LanguageError& compilation_error = LanguageError::Cast(error);
997 String& message = String::Handle(compilation_error.message());
998 ThrowMirroredCompilationError(message);
999 UNREACHABLE();
1000 }
1001 Exceptions::PropagateError(error);
1002 UNREACHABLE();
1003 }
1004
1005
984 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { 1006 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
985 const MirrorReference& decl_ref = 1007 const MirrorReference& decl_ref =
986 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1008 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
987 const Object& decl = Object::Handle(decl_ref.referent()); 1009 const Object& decl = Object::Handle(decl_ref.referent());
988 1010
989 Class& klass = Class::Handle(); 1011 Class& klass = Class::Handle();
990 if (decl.IsClass()) { 1012 if (decl.IsClass()) {
991 klass ^= decl.raw(); 1013 klass ^= decl.raw();
992 } else if (decl.IsFunction()) { 1014 } else if (decl.IsFunction()) {
993 klass = Function::Cast(decl).origin(); 1015 klass = Function::Cast(decl).origin();
994 } else if (decl.IsField()) { 1016 } else if (decl.IsField()) {
995 klass = Field::Cast(decl).origin(); 1017 klass = Field::Cast(decl).origin();
996 } else { 1018 } else {
997 return Object::empty_array().raw(); 1019 return Object::empty_array().raw();
998 } 1020 }
999 1021
1000 const Library& library = Library::Handle(klass.library()); 1022 const Library& library = Library::Handle(klass.library());
1001 return library.GetMetadata(decl); 1023 const Object& metadata = Object::Handle(library.GetMetadata(decl));
1024 if (metadata.IsError()) {
1025 ThrowInvokeError(Error::Cast(metadata));
1026 }
1027 return metadata.raw();
1002 } 1028 }
1003 1029
1004 1030
1005 void HandleMirrorsMessage(Isolate* isolate, 1031 void HandleMirrorsMessage(Isolate* isolate,
1006 Dart_Port reply_port, 1032 Dart_Port reply_port,
1007 const Instance& message) { 1033 const Instance& message) {
1008 UNIMPLEMENTED(); 1034 UNIMPLEMENTED();
1009 } 1035 }
1010 1036
1011 1037
1012 static void ThrowMirroredCompilationError(const String& message) {
1013 Array& args = Array::Handle(Array::New(1));
1014 args.SetAt(0, message);
1015
1016 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args);
1017 UNREACHABLE();
1018 }
1019
1020
1021 static void ThrowInvokeError(const Error& error) {
1022 if (error.IsLanguageError()) {
1023 // A compilation error that was delayed by lazy compilation.
1024 const LanguageError& compilation_error = LanguageError::Cast(error);
1025 String& message = String::Handle(compilation_error.message());
1026 ThrowMirroredCompilationError(message);
1027 UNREACHABLE();
1028 }
1029 Exceptions::PropagateError(error);
1030 UNREACHABLE();
1031 }
1032
1033
1034 static bool FieldIsUninitialized(const Field& field) { 1038 static bool FieldIsUninitialized(const Field& field) {
1035 ASSERT(!field.IsNull()); 1039 ASSERT(!field.IsNull());
1036 1040
1037 // Return getter method for uninitialized fields, rather than the 1041 // Return getter method for uninitialized fields, rather than the
1038 // field object, since the value in the field object will not be 1042 // field object, since the value in the field object will not be
1039 // initialized until the first time the getter is invoked. 1043 // initialized until the first time the getter is invoked.
1040 const Instance& value = Instance::Handle(field.value()); 1044 const Instance& value = Instance::Handle(field.value());
1041 ASSERT(value.raw() != Object::transition_sentinel().raw()); 1045 ASSERT(value.raw() != Object::transition_sentinel().raw());
1042 return value.raw() == Object::sentinel().raw(); 1046 return value.raw() == Object::sentinel().raw();
1043 } 1047 }
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 1774
1771 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1775 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1772 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1776 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1773 const Field& field = Field::Handle(ref.GetFieldReferent()); 1777 const Field& field = Field::Handle(ref.GetFieldReferent());
1774 1778
1775 const AbstractType& type = AbstractType::Handle(field.type()); 1779 const AbstractType& type = AbstractType::Handle(field.type());
1776 return CreateTypeMirror(type); 1780 return CreateTypeMirror(type);
1777 } 1781 }
1778 1782
1779 } // namespace dart 1783 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698