| 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 "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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 Bool::True(), // is_declaration | 420 Bool::True(), // is_declaration |
| 421 Object::null_instance()); | 421 Object::null_instance()); |
| 422 } | 422 } |
| 423 | 423 |
| 424 | 424 |
| 425 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 425 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
| 426 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 426 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 427 return CreateTypeMirror(type); | 427 return CreateTypeMirror(type); |
| 428 } | 428 } |
| 429 | 429 |
| 430 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) { |
| 431 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 432 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 433 const Library& lib = Library::Handle(ref.GetLibraryReferent()); |
| 434 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw(); |
| 435 } |
| 436 |
| 437 DEFINE_NATIVE_ENTRY(Mirrors_unmangleName, 1) { |
| 438 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); |
| 439 return Library::IsPrivate(name) ? |
| 440 String::IdentifierPrettyName(name) : name.raw(); |
| 441 } |
| 442 |
| 430 | 443 |
| 431 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 444 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
| 432 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 445 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
| 433 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 446 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
| 434 return Bool::Get(a.referent() == b.referent()).raw(); | 447 return Bool::Get(a.referent() == b.referent()).raw(); |
| 435 } | 448 } |
| 436 | 449 |
| 437 | 450 |
| 438 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 451 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
| 439 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); | 452 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // because this native is an instance method in order to be polymorphic | 809 // because this native is an instance method in order to be polymorphic |
| 797 // with its cousins. | 810 // with its cousins. |
| 798 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 811 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 799 GET_NON_NULL_NATIVE_ARGUMENT( | 812 GET_NON_NULL_NATIVE_ARGUMENT( |
| 800 String, function_name, arguments->NativeArgAt(2)); | 813 String, function_name, arguments->NativeArgAt(2)); |
| 801 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 814 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 802 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 815 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 803 | 816 |
| 804 Class& klass = Class::Handle(reflectee.clazz()); | 817 Class& klass = Class::Handle(reflectee.clazz()); |
| 805 Function& function = Function::Handle( | 818 Function& function = Function::Handle( |
| 806 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, function_name)); | 819 Resolver::ResolveDynamicAnyArgs(klass, function_name)); |
| 807 | 820 |
| 808 const Array& args_descriptor = | 821 const Array& args_descriptor = |
| 809 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 822 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 810 | 823 |
| 811 return ReflectivelyInvokeDynamicFunction(reflectee, | 824 return ReflectivelyInvokeDynamicFunction(reflectee, |
| 812 function, | 825 function, |
| 813 function_name, | 826 function_name, |
| 814 args, | 827 args, |
| 815 args_descriptor); | 828 args_descriptor); |
| 816 } | 829 } |
| 817 | 830 |
| 818 | 831 |
| 819 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { | 832 DEFINE_NATIVE_ENTRY(InstanceMirror_invokeGetter, 3) { |
| 820 // Argument 0 is the mirror, which is unused by the native. It exists | 833 // 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 | 834 // because this native is an instance method in order to be polymorphic |
| 822 // with its cousins. | 835 // with its cousins. |
| 823 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); | 836 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); |
| 824 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 837 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 825 | 838 |
| 826 Class& klass = Class::Handle(reflectee.clazz()); | 839 Class& klass = Class::Handle(reflectee.clazz()); |
| 827 String& internal_getter_name = String::Handle(Field::GetterName(getter_name)); | 840 String& internal_getter_name = String::Handle(Field::GetterName(getter_name)); |
| 828 Function& function = Function::Handle( | 841 Function& function = Function::Handle( |
| 829 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, internal_getter_name)); | 842 Resolver::ResolveDynamicAnyArgs(klass, internal_getter_name)); |
| 830 | 843 |
| 831 const int kNumArgs = 1; | 844 const int kNumArgs = 1; |
| 832 const Array& args = Array::Handle(Array::New(kNumArgs)); | 845 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 833 args.SetAt(0, reflectee); | 846 args.SetAt(0, reflectee); |
| 834 const Array& args_descriptor = | 847 const Array& args_descriptor = |
| 835 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 848 Array::Handle(ArgumentsDescriptor::New(args.Length())); |
| 836 | 849 |
| 837 return ReflectivelyInvokeDynamicFunction(reflectee, | 850 return ReflectivelyInvokeDynamicFunction(reflectee, |
| 838 function, | 851 function, |
| 839 internal_getter_name, | 852 internal_getter_name, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 860 while (!klass.IsNull()) { | 873 while (!klass.IsNull()) { |
| 861 field = klass.LookupInstanceField(setter_name); | 874 field = klass.LookupInstanceField(setter_name); |
| 862 if (!field.IsNull() && field.is_final()) { | 875 if (!field.IsNull() && field.is_final()) { |
| 863 const String& message = String::Handle( | 876 const String& message = String::Handle( |
| 864 String::NewFormatted("%s: cannot set final field '%s'.", | 877 String::NewFormatted("%s: cannot set final field '%s'.", |
| 865 "InstanceMirror_invokeSetter", | 878 "InstanceMirror_invokeSetter", |
| 866 setter_name.ToCString())); | 879 setter_name.ToCString())); |
| 867 ThrowMirroredCompilationError(message); | 880 ThrowMirroredCompilationError(message); |
| 868 UNREACHABLE(); | 881 UNREACHABLE(); |
| 869 } | 882 } |
| 870 setter = klass.LookupDynamicFunctionAllowPrivate(internal_setter_name); | 883 setter = klass.LookupDynamicFunction(internal_setter_name); |
| 871 if (!setter.IsNull()) { | 884 if (!setter.IsNull()) { |
| 872 break; | 885 break; |
| 873 } | 886 } |
| 874 klass = klass.SuperClass(); | 887 klass = klass.SuperClass(); |
| 875 } | 888 } |
| 876 | 889 |
| 877 // Invoke the setter and return the result. | 890 // Invoke the setter and return the result. |
| 878 const int kNumArgs = 2; | 891 const int kNumArgs = 2; |
| 879 const Array& args = Array::Handle(Array::New(kNumArgs)); | 892 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 880 args.SetAt(0, reflectee); | 893 args.SetAt(0, reflectee); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 const Class& klass = Class::Handle(ref.GetClassReferent()); | 942 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 930 GET_NON_NULL_NATIVE_ARGUMENT( | 943 GET_NON_NULL_NATIVE_ARGUMENT( |
| 931 String, function_name, arguments->NativeArgAt(2)); | 944 String, function_name, arguments->NativeArgAt(2)); |
| 932 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 945 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 933 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 946 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 934 | 947 |
| 935 const Array& args_descriptor_array = | 948 const Array& args_descriptor_array = |
| 936 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 949 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 937 | 950 |
| 938 const Function& function = Function::Handle( | 951 const Function& function = Function::Handle( |
| 939 klass.LookupStaticFunctionAllowPrivate(function_name)); | 952 klass.LookupStaticFunction(function_name)); |
| 940 | |
| 941 | 953 |
| 942 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 954 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
| 943 if (function.IsNull() || | 955 if (function.IsNull() || |
| 944 !function.AreValidArguments(args_descriptor, NULL) || | 956 !function.AreValidArguments(args_descriptor, NULL) || |
| 945 !function.is_visible()) { | 957 !function.is_visible()) { |
| 946 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 958 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 947 function_name, | 959 function_name, |
| 948 function, | 960 function, |
| 949 InvocationMirror::kStatic, | 961 InvocationMirror::kStatic, |
| 950 InvocationMirror::kMethod); | 962 InvocationMirror::kMethod); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 968 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 980 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 969 const Class& klass = Class::Handle(ref.GetClassReferent()); | 981 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 970 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 982 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 971 | 983 |
| 972 // Note static fields do not have implicit getters. | 984 // Note static fields do not have implicit getters. |
| 973 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 985 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 974 if (field.IsNull() || FieldIsUninitialized(field)) { | 986 if (field.IsNull() || FieldIsUninitialized(field)) { |
| 975 const String& internal_getter_name = String::Handle( | 987 const String& internal_getter_name = String::Handle( |
| 976 Field::GetterName(getter_name)); | 988 Field::GetterName(getter_name)); |
| 977 Function& getter = Function::Handle( | 989 Function& getter = Function::Handle( |
| 978 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 990 klass.LookupStaticFunction(internal_getter_name)); |
| 979 | 991 |
| 980 if (getter.IsNull() || !getter.is_visible()) { | 992 if (getter.IsNull() || !getter.is_visible()) { |
| 981 if (getter.IsNull()) { | 993 if (getter.IsNull()) { |
| 982 getter = klass.LookupStaticFunctionAllowPrivate(getter_name); | 994 getter = klass.LookupStaticFunction(getter_name); |
| 983 if (!getter.IsNull()) { | 995 if (!getter.IsNull()) { |
| 984 // Looking for a getter but found a regular method: closurize. | 996 // Looking for a getter but found a regular method: closurize. |
| 985 const Function& closure_function = | 997 const Function& closure_function = |
| 986 Function::Handle(getter.ImplicitClosureFunction()); | 998 Function::Handle(getter.ImplicitClosureFunction()); |
| 987 return closure_function.ImplicitStaticClosure(); | 999 return closure_function.ImplicitStaticClosure(); |
| 988 } | 1000 } |
| 989 } | 1001 } |
| 990 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1002 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 991 getter_name, | 1003 getter_name, |
| 992 getter, | 1004 getter, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1016 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1028 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 1017 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1029 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1018 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1030 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1019 | 1031 |
| 1020 // Check for real fields and user-defined setters. | 1032 // Check for real fields and user-defined setters. |
| 1021 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1033 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 1022 if (field.IsNull()) { | 1034 if (field.IsNull()) { |
| 1023 const String& internal_setter_name = String::Handle( | 1035 const String& internal_setter_name = String::Handle( |
| 1024 Field::SetterName(setter_name)); | 1036 Field::SetterName(setter_name)); |
| 1025 const Function& setter = Function::Handle( | 1037 const Function& setter = Function::Handle( |
| 1026 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1038 klass.LookupStaticFunction(internal_setter_name)); |
| 1027 | 1039 |
| 1028 if (setter.IsNull() || !setter.is_visible()) { | 1040 if (setter.IsNull() || !setter.is_visible()) { |
| 1029 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1041 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 1030 setter_name, | 1042 setter_name, |
| 1031 setter, | 1043 setter, |
| 1032 InvocationMirror::kStatic, | 1044 InvocationMirror::kStatic, |
| 1033 InvocationMirror::kSetter); | 1045 InvocationMirror::kSetter); |
| 1034 UNREACHABLE(); | 1046 UNREACHABLE(); |
| 1035 } | 1047 } |
| 1036 | 1048 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 // This convention prevents users from explicitly calling constructors. | 1089 // This convention prevents users from explicitly calling constructors. |
| 1078 const String& klass_name = String::Handle(klass.Name()); | 1090 const String& klass_name = String::Handle(klass.Name()); |
| 1079 String& internal_constructor_name = | 1091 String& internal_constructor_name = |
| 1080 String::Handle(String::Concat(klass_name, Symbols::Dot())); | 1092 String::Handle(String::Concat(klass_name, Symbols::Dot())); |
| 1081 if (!constructor_name.IsNull()) { | 1093 if (!constructor_name.IsNull()) { |
| 1082 internal_constructor_name = | 1094 internal_constructor_name = |
| 1083 String::Concat(internal_constructor_name, constructor_name); | 1095 String::Concat(internal_constructor_name, constructor_name); |
| 1084 } | 1096 } |
| 1085 | 1097 |
| 1086 Function& lookup_constructor = Function::Handle( | 1098 Function& lookup_constructor = Function::Handle( |
| 1087 klass.LookupFunctionAllowPrivate(internal_constructor_name)); | 1099 klass.LookupFunction(internal_constructor_name)); |
| 1088 | 1100 |
| 1089 if (lookup_constructor.IsNull() || | 1101 if (lookup_constructor.IsNull() || |
| 1090 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || | 1102 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || |
| 1091 !lookup_constructor.is_visible()) { | 1103 !lookup_constructor.is_visible()) { |
| 1092 // Pretend we didn't find the constructor at all when the arity is wrong | 1104 // 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. | 1105 // so as to produce the same NoSuchMethodError as the non-reflective case. |
| 1094 lookup_constructor = Function::null(); | 1106 lookup_constructor = Function::null(); |
| 1095 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1107 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
| 1096 internal_constructor_name, | 1108 internal_constructor_name, |
| 1097 lookup_constructor, | 1109 lookup_constructor, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1205 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1194 GET_NON_NULL_NATIVE_ARGUMENT( | 1206 GET_NON_NULL_NATIVE_ARGUMENT( |
| 1195 String, function_name, arguments->NativeArgAt(2)); | 1207 String, function_name, arguments->NativeArgAt(2)); |
| 1196 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); | 1208 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); |
| 1197 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); | 1209 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| 1198 | 1210 |
| 1199 const Array& args_descriptor_array = | 1211 const Array& args_descriptor_array = |
| 1200 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1212 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
| 1201 | 1213 |
| 1202 const Function& function = Function::Handle( | 1214 const Function& function = Function::Handle( |
| 1203 library.LookupFunctionAllowPrivate(function_name)); | 1215 library.LookupLocalFunction(function_name)); |
| 1204 | 1216 |
| 1205 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1217 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
| 1206 if (function.IsNull() || | 1218 if (function.IsNull() || |
| 1207 !function.AreValidArguments(args_descriptor, NULL) || | 1219 !function.AreValidArguments(args_descriptor, NULL) || |
| 1208 !function.is_visible()) { | 1220 !function.is_visible()) { |
| 1209 ThrowNoSuchMethod(Instance::null_instance(), | 1221 ThrowNoSuchMethod(Instance::null_instance(), |
| 1210 function_name, | 1222 function_name, |
| 1211 function, | 1223 function, |
| 1212 InvocationMirror::kTopLevel, | 1224 InvocationMirror::kTopLevel, |
| 1213 InvocationMirror::kMethod); | 1225 InvocationMirror::kMethod); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1229 // because this native is an instance method in order to be polymorphic | 1241 // because this native is an instance method in order to be polymorphic |
| 1230 // with its cousins. | 1242 // with its cousins. |
| 1231 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1243 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1232 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1244 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1233 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 1245 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 1234 | 1246 |
| 1235 // To access a top-level we may need to use the Field or the | 1247 // 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 | 1248 // getter Function. The getter function may either be in the |
| 1237 // library or in the field's owner class, depending. | 1249 // library or in the field's owner class, depending. |
| 1238 const Field& field = Field::Handle( | 1250 const Field& field = Field::Handle( |
| 1239 library.LookupFieldAllowPrivate(getter_name)); | 1251 library.LookupLocalField(getter_name)); |
| 1240 Function& getter = Function::Handle(); | 1252 Function& getter = Function::Handle(); |
| 1241 if (field.IsNull()) { | 1253 if (field.IsNull()) { |
| 1242 // No field found and no ambiguity error. Check for a getter in the lib. | 1254 // No field found and no ambiguity error. Check for a getter in the lib. |
| 1243 const String& internal_getter_name = | 1255 const String& internal_getter_name = |
| 1244 String::Handle(Field::GetterName(getter_name)); | 1256 String::Handle(Field::GetterName(getter_name)); |
| 1245 getter = library.LookupFunctionAllowPrivate(internal_getter_name); | 1257 getter = library.LookupLocalFunction(internal_getter_name); |
| 1246 if (getter.IsNull()) { | 1258 if (getter.IsNull()) { |
| 1247 getter = library.LookupFunctionAllowPrivate(getter_name); | 1259 getter = library.LookupLocalFunction(getter_name); |
| 1248 if (!getter.IsNull()) { | 1260 if (!getter.IsNull()) { |
| 1249 // Looking for a getter but found a regular method: closurize. | 1261 // Looking for a getter but found a regular method: closurize. |
| 1250 const Function& closure_function = | 1262 const Function& closure_function = |
| 1251 Function::Handle(getter.ImplicitClosureFunction()); | 1263 Function::Handle(getter.ImplicitClosureFunction()); |
| 1252 return closure_function.ImplicitStaticClosure(); | 1264 return closure_function.ImplicitStaticClosure(); |
| 1253 } | 1265 } |
| 1254 } | 1266 } |
| 1255 } else if (!field.IsNull() && FieldIsUninitialized(field)) { | 1267 } else if (!field.IsNull() && FieldIsUninitialized(field)) { |
| 1256 // A field was found. Check for a getter in the field's owner classs. | 1268 // A field was found. Check for a getter in the field's owner classs. |
| 1257 const Class& klass = Class::Handle(field.owner()); | 1269 const Class& klass = Class::Handle(field.owner()); |
| 1258 const String& internal_getter_name = | 1270 const String& internal_getter_name = |
| 1259 String::Handle(Field::GetterName(getter_name)); | 1271 String::Handle(Field::GetterName(getter_name)); |
| 1260 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 1272 getter = klass.LookupStaticFunction(internal_getter_name); |
| 1261 } | 1273 } |
| 1262 | 1274 |
| 1263 if (!getter.IsNull() && getter.is_visible()) { | 1275 if (!getter.IsNull() && getter.is_visible()) { |
| 1264 // Invoke the getter and return the result. | 1276 // Invoke the getter and return the result. |
| 1265 const Object& result = Object::Handle( | 1277 const Object& result = Object::Handle( |
| 1266 DartEntry::InvokeFunction(getter, Object::empty_array())); | 1278 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 1267 if (result.IsError()) { | 1279 if (result.IsError()) { |
| 1268 ThrowInvokeError(Error::Cast(result)); | 1280 ThrowInvokeError(Error::Cast(result)); |
| 1269 UNREACHABLE(); | 1281 UNREACHABLE(); |
| 1270 } | 1282 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1289 // with its cousins. | 1301 // with its cousins. |
| 1290 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1302 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1291 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 1303 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 1292 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); | 1304 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); |
| 1293 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 1305 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 1294 | 1306 |
| 1295 // To access a top-level we may need to use the Field or the | 1307 // 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 | 1308 // setter Function. The setter function may either be in the |
| 1297 // library or in the field's owner class, depending. | 1309 // library or in the field's owner class, depending. |
| 1298 const Field& field = Field::Handle( | 1310 const Field& field = Field::Handle( |
| 1299 library.LookupFieldAllowPrivate(setter_name)); | 1311 library.LookupLocalField(setter_name)); |
| 1300 | 1312 |
| 1301 if (field.IsNull()) { | 1313 if (field.IsNull()) { |
| 1302 const String& internal_setter_name = | 1314 const String& internal_setter_name = |
| 1303 String::Handle(Field::SetterName(setter_name)); | 1315 String::Handle(Field::SetterName(setter_name)); |
| 1304 const Function& setter = Function::Handle( | 1316 const Function& setter = Function::Handle( |
| 1305 library.LookupFunctionAllowPrivate(internal_setter_name)); | 1317 library.LookupLocalFunction(internal_setter_name)); |
| 1306 if (setter.IsNull() || !setter.is_visible()) { | 1318 if (setter.IsNull() || !setter.is_visible()) { |
| 1307 ThrowNoSuchMethod(Instance::null_instance(), | 1319 ThrowNoSuchMethod(Instance::null_instance(), |
| 1308 setter_name, | 1320 setter_name, |
| 1309 setter, | 1321 setter, |
| 1310 InvocationMirror::kTopLevel, | 1322 InvocationMirror::kTopLevel, |
| 1311 InvocationMirror::kSetter); | 1323 InvocationMirror::kSetter); |
| 1312 UNREACHABLE(); | 1324 UNREACHABLE(); |
| 1313 } | 1325 } |
| 1314 | 1326 |
| 1315 // Invoke the setter and return the result. | 1327 // Invoke the setter and return the result. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 } | 1431 } |
| 1420 | 1432 |
| 1421 | 1433 |
| 1422 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1434 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1423 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1435 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1424 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1436 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1425 return field.type(); | 1437 return field.type(); |
| 1426 } | 1438 } |
| 1427 | 1439 |
| 1428 } // namespace dart | 1440 } // namespace dart |
| OLD | NEW |