| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 Field& field = Field::Handle(); | 484 Field& field = Field::Handle(); |
| 485 for (intptr_t i = 0; i < num_fields; i++) { | 485 for (intptr_t i = 0; i < num_fields; i++) { |
| 486 field ^= fields.At(i); | 486 field ^= fields.At(i); |
| 487 member_mirror = CreateVariableMirror(field, owner_mirror); | 487 member_mirror = CreateVariableMirror(field, owner_mirror); |
| 488 member_mirrors.Add(member_mirror); | 488 member_mirrors.Add(member_mirror); |
| 489 } | 489 } |
| 490 | 490 |
| 491 Function& func = Function::Handle(); | 491 Function& func = Function::Handle(); |
| 492 for (intptr_t i = 0; i < num_functions; i++) { | 492 for (intptr_t i = 0; i < num_functions; i++) { |
| 493 func ^= functions.At(i); | 493 func ^= functions.At(i); |
| 494 if (func.kind() == RawFunction::kRegularFunction || | 494 if (func.is_visible() && |
| 495 (func.kind() == RawFunction::kRegularFunction || |
| 495 func.kind() == RawFunction::kGetterFunction || | 496 func.kind() == RawFunction::kGetterFunction || |
| 496 func.kind() == RawFunction::kSetterFunction) { | 497 func.kind() == RawFunction::kSetterFunction)) { |
| 497 member_mirror = CreateMethodMirror(func, owner_mirror); | 498 member_mirror = CreateMethodMirror(func, owner_mirror); |
| 498 member_mirrors.Add(member_mirror); | 499 member_mirrors.Add(member_mirror); |
| 499 } | 500 } |
| 500 } | 501 } |
| 501 | 502 |
| 502 return member_mirrors.raw(); | 503 return member_mirrors.raw(); |
| 503 } | 504 } |
| 504 | 505 |
| 505 | 506 |
| 506 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { | 507 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 631 |
| 631 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled | 632 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled |
| 632 // exceptions. Wrap and propagate any compilation errors. | 633 // exceptions. Wrap and propagate any compilation errors. |
| 633 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, | 634 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, |
| 634 const Function& function, | 635 const Function& function, |
| 635 const String& target_name, | 636 const String& target_name, |
| 636 const Array& arguments) { | 637 const Array& arguments) { |
| 637 // Note "arguments" is already the internal arguments with the receiver as | 638 // Note "arguments" is already the internal arguments with the receiver as |
| 638 // the first element. | 639 // the first element. |
| 639 Object& result = Object::Handle(); | 640 Object& result = Object::Handle(); |
| 640 if (function.IsNull()) { | 641 if (function.IsNull() || !function.is_visible()) { |
| 641 const Array& arguments_descriptor = | 642 const Array& arguments_descriptor = |
| 642 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 643 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); |
| 643 result = DartEntry::InvokeNoSuchMethod(receiver, | 644 result = DartEntry::InvokeNoSuchMethod(receiver, |
| 644 target_name, | 645 target_name, |
| 645 arguments, | 646 arguments, |
| 646 arguments_descriptor); | 647 arguments_descriptor); |
| 647 } else { | 648 } else { |
| 648 result = DartEntry::InvokeFunction(function, arguments); | 649 result = DartEntry::InvokeFunction(function, arguments); |
| 649 } | 650 } |
| 650 | 651 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 Array, positional_args, arguments->NativeArgAt(3)); | 890 Array, positional_args, arguments->NativeArgAt(3)); |
| 890 | 891 |
| 891 intptr_t number_of_arguments = positional_args.Length(); | 892 intptr_t number_of_arguments = positional_args.Length(); |
| 892 | 893 |
| 893 const Function& function = Function::Handle( | 894 const Function& function = Function::Handle( |
| 894 klass.LookupStaticFunctionAllowPrivate(function_name)); | 895 klass.LookupStaticFunctionAllowPrivate(function_name)); |
| 895 | 896 |
| 896 if (function.IsNull() || | 897 if (function.IsNull() || |
| 897 !function.AreValidArgumentCounts(number_of_arguments, | 898 !function.AreValidArgumentCounts(number_of_arguments, |
| 898 /* named_args */ 0, | 899 /* named_args */ 0, |
| 899 NULL)) { | 900 NULL) || |
| 901 !function.is_visible()) { |
| 900 ThrowNoSuchMethod(klass, | 902 ThrowNoSuchMethod(klass, |
| 901 function_name, | 903 function_name, |
| 902 function, | 904 function, |
| 903 InvocationMirror::kStatic, | 905 InvocationMirror::kStatic, |
| 904 InvocationMirror::kMethod); | 906 InvocationMirror::kMethod); |
| 905 UNREACHABLE(); | 907 UNREACHABLE(); |
| 906 } | 908 } |
| 907 | 909 |
| 908 Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 910 Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
| 909 positional_args)); | 911 positional_args)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 924 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); | 926 GET_NON_NULL_NATIVE_ARGUMENT(String, getter_name, arguments->NativeArgAt(2)); |
| 925 | 927 |
| 926 // Note static fields do not have implicit getters. | 928 // Note static fields do not have implicit getters. |
| 927 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 929 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 928 if (field.IsNull() || FieldIsUninitialized(field)) { | 930 if (field.IsNull() || FieldIsUninitialized(field)) { |
| 929 const String& internal_getter_name = String::Handle( | 931 const String& internal_getter_name = String::Handle( |
| 930 Field::GetterName(getter_name)); | 932 Field::GetterName(getter_name)); |
| 931 const Function& getter = Function::Handle( | 933 const Function& getter = Function::Handle( |
| 932 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 934 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
| 933 | 935 |
| 934 if (getter.IsNull()) { | 936 if (getter.IsNull() || !getter.is_visible()) { |
| 935 ThrowNoSuchMethod(klass, | 937 ThrowNoSuchMethod(klass, |
| 936 getter_name, | 938 getter_name, |
| 937 getter, | 939 getter, |
| 938 InvocationMirror::kStatic, | 940 InvocationMirror::kStatic, |
| 939 InvocationMirror::kGetter); | 941 InvocationMirror::kGetter); |
| 940 UNREACHABLE(); | 942 UNREACHABLE(); |
| 941 } | 943 } |
| 942 | 944 |
| 943 // Invoke the getter and return the result. | 945 // Invoke the getter and return the result. |
| 944 Object& result = Object::Handle( | 946 Object& result = Object::Handle( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 963 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); | 965 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); |
| 964 | 966 |
| 965 // Check for real fields and user-defined setters. | 967 // Check for real fields and user-defined setters. |
| 966 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 968 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 967 if (field.IsNull()) { | 969 if (field.IsNull()) { |
| 968 const String& internal_setter_name = String::Handle( | 970 const String& internal_setter_name = String::Handle( |
| 969 Field::SetterName(setter_name)); | 971 Field::SetterName(setter_name)); |
| 970 const Function& setter = Function::Handle( | 972 const Function& setter = Function::Handle( |
| 971 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 973 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
| 972 | 974 |
| 973 if (setter.IsNull()) { | 975 if (setter.IsNull() || !setter.is_visible()) { |
| 974 ThrowNoSuchMethod(klass, | 976 ThrowNoSuchMethod(klass, |
| 975 setter_name, | 977 setter_name, |
| 976 setter, | 978 setter, |
| 977 InvocationMirror::kStatic, | 979 InvocationMirror::kStatic, |
| 978 InvocationMirror::kSetter); | 980 InvocationMirror::kSetter); |
| 979 UNREACHABLE(); | 981 UNREACHABLE(); |
| 980 } | 982 } |
| 981 | 983 |
| 982 // Invoke the setter and return the result. | 984 // Invoke the setter and return the result. |
| 983 const int kNumArgs = 1; | 985 const int kNumArgs = 1; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1032 Function& constructor = Function::Handle( | 1034 Function& constructor = Function::Handle( |
| 1033 klass.LookupFunctionAllowPrivate(internal_constructor_name)); | 1035 klass.LookupFunctionAllowPrivate(internal_constructor_name)); |
| 1034 | 1036 |
| 1035 if (constructor.IsNull() || | 1037 if (constructor.IsNull() || |
| 1036 (!constructor.IsConstructor() && !constructor.IsFactory()) || | 1038 (!constructor.IsConstructor() && !constructor.IsFactory()) || |
| 1037 !constructor.AreValidArgumentCounts(number_of_arguments + | 1039 !constructor.AreValidArgumentCounts(number_of_arguments + |
| 1038 constructor.NumImplicitParameters(), | 1040 constructor.NumImplicitParameters(), |
| 1039 /* named args */ 0, | 1041 /* named args */ 0, |
| 1040 NULL)) { | 1042 NULL) || |
| 1043 !constructor.is_visible()) { |
| 1041 // Pretend we didn't find the constructor at all when the arity is wrong | 1044 // Pretend we didn't find the constructor at all when the arity is wrong |
| 1042 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1045 // so as to produce the same NoSuchMethodError as the non-reflective case. |
| 1043 constructor = Function::null(); | 1046 constructor = Function::null(); |
| 1044 ThrowNoSuchMethod(klass, | 1047 ThrowNoSuchMethod(klass, |
| 1045 internal_constructor_name, | 1048 internal_constructor_name, |
| 1046 constructor, | 1049 constructor, |
| 1047 InvocationMirror::kConstructor, | 1050 InvocationMirror::kConstructor, |
| 1048 InvocationMirror::kMethod); | 1051 InvocationMirror::kMethod); |
| 1049 UNREACHABLE(); | 1052 UNREACHABLE(); |
| 1050 } | 1053 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1081 library.LookupFunctionAllowPrivate(function_name, &ambiguity_error_msg)); | 1084 library.LookupFunctionAllowPrivate(function_name, &ambiguity_error_msg)); |
| 1082 | 1085 |
| 1083 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { | 1086 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { |
| 1084 ThrowMirroredCompilationError(ambiguity_error_msg); | 1087 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1085 UNREACHABLE(); | 1088 UNREACHABLE(); |
| 1086 } | 1089 } |
| 1087 | 1090 |
| 1088 if (function.IsNull() || | 1091 if (function.IsNull() || |
| 1089 !function.AreValidArgumentCounts(number_of_arguments, | 1092 !function.AreValidArgumentCounts(number_of_arguments, |
| 1090 0, | 1093 0, |
| 1091 NULL) ) { | 1094 NULL) || |
| 1095 !function.is_visible()) { |
| 1092 ThrowNoSuchMethod(library, | 1096 ThrowNoSuchMethod(library, |
| 1093 function_name, | 1097 function_name, |
| 1094 function, | 1098 function, |
| 1095 InvocationMirror::kTopLevel, | 1099 InvocationMirror::kTopLevel, |
| 1096 InvocationMirror::kMethod); | 1100 InvocationMirror::kMethod); |
| 1097 UNREACHABLE(); | 1101 UNREACHABLE(); |
| 1098 } | 1102 } |
| 1099 | 1103 |
| 1100 const Object& result = Object::Handle( | 1104 const Object& result = Object::Handle( |
| 1101 DartEntry::InvokeFunction(function, positional_args)); | 1105 DartEntry::InvokeFunction(function, positional_args)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1129 getter = library.LookupFunctionAllowPrivate(internal_getter_name, | 1133 getter = library.LookupFunctionAllowPrivate(internal_getter_name, |
| 1130 &ambiguity_error_msg); | 1134 &ambiguity_error_msg); |
| 1131 } else if (!field.IsNull() && FieldIsUninitialized(field)) { | 1135 } else if (!field.IsNull() && FieldIsUninitialized(field)) { |
| 1132 // A field was found. Check for a getter in the field's owner classs. | 1136 // A field was found. Check for a getter in the field's owner classs. |
| 1133 const Class& klass = Class::Handle(field.owner()); | 1137 const Class& klass = Class::Handle(field.owner()); |
| 1134 const String& internal_getter_name = | 1138 const String& internal_getter_name = |
| 1135 String::Handle(Field::GetterName(getter_name)); | 1139 String::Handle(Field::GetterName(getter_name)); |
| 1136 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); | 1140 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); |
| 1137 } | 1141 } |
| 1138 | 1142 |
| 1139 if (!getter.IsNull()) { | 1143 if (!getter.IsNull() && getter.is_visible()) { |
| 1140 // Invoke the getter and return the result. | 1144 // Invoke the getter and return the result. |
| 1141 const Object& result = Object::Handle( | 1145 const Object& result = Object::Handle( |
| 1142 DartEntry::InvokeFunction(getter, Object::empty_array())); | 1146 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 1143 if (result.IsError()) { | 1147 if (result.IsError()) { |
| 1144 ThrowInvokeError(Error::Cast(result)); | 1148 ThrowInvokeError(Error::Cast(result)); |
| 1145 UNREACHABLE(); | 1149 UNREACHABLE(); |
| 1146 } | 1150 } |
| 1147 return result.raw(); | 1151 return result.raw(); |
| 1148 } | 1152 } |
| 1149 if (!field.IsNull()) { | 1153 if (!field.IsNull()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1178 String& ambiguity_error_msg = String::Handle(isolate); | 1182 String& ambiguity_error_msg = String::Handle(isolate); |
| 1179 const Field& field = Field::Handle( | 1183 const Field& field = Field::Handle( |
| 1180 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); | 1184 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); |
| 1181 | 1185 |
| 1182 if (field.IsNull() && ambiguity_error_msg.IsNull()) { | 1186 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| 1183 const String& internal_setter_name = | 1187 const String& internal_setter_name = |
| 1184 String::Handle(Field::SetterName(setter_name)); | 1188 String::Handle(Field::SetterName(setter_name)); |
| 1185 const Function& setter = Function::Handle( | 1189 const Function& setter = Function::Handle( |
| 1186 library.LookupFunctionAllowPrivate(internal_setter_name, | 1190 library.LookupFunctionAllowPrivate(internal_setter_name, |
| 1187 &ambiguity_error_msg)); | 1191 &ambiguity_error_msg)); |
| 1188 if (setter.IsNull()) { | 1192 if (setter.IsNull() || !setter.is_visible()) { |
| 1189 if (ambiguity_error_msg.IsNull()) { | 1193 if (ambiguity_error_msg.IsNull()) { |
| 1190 ThrowNoSuchMethod(library, | 1194 ThrowNoSuchMethod(library, |
| 1191 setter_name, | 1195 setter_name, |
| 1192 setter, | 1196 setter, |
| 1193 InvocationMirror::kTopLevel, | 1197 InvocationMirror::kTopLevel, |
| 1194 InvocationMirror::kSetter); | 1198 InvocationMirror::kSetter); |
| 1195 } else { | 1199 } else { |
| 1196 ThrowMirroredCompilationError(ambiguity_error_msg); | 1200 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1197 } | 1201 } |
| 1198 UNREACHABLE(); | 1202 UNREACHABLE(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 } | 1280 } |
| 1277 | 1281 |
| 1278 | 1282 |
| 1279 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1283 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1280 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1284 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1281 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1285 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1282 return field.type(); | 1286 return field.type(); |
| 1283 } | 1287 } |
| 1284 | 1288 |
| 1285 } // namespace dart | 1289 } // namespace dart |
| OLD | NEW |