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

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

Issue 24631003: Add proper API for creating private symbols wrt a library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: amend tests Created 7 years, 2 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
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/vm/object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
227 args.SetAt(1, type); 227 args.SetAt(1, type);
228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); 228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args);
229 } 229 }
230 230
231 231
232 static RawInstance* CreateMethodMirror(const Function& func, 232 static RawInstance* CreateMethodMirror(const Function& func,
233 const Instance& owner_mirror) { 233 const Instance& owner_mirror) {
234 const Array& args = Array::Handle(Array::New(12)); 234 const Array& args = Array::Handle(Array::New(12));
235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
236 args.SetAt(1, String::Handle(func.UserVisibleName())); 236
237 String& name = String::Handle(func.name());
238 name = String::StripAccessorPrefix(name); // But not the private mangling!
239 args.SetAt(1, name);
240
237 args.SetAt(2, owner_mirror); 241 args.SetAt(2, owner_mirror);
238 args.SetAt(3, Bool::Get(func.is_static())); 242 args.SetAt(3, Bool::Get(func.is_static()));
239 args.SetAt(4, Bool::Get(func.is_abstract())); 243 args.SetAt(4, Bool::Get(func.is_abstract()));
240 args.SetAt(5, Bool::Get(func.IsGetterFunction())); 244 args.SetAt(5, Bool::Get(func.IsGetterFunction()));
241 args.SetAt(6, Bool::Get(func.IsSetterFunction())); 245 args.SetAt(6, Bool::Get(func.IsSetterFunction()));
242 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor)); 246 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor));
243 // TODO(mlippautz): Implement different constructor kinds. 247 // TODO(mlippautz): Implement different constructor kinds.
244 args.SetAt(8, Bool::False()); 248 args.SetAt(8, Bool::False());
245 args.SetAt(9, Bool::False()); 249 args.SetAt(9, Bool::False());
246 args.SetAt(10, Bool::False()); 250 args.SetAt(10, Bool::False());
247 args.SetAt(11, Bool::False()); 251 args.SetAt(11, Bool::False());
248 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); 252 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args);
249 } 253 }
250 254
251 255
252 static RawInstance* CreateVariableMirror(const Field& field, 256 static RawInstance* CreateVariableMirror(const Field& field,
253 const Instance& owner_mirror) { 257 const Instance& owner_mirror) {
254 const MirrorReference& field_ref = 258 const MirrorReference& field_ref =
255 MirrorReference::Handle(MirrorReference::New(field)); 259 MirrorReference::Handle(MirrorReference::New(field));
256 260
257 const String& name = String::Handle(field.UserVisibleName()); 261 const String& name = String::Handle(field.name());
258 262
259 const Array& args = Array::Handle(Array::New(6)); 263 const Array& args = Array::Handle(Array::New(6));
260 args.SetAt(0, field_ref); 264 args.SetAt(0, field_ref);
261 args.SetAt(1, name); 265 args.SetAt(1, name);
262 args.SetAt(2, owner_mirror); 266 args.SetAt(2, owner_mirror);
263 args.SetAt(3, Object::null_instance()); // Null for type. 267 args.SetAt(3, Object::null_instance()); // Null for type.
264 args.SetAt(4, Bool::Get(field.is_static())); 268 args.SetAt(4, Bool::Get(field.is_static()));
265 args.SetAt(5, Bool::Get(field.is_final())); 269 args.SetAt(5, Bool::Get(field.is_final()));
266 270
267 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); 271 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); 309 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0);
306 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); 310 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef());
307 311
308 const Array& args = Array::Handle(Array::New(6)); 312 const Array& args = Array::Handle(Array::New(6));
309 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 313 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
310 args.SetAt(1, type); 314 args.SetAt(1, type);
311 // We do not set the names of anonymous mixin applications because the mirrors 315 // We do not set the names of anonymous mixin applications because the mirrors
312 // use a different naming convention than the VM (lib.S with lib.M and S&M 316 // use a different naming convention than the VM (lib.S with lib.M and S&M
313 // respectively). 317 // respectively).
314 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { 318 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) {
315 args.SetAt(2, String::Handle(cls.UserVisibleName())); 319 args.SetAt(2, String::Handle(cls.Name()));
316 } 320 }
317 args.SetAt(3, is_generic); 321 args.SetAt(3, is_generic);
318 args.SetAt(4, is_mixin_typedef); 322 args.SetAt(4, is_mixin_typedef);
319 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); 323 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
320 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); 324 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args);
321 } 325 }
322 326
323 327
324 static RawInstance* CreateLibraryMirror(const Library& lib) { 328 static RawInstance* CreateLibraryMirror(const Library& lib) {
325 const Array& args = Array::Handle(Array::New(3)); 329 const Array& args = Array::Handle(Array::New(3));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 Bool::True(), // is_declaration 424 Bool::True(), // is_declaration
421 Object::null_instance()); 425 Object::null_instance());
422 } 426 }
423 427
424 428
425 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { 429 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) {
426 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 430 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
427 return CreateTypeMirror(type); 431 return CreateTypeMirror(type);
428 } 432 }
429 433
434 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) {
435 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
436 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
437 const Library& lib = Library::Handle(ref.GetLibraryReferent());
438 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw();
439 }
440
441 DEFINE_NATIVE_ENTRY(Mirrors_unmangleName, 1) {
442 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
443 // It would be nice to unconditionally use IdentifierPrettyName, alas it
444 // cannot cope with the symbols for the names of anonymous mixin applications.
445 if (Library::IsPrivate(name) ||
446 Field::IsGetterName(name) ||
447 Field::IsSetterName(name)) {
448 return String::IdentifierPrettyName(name);
449 }
450 return name.raw();
451 }
452
430 453
431 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { 454 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) {
432 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); 455 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0));
433 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); 456 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1));
434 return Bool::Get(a.referent() == b.referent()).raw(); 457 return Bool::Get(a.referent() == b.referent()).raw();
435 } 458 }
436 459
437 460
438 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { 461 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
439 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); 462 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0));
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 // because this native is an instance method in order to be polymorphic 819 // because this native is an instance method in order to be polymorphic
797 // with its cousins. 820 // with its cousins.
798 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 821 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
799 GET_NON_NULL_NATIVE_ARGUMENT( 822 GET_NON_NULL_NATIVE_ARGUMENT(
800 String, function_name, arguments->NativeArgAt(2)); 823 String, function_name, arguments->NativeArgAt(2));
801 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 824 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
802 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 825 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
803 826
804 Class& klass = Class::Handle(reflectee.clazz()); 827 Class& klass = Class::Handle(reflectee.clazz());
805 Function& function = Function::Handle( 828 Function& function = Function::Handle(
806 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, function_name)); 829 Resolver::ResolveDynamicAnyArgs(klass, function_name));
807 830
808 const Array& args_descriptor = 831 const Array& args_descriptor =
809 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 832 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
810 833
811 return ReflectivelyInvokeDynamicFunction(reflectee, 834 return ReflectivelyInvokeDynamicFunction(reflectee,
812 function, 835 function,
813 function_name, 836 function_name,
814 args, 837 args,
815 args_descriptor); 838 args_descriptor);
816 } 839 }
817 840
818 841
819 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { 842 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) {
820 // Argument 0 is the mirror, which is unused by the native. It exists 843 // Argument 0 is the mirror, which is unused by the native. It exists
821 // because this native is an instance method in order to be polymorphic 844 // because this native is an instance method in order to be polymorphic
822 // with its cousins. 845 // with its cousins.
823 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 846 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
824 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); 847 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
825 848
826 Class& klass = Class::Handle(reflectee.clazz()); 849 Class& klass = Class::Handle(reflectee.clazz());
827 String& internal_getter_name = String::Handle(Field::GetterName(getter_name)); 850 String& internal_getter_name = String::Handle(Field::GetterName(getter_name));
828 Function& function = Function::Handle( 851 Function& function = Function::Handle(
829 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, internal_getter_name)); 852 Resolver::ResolveDynamicAnyArgs(klass, internal_getter_name));
830 853
831 const int kNumArgs = 1; 854 const int kNumArgs = 1;
832 const Array& args = Array::Handle(Array::New(kNumArgs)); 855 const Array& args = Array::Handle(Array::New(kNumArgs));
833 args.SetAt(0, reflectee); 856 args.SetAt(0, reflectee);
834 const Array& args_descriptor = 857 const Array& args_descriptor =
835 Array::Handle(ArgumentsDescriptor::New(args.Length())); 858 Array::Handle(ArgumentsDescriptor::New(args.Length()));
836 859
837 return ReflectivelyInvokeDynamicFunction(reflectee, 860 return ReflectivelyInvokeDynamicFunction(reflectee,
838 function, 861 function,
839 internal_getter_name, 862 internal_getter_name,
(...skipping 20 matching lines...) Expand all
860 while (!klass.IsNull()) { 883 while (!klass.IsNull()) {
861 field = klass.LookupInstanceField(setter_name); 884 field = klass.LookupInstanceField(setter_name);
862 if (!field.IsNull() && field.is_final()) { 885 if (!field.IsNull() && field.is_final()) {
863 const String& message = String::Handle( 886 const String& message = String::Handle(
864 String::NewFormatted("%s: cannot set final field '%s'.", 887 String::NewFormatted("%s: cannot set final field '%s'.",
865 "InstanceMirror_invokeSetter", 888 "InstanceMirror_invokeSetter",
866 setter_name.ToCString())); 889 setter_name.ToCString()));
867 ThrowMirroredCompilationError(message); 890 ThrowMirroredCompilationError(message);
868 UNREACHABLE(); 891 UNREACHABLE();
869 } 892 }
870 setter = klass.LookupDynamicFunctionAllowPrivate(internal_setter_name); 893 setter = klass.LookupDynamicFunction(internal_setter_name);
871 if (!setter.IsNull()) { 894 if (!setter.IsNull()) {
872 break; 895 break;
873 } 896 }
874 klass = klass.SuperClass(); 897 klass = klass.SuperClass();
875 } 898 }
876 899
877 // Invoke the setter and return the result. 900 // Invoke the setter and return the result.
878 const int kNumArgs = 2; 901 const int kNumArgs = 2;
879 const Array& args = Array::Handle(Array::New(kNumArgs)); 902 const Array& args = Array::Handle(Array::New(kNumArgs));
880 args.SetAt(0, reflectee); 903 args.SetAt(0, reflectee);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 const Class& klass = Class::Handle(ref.GetClassReferent()); 952 const Class& klass = Class::Handle(ref.GetClassReferent());
930 GET_NON_NULL_NATIVE_ARGUMENT( 953 GET_NON_NULL_NATIVE_ARGUMENT(
931 String, function_name, arguments->NativeArgAt(2)); 954 String, function_name, arguments->NativeArgAt(2));
932 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 955 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
933 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 956 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
934 957
935 const Array& args_descriptor_array = 958 const Array& args_descriptor_array =
936 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 959 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
937 960
938 const Function& function = Function::Handle( 961 const Function& function = Function::Handle(
939 klass.LookupStaticFunctionAllowPrivate(function_name)); 962 klass.LookupStaticFunction(function_name));
940
941 963
942 ArgumentsDescriptor args_descriptor(args_descriptor_array); 964 ArgumentsDescriptor args_descriptor(args_descriptor_array);
943 if (function.IsNull() || 965 if (function.IsNull() ||
944 !function.AreValidArguments(args_descriptor, NULL) || 966 !function.AreValidArguments(args_descriptor, NULL) ||
945 !function.is_visible()) { 967 !function.is_visible()) {
946 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 968 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
947 function_name, 969 function_name,
948 function, 970 function,
949 InvocationMirror::kStatic, 971 InvocationMirror::kStatic,
950 InvocationMirror::kMethod); 972 InvocationMirror::kMethod);
(...skipping 17 matching lines...) Expand all
968 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 990 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
969 const Class& klass = Class::Handle(ref.GetClassReferent()); 991 const Class& klass = Class::Handle(ref.GetClassReferent());
970 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); 992 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
971 993
972 // Note static fields do not have implicit getters. 994 // Note static fields do not have implicit getters.
973 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); 995 const Field& field = Field::Handle(klass.LookupStaticField(getter_name));
974 if (field.IsNull() || FieldIsUninitialized(field)) { 996 if (field.IsNull() || FieldIsUninitialized(field)) {
975 const String& internal_getter_name = String::Handle( 997 const String& internal_getter_name = String::Handle(
976 Field::GetterName(getter_name)); 998 Field::GetterName(getter_name));
977 Function& getter = Function::Handle( 999 Function& getter = Function::Handle(
978 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); 1000 klass.LookupStaticFunction(internal_getter_name));
979 1001
980 if (getter.IsNull() || !getter.is_visible()) { 1002 if (getter.IsNull() || !getter.is_visible()) {
981 if (getter.IsNull()) { 1003 if (getter.IsNull()) {
982 getter = klass.LookupStaticFunctionAllowPrivate(getter_name); 1004 getter = klass.LookupStaticFunction(getter_name);
983 if (!getter.IsNull()) { 1005 if (!getter.IsNull()) {
984 // Looking for a getter but found a regular method: closurize. 1006 // Looking for a getter but found a regular method: closurize.
985 const Function& closure_function = 1007 const Function& closure_function =
986 Function::Handle(getter.ImplicitClosureFunction()); 1008 Function::Handle(getter.ImplicitClosureFunction());
987 return closure_function.ImplicitStaticClosure(); 1009 return closure_function.ImplicitStaticClosure();
988 } 1010 }
989 } 1011 }
990 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1012 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
991 getter_name, 1013 getter_name,
992 getter, 1014 getter,
(...skipping 23 matching lines...) Expand all
1016 const Class& klass = Class::Handle(ref.GetClassReferent()); 1038 const Class& klass = Class::Handle(ref.GetClassReferent());
1017 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1039 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1018 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1040 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1019 1041
1020 // Check for real fields and user-defined setters. 1042 // Check for real fields and user-defined setters.
1021 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); 1043 const Field& field = Field::Handle(klass.LookupStaticField(setter_name));
1022 if (field.IsNull()) { 1044 if (field.IsNull()) {
1023 const String& internal_setter_name = String::Handle( 1045 const String& internal_setter_name = String::Handle(
1024 Field::SetterName(setter_name)); 1046 Field::SetterName(setter_name));
1025 const Function& setter = Function::Handle( 1047 const Function& setter = Function::Handle(
1026 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); 1048 klass.LookupStaticFunction(internal_setter_name));
1027 1049
1028 if (setter.IsNull() || !setter.is_visible()) { 1050 if (setter.IsNull() || !setter.is_visible()) {
1029 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1051 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1030 setter_name, 1052 setter_name,
1031 setter, 1053 setter,
1032 InvocationMirror::kStatic, 1054 InvocationMirror::kStatic,
1033 InvocationMirror::kSetter); 1055 InvocationMirror::kSetter);
1034 UNREACHABLE(); 1056 UNREACHABLE();
1035 } 1057 }
1036 1058
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 // This convention prevents users from explicitly calling constructors. 1099 // This convention prevents users from explicitly calling constructors.
1078 const String& klass_name = String::Handle(klass.Name()); 1100 const String& klass_name = String::Handle(klass.Name());
1079 String& internal_constructor_name = 1101 String& internal_constructor_name =
1080 String::Handle(String::Concat(klass_name, Symbols::Dot())); 1102 String::Handle(String::Concat(klass_name, Symbols::Dot()));
1081 if (!constructor_name.IsNull()) { 1103 if (!constructor_name.IsNull()) {
1082 internal_constructor_name = 1104 internal_constructor_name =
1083 String::Concat(internal_constructor_name, constructor_name); 1105 String::Concat(internal_constructor_name, constructor_name);
1084 } 1106 }
1085 1107
1086 Function& lookup_constructor = Function::Handle( 1108 Function& lookup_constructor = Function::Handle(
1087 klass.LookupFunctionAllowPrivate(internal_constructor_name)); 1109 klass.LookupFunction(internal_constructor_name));
1088 1110
1089 if (lookup_constructor.IsNull() || 1111 if (lookup_constructor.IsNull() ||
1090 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || 1112 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) ||
1091 !lookup_constructor.is_visible()) { 1113 !lookup_constructor.is_visible()) {
1092 // Pretend we didn't find the constructor at all when the arity is wrong 1114 // Pretend we didn't find the constructor at all when the arity is wrong
1093 // so as to produce the same NoSuchMethodError as the non-reflective case. 1115 // so as to produce the same NoSuchMethodError as the non-reflective case.
1094 lookup_constructor = Function::null(); 1116 lookup_constructor = Function::null();
1095 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1117 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1096 internal_constructor_name, 1118 internal_constructor_name,
1097 lookup_constructor, 1119 lookup_constructor,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1215 const Library& library = Library::Handle(ref.GetLibraryReferent());
1194 GET_NON_NULL_NATIVE_ARGUMENT( 1216 GET_NON_NULL_NATIVE_ARGUMENT(
1195 String, function_name, arguments->NativeArgAt(2)); 1217 String, function_name, arguments->NativeArgAt(2));
1196 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1218 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1197 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1219 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1198 1220
1199 const Array& args_descriptor_array = 1221 const Array& args_descriptor_array =
1200 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1222 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1201 1223
1202 const Function& function = Function::Handle( 1224 const Function& function = Function::Handle(
1203 library.LookupFunctionAllowPrivate(function_name)); 1225 library.LookupLocalFunction(function_name));
1204 1226
1205 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1227 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1206 if (function.IsNull() || 1228 if (function.IsNull() ||
1207 !function.AreValidArguments(args_descriptor, NULL) || 1229 !function.AreValidArguments(args_descriptor, NULL) ||
1208 !function.is_visible()) { 1230 !function.is_visible()) {
1209 ThrowNoSuchMethod(Instance::null_instance(), 1231 ThrowNoSuchMethod(Instance::null_instance(),
1210 function_name, 1232 function_name,
1211 function, 1233 function,
1212 InvocationMirror::kTopLevel, 1234 InvocationMirror::kTopLevel,
1213 InvocationMirror::kMethod); 1235 InvocationMirror::kMethod);
(...skipping 15 matching lines...) Expand all
1229 // because this native is an instance method in order to be polymorphic 1251 // because this native is an instance method in order to be polymorphic
1230 // with its cousins. 1252 // with its cousins.
1231 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1253 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1232 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1254 const Library& library = Library::Handle(ref.GetLibraryReferent());
1233 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); 1255 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2));
1234 1256
1235 // To access a top-level we may need to use the Field or the 1257 // To access a top-level we may need to use the Field or the
1236 // getter Function. The getter function may either be in the 1258 // getter Function. The getter function may either be in the
1237 // library or in the field's owner class, depending. 1259 // library or in the field's owner class, depending.
1238 const Field& field = Field::Handle( 1260 const Field& field = Field::Handle(
1239 library.LookupFieldAllowPrivate(getter_name)); 1261 library.LookupLocalField(getter_name));
1240 Function& getter = Function::Handle(); 1262 Function& getter = Function::Handle();
1241 if (field.IsNull()) { 1263 if (field.IsNull()) {
1242 // No field found and no ambiguity error. Check for a getter in the lib. 1264 // No field found and no ambiguity error. Check for a getter in the lib.
1243 const String& internal_getter_name = 1265 const String& internal_getter_name =
1244 String::Handle(Field::GetterName(getter_name)); 1266 String::Handle(Field::GetterName(getter_name));
1245 getter = library.LookupFunctionAllowPrivate(internal_getter_name); 1267 getter = library.LookupLocalFunction(internal_getter_name);
1246 if (getter.IsNull()) { 1268 if (getter.IsNull()) {
1247 getter = library.LookupFunctionAllowPrivate(getter_name); 1269 getter = library.LookupLocalFunction(getter_name);
1248 if (!getter.IsNull()) { 1270 if (!getter.IsNull()) {
1249 // Looking for a getter but found a regular method: closurize. 1271 // Looking for a getter but found a regular method: closurize.
1250 const Function& closure_function = 1272 const Function& closure_function =
1251 Function::Handle(getter.ImplicitClosureFunction()); 1273 Function::Handle(getter.ImplicitClosureFunction());
1252 return closure_function.ImplicitStaticClosure(); 1274 return closure_function.ImplicitStaticClosure();
1253 } 1275 }
1254 } 1276 }
1255 } else if (!field.IsNull() && FieldIsUninitialized(field)) { 1277 } else if (!field.IsNull() && FieldIsUninitialized(field)) {
1256 // A field was found. Check for a getter in the field's owner classs. 1278 // A field was found. Check for a getter in the field's owner classs.
1257 const Class& klass = Class::Handle(field.owner()); 1279 const Class& klass = Class::Handle(field.owner());
1258 const String& internal_getter_name = 1280 const String& internal_getter_name =
1259 String::Handle(Field::GetterName(getter_name)); 1281 String::Handle(Field::GetterName(getter_name));
1260 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); 1282 getter = klass.LookupStaticFunction(internal_getter_name);
1261 } 1283 }
1262 1284
1263 if (!getter.IsNull() && getter.is_visible()) { 1285 if (!getter.IsNull() && getter.is_visible()) {
1264 // Invoke the getter and return the result. 1286 // Invoke the getter and return the result.
1265 const Object& result = Object::Handle( 1287 const Object& result = Object::Handle(
1266 DartEntry::InvokeFunction(getter, Object::empty_array())); 1288 DartEntry::InvokeFunction(getter, Object::empty_array()));
1267 if (result.IsError()) { 1289 if (result.IsError()) {
1268 ThrowInvokeError(Error::Cast(result)); 1290 ThrowInvokeError(Error::Cast(result));
1269 UNREACHABLE(); 1291 UNREACHABLE();
1270 } 1292 }
(...skipping 18 matching lines...) Expand all
1289 // with its cousins. 1311 // with its cousins.
1290 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1312 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1291 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1313 const Library& library = Library::Handle(ref.GetLibraryReferent());
1292 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1314 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1293 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1315 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1294 1316
1295 // To access a top-level we may need to use the Field or the 1317 // To access a top-level we may need to use the Field or the
1296 // setter Function. The setter function may either be in the 1318 // setter Function. The setter function may either be in the
1297 // library or in the field's owner class, depending. 1319 // library or in the field's owner class, depending.
1298 const Field& field = Field::Handle( 1320 const Field& field = Field::Handle(
1299 library.LookupFieldAllowPrivate(setter_name)); 1321 library.LookupLocalField(setter_name));
1300 1322
1301 if (field.IsNull()) { 1323 if (field.IsNull()) {
1302 const String& internal_setter_name = 1324 const String& internal_setter_name =
1303 String::Handle(Field::SetterName(setter_name)); 1325 String::Handle(Field::SetterName(setter_name));
1304 const Function& setter = Function::Handle( 1326 const Function& setter = Function::Handle(
1305 library.LookupFunctionAllowPrivate(internal_setter_name)); 1327 library.LookupLocalFunction(internal_setter_name));
1306 if (setter.IsNull() || !setter.is_visible()) { 1328 if (setter.IsNull() || !setter.is_visible()) {
1307 ThrowNoSuchMethod(Instance::null_instance(), 1329 ThrowNoSuchMethod(Instance::null_instance(),
1308 setter_name, 1330 setter_name,
1309 setter, 1331 setter,
1310 InvocationMirror::kTopLevel, 1332 InvocationMirror::kTopLevel,
1311 InvocationMirror::kSetter); 1333 InvocationMirror::kSetter);
1312 UNREACHABLE(); 1334 UNREACHABLE();
1313 } 1335 }
1314 1336
1315 // Invoke the setter and return the result. 1337 // Invoke the setter and return the result.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 } 1441 }
1420 1442
1421 1443
1422 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1444 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1423 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1445 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1424 const Field& field = Field::Handle(ref.GetFieldReferent()); 1446 const Field& field = Field::Handle(ref.GetFieldReferent());
1425 return field.type(); 1447 return field.type();
1426 } 1448 }
1427 1449
1428 } // namespace dart 1450 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698