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