| 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" |
| 11 #include "vm/parser.h" |
| 11 #include "vm/port.h" | 12 #include "vm/port.h" |
| 12 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
| 13 | 14 |
| 14 namespace dart { | 15 namespace dart { |
| 15 | 16 |
| 16 static RawInstance* CreateMirror(const String& mirror_class_name, | 17 static RawInstance* CreateMirror(const String& mirror_class_name, |
| 17 const Array& constructor_arguments) { | 18 const Array& constructor_arguments) { |
| 18 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); | 19 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); |
| 19 const String& constructor_name = Symbols::Dot(); | 20 const String& constructor_name = Symbols::Dot(); |
| 20 | 21 |
| 21 const Object& result = Object::Handle( | 22 const Object& result = Object::Handle( |
| 22 DartLibraryCalls::InstanceCreate(mirrors_lib, | 23 DartLibraryCalls::InstanceCreate(mirrors_lib, |
| 23 mirror_class_name, | 24 mirror_class_name, |
| 24 constructor_name, | 25 constructor_name, |
| 25 constructor_arguments)); | 26 constructor_arguments)); |
| 26 ASSERT(!result.IsError()); | 27 ASSERT(!result.IsError()); |
| 27 return Instance::Cast(result).raw(); | 28 return Instance::Cast(result).raw(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 | 31 |
| 32 // Note a "raw type" is not the same as a RawType. |
| 33 static RawAbstractType* RawTypeOfClass(const Class& cls) { |
| 34 Type& type = Type::Handle(Type::New(cls, |
| 35 Object::null_abstract_type_arguments(), |
| 36 Scanner::kDummyTokenIndex)); |
| 37 return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); |
| 38 } |
| 39 |
| 40 |
| 41 static void ThrowMirroredCompilationError(const String& message) { |
| 42 Array& args = Array::Handle(Array::New(1)); |
| 43 args.SetAt(0, message); |
| 44 |
| 45 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
| 46 UNREACHABLE(); |
| 47 } |
| 48 |
| 49 |
| 50 static void ThrowInvokeError(const Error& error) { |
| 51 if (error.IsLanguageError()) { |
| 52 // A compilation error that was delayed by lazy compilation. |
| 53 const LanguageError& compilation_error = LanguageError::Cast(error); |
| 54 String& message = String::Handle(compilation_error.message()); |
| 55 ThrowMirroredCompilationError(message); |
| 56 UNREACHABLE(); |
| 57 } |
| 58 Exceptions::PropagateError(error); |
| 59 UNREACHABLE(); |
| 60 } |
| 61 |
| 62 |
| 63 // Conventions: |
| 64 // * For throwing a NSM in a class klass we use its runtime type as receiver, |
| 65 // i.e., RawTypeOfClass(klass). |
| 66 // * For throwing a NSM in a library, we just pass the null instance as |
| 67 // receiver. |
| 68 static void ThrowNoSuchMethod(const Instance& receiver, |
| 69 const String& function_name, |
| 70 const Function& function, |
| 71 const InvocationMirror::Call call, |
| 72 const InvocationMirror::Type type) { |
| 73 const Smi& invocation_type = Smi::Handle(Smi::New( |
| 74 InvocationMirror::EncodeType(call, type))); |
| 75 |
| 76 const Array& args = Array::Handle(Array::New(6)); |
| 77 args.SetAt(0, receiver); |
| 78 args.SetAt(1, function_name); |
| 79 args.SetAt(2, invocation_type); |
| 80 // Parameter 3 (actual arguments): We omit this parameter to get the same |
| 81 // error message as one would get by invoking the function non-reflectively. |
| 82 // Parameter 4 (named arguments): We omit this parameters since we cannot |
| 83 // invoke functions with named parameters reflectively (using mirrors). |
| 84 if (!function.IsNull()) { |
| 85 const int total_num_parameters = function.NumParameters(); |
| 86 const Array& array = Array::Handle(Array::New(total_num_parameters)); |
| 87 String& param_name = String::Handle(); |
| 88 for (int i = 0; i < total_num_parameters; i++) { |
| 89 param_name = function.ParameterNameAt(i); |
| 90 array.SetAt(i, param_name); |
| 91 } |
| 92 args.SetAt(5, array); |
| 93 } |
| 94 |
| 95 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); |
| 96 UNREACHABLE(); |
| 97 } |
| 98 |
| 99 |
| 31 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { | 100 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { |
| 32 GET_NON_NULL_NATIVE_ARGUMENT(Instance, port, arguments->NativeArgAt(0)); | 101 GET_NON_NULL_NATIVE_ARGUMENT(Instance, port, arguments->NativeArgAt(0)); |
| 33 | 102 |
| 34 // Get the port id from the SendPort instance. | 103 // Get the port id from the SendPort instance. |
| 35 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); | 104 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); |
| 36 if (id_obj.IsError()) { | 105 if (id_obj.IsError()) { |
| 37 Exceptions::PropagateError(Error::Cast(id_obj)); | 106 Exceptions::PropagateError(Error::Cast(id_obj)); |
| 38 UNREACHABLE(); | 107 UNREACHABLE(); |
| 39 } | 108 } |
| 40 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); | 109 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); |
| 41 Integer& id = Integer::Handle(); | 110 Integer& id = Integer::Handle(); |
| 42 id ^= id_obj.raw(); | 111 id ^= id_obj.raw(); |
| 43 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); | 112 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); |
| 44 return Bool::Get(PortMap::IsLocalPort(port_id)); | 113 return Bool::Get(PortMap::IsLocalPort(port_id)); |
| 45 } | 114 } |
| 46 | 115 |
| 47 | 116 |
| 48 static RawInstance* CreateParameterMirrorList(const Function& func, | 117 static RawInstance* CreateParameterMirrorList(const Function& func, |
| 49 const Instance& owner_mirror) { | 118 const Instance& owner_mirror) { |
| 50 HANDLESCOPE(Isolate::Current()); | 119 HANDLESCOPE(Isolate::Current()); |
| 51 const intptr_t implicit_param_count = func.NumImplicitParameters(); | 120 const intptr_t implicit_param_count = func.NumImplicitParameters(); |
| 52 const intptr_t non_implicit_param_count = func.NumParameters() - | 121 const intptr_t non_implicit_param_count = func.NumParameters() - |
| 53 implicit_param_count; | 122 implicit_param_count; |
| 54 const intptr_t index_of_first_optional_param = | 123 const intptr_t index_of_first_optional_param = |
| 55 non_implicit_param_count - func.NumOptionalParameters(); | 124 non_implicit_param_count - func.NumOptionalParameters(); |
| 56 const intptr_t index_of_first_named_param = | 125 const intptr_t index_of_first_named_param = |
| 57 non_implicit_param_count - func.NumOptionalNamedParameters(); | 126 non_implicit_param_count - func.NumOptionalNamedParameters(); |
| 58 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); | 127 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); |
| 59 const Array& args = Array::Handle(Array::New(6)); | 128 const Array& args = Array::Handle(Array::New(8)); |
| 60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 129 |
| 61 args.SetAt(2, owner_mirror); | 130 // Return for synthetic functions and getters. |
| 131 if (func.IsGetterFunction() || |
| 132 func.IsImplicitConstructor() || |
| 133 func.IsImplicitGetterFunction() || |
| 134 func.IsImplicitSetterFunction()) { |
| 135 return results.raw(); |
| 136 } |
| 137 |
| 62 Smi& pos = Smi::Handle(); | 138 Smi& pos = Smi::Handle(); |
| 63 String& name = String::Handle(); | 139 String& name = String::Handle(); |
| 64 Instance& param = Instance::Handle(); | 140 Instance& param = Instance::Handle(); |
| 141 Bool& is_final = Bool::Handle(); |
| 142 Object& default_value = Object::Handle(); |
| 143 |
| 144 // Reparse the function for the following information: |
| 145 // * The default value of a parameter. |
| 146 // * Whether a parameters has been deflared as final. |
| 147 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); |
| 148 if (result.IsError()) { |
| 149 ThrowInvokeError(Error::Cast(result)); |
| 150 UNREACHABLE(); |
| 151 } |
| 152 |
| 153 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 154 args.SetAt(2, owner_mirror); |
| 155 |
| 156 const Array& param_descriptor = Array::Cast(result); |
| 157 ASSERT(param_descriptor.Length() == (2 * non_implicit_param_count)); |
| 65 for (intptr_t i = 0; i < non_implicit_param_count; i++) { | 158 for (intptr_t i = 0; i < non_implicit_param_count; i++) { |
| 66 pos ^= Smi::New(i); | 159 pos ^= Smi::New(i); |
| 67 name ^= func.ParameterNameAt(implicit_param_count + i); | 160 name ^= func.ParameterNameAt(implicit_param_count + i); |
| 161 is_final ^= param_descriptor.At(i * 2); |
| 162 default_value = param_descriptor.At(i * 2 + 1); |
| 163 ASSERT(default_value.IsNull() || default_value.IsInstance()); |
| 164 |
| 165 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See |
| 166 // above. |
| 68 args.SetAt(1, name); | 167 args.SetAt(1, name); |
| 69 args.SetAt(3, pos); | 168 args.SetAt(3, pos); |
| 70 args.SetAt(4, (i >= index_of_first_optional_param) ? | 169 args.SetAt(4, (i >= index_of_first_optional_param) ? |
| 71 Bool::True() : Bool::False()); | 170 Bool::True() : Bool::False()); |
| 72 args.SetAt(5, (i >= index_of_first_named_param) ? | 171 args.SetAt(5, (i >= index_of_first_named_param) ? |
| 73 Bool::True() : Bool::False()); | 172 Bool::True() : Bool::False()); |
| 173 args.SetAt(6, is_final); |
| 174 args.SetAt(7, default_value); |
| 74 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | 175 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
| 75 results.SetAt(i, param); | 176 results.SetAt(i, param); |
| 76 } | 177 } |
| 77 results.MakeImmutable(); | 178 results.MakeImmutable(); |
| 78 return results.raw(); | 179 return results.raw(); |
| 79 } | 180 } |
| 80 | 181 |
| 81 | 182 |
| 82 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, | 183 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
| 83 const Instance& owner_mirror) { | 184 const Instance& owner_mirror) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 305 |
| 205 const Array& args = Array::Handle(Array::New(4)); | 306 const Array& args = Array::Handle(Array::New(4)); |
| 206 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 307 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 207 args.SetAt(1, type); | 308 args.SetAt(1, type); |
| 208 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 309 args.SetAt(2, String::Handle(cls.UserVisibleName())); |
| 209 args.SetAt(3, is_generic); | 310 args.SetAt(3, is_generic); |
| 210 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 311 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 211 } | 312 } |
| 212 | 313 |
| 213 | 314 |
| 214 // Note a "raw type" is not the same as a RawType. | |
| 215 static RawAbstractType* RawTypeOfClass(const Class& cls) { | |
| 216 Type& type = Type::Handle(Type::New(cls, | |
| 217 Object::null_abstract_type_arguments(), | |
| 218 Scanner::kDummyTokenIndex)); | |
| 219 return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); | |
| 220 } | |
| 221 | |
| 222 | |
| 223 static RawInstance* CreateLibraryMirror(const Library& lib) { | 315 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 224 const Array& args = Array::Handle(Array::New(3)); | 316 const Array& args = Array::Handle(Array::New(3)); |
| 225 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 317 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| 226 String& str = String::Handle(); | 318 String& str = String::Handle(); |
| 227 str = lib.name(); | 319 str = lib.name(); |
| 228 args.SetAt(1, str); | 320 args.SetAt(1, str); |
| 229 str = lib.url(); | 321 str = lib.url(); |
| 230 args.SetAt(2, str); | 322 args.SetAt(2, str); |
| 231 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); | 323 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); |
| 232 } | 324 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 417 } |
| 326 } | 418 } |
| 327 | 419 |
| 328 | 420 |
| 329 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 421 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
| 330 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 422 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 331 return CreateTypeMirror(type); | 423 return CreateTypeMirror(type); |
| 332 } | 424 } |
| 333 | 425 |
| 334 | 426 |
| 335 static void ThrowMirroredCompilationError(const String& message) { | |
| 336 Array& args = Array::Handle(Array::New(1)); | |
| 337 args.SetAt(0, message); | |
| 338 | |
| 339 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); | |
| 340 UNREACHABLE(); | |
| 341 } | |
| 342 | |
| 343 | |
| 344 static void ThrowInvokeError(const Error& error) { | |
| 345 if (error.IsLanguageError()) { | |
| 346 // A compilation error that was delayed by lazy compilation. | |
| 347 const LanguageError& compilation_error = LanguageError::Cast(error); | |
| 348 String& message = String::Handle(compilation_error.message()); | |
| 349 ThrowMirroredCompilationError(message); | |
| 350 UNREACHABLE(); | |
| 351 } | |
| 352 Exceptions::PropagateError(error); | |
| 353 UNREACHABLE(); | |
| 354 } | |
| 355 | |
| 356 | |
| 357 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { | 427 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
| 358 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 428 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
| 359 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 429 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
| 360 return Bool::Get(a.referent() == b.referent()); | 430 return Bool::Get(a.referent() == b.referent()); |
| 361 } | 431 } |
| 362 | 432 |
| 363 | 433 |
| 364 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 434 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
| 365 const MirrorReference& decl_ref = | 435 const MirrorReference& decl_ref = |
| 366 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 436 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 ASSERT(!closure.IsNull()); | 912 ASSERT(!closure.IsNull()); |
| 843 | 913 |
| 844 Function& function = Function::Handle(); | 914 Function& function = Function::Handle(); |
| 845 bool callable = closure.IsCallable(&function, NULL); | 915 bool callable = closure.IsCallable(&function, NULL); |
| 846 ASSERT(callable); | 916 ASSERT(callable); |
| 847 | 917 |
| 848 return CreateMethodMirror(function, Instance::null_instance()); | 918 return CreateMethodMirror(function, Instance::null_instance()); |
| 849 } | 919 } |
| 850 | 920 |
| 851 | 921 |
| 852 static void ThrowNoSuchMethod(const Instance& receiver, | |
| 853 const String& function_name, | |
| 854 const Function& function, | |
| 855 const InvocationMirror::Call call, | |
| 856 const InvocationMirror::Type type) { | |
| 857 const Smi& invocation_type = Smi::Handle(Smi::New( | |
| 858 InvocationMirror::EncodeType(call, type))); | |
| 859 | |
| 860 const Array& args = Array::Handle(Array::New(6)); | |
| 861 args.SetAt(0, receiver); | |
| 862 args.SetAt(1, function_name); | |
| 863 args.SetAt(2, invocation_type); | |
| 864 if (!function.IsNull()) { | |
| 865 const int total_num_parameters = function.NumParameters(); | |
| 866 const Array& array = Array::Handle(Array::New(total_num_parameters)); | |
| 867 String& param_name = String::Handle(); | |
| 868 for (int i = 0; i < total_num_parameters; i++) { | |
| 869 param_name = function.ParameterNameAt(i); | |
| 870 array.SetAt(i, param_name); | |
| 871 } | |
| 872 args.SetAt(5, array); | |
| 873 } | |
| 874 | |
| 875 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); | |
| 876 UNREACHABLE(); | |
| 877 } | |
| 878 | |
| 879 | |
| 880 static void ThrowNoSuchMethod(const Class& klass, | |
| 881 const String& function_name, | |
| 882 const Function& function, | |
| 883 const InvocationMirror::Call call, | |
| 884 const InvocationMirror::Type type) { | |
| 885 AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass)); | |
| 886 | |
| 887 ThrowNoSuchMethod(runtime_type, | |
| 888 function_name, | |
| 889 function, | |
| 890 call, | |
| 891 type); | |
| 892 UNREACHABLE(); | |
| 893 } | |
| 894 | |
| 895 | |
| 896 static void ThrowNoSuchMethod(const Library& library, | |
| 897 const String& function_name, | |
| 898 const Function& function, | |
| 899 const InvocationMirror::Call call, | |
| 900 const InvocationMirror::Type type) { | |
| 901 ThrowNoSuchMethod(Instance::null_instance(), | |
| 902 function_name, | |
| 903 function, | |
| 904 call, | |
| 905 type); | |
| 906 UNREACHABLE(); | |
| 907 } | |
| 908 | |
| 909 | |
| 910 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { | 922 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { |
| 911 // Argument 0 is the mirror, which is unused by the native. It exists | 923 // Argument 0 is the mirror, which is unused by the native. It exists |
| 912 // because this native is an instance method in order to be polymorphic | 924 // because this native is an instance method in order to be polymorphic |
| 913 // with its cousins. | 925 // with its cousins. |
| 914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 926 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 915 const Class& klass = Class::Handle(ref.GetClassReferent()); | 927 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 916 GET_NON_NULL_NATIVE_ARGUMENT( | 928 GET_NON_NULL_NATIVE_ARGUMENT( |
| 917 String, function_name, arguments->NativeArgAt(2)); | 929 String, function_name, arguments->NativeArgAt(2)); |
| 918 GET_NON_NULL_NATIVE_ARGUMENT( | 930 GET_NON_NULL_NATIVE_ARGUMENT( |
| 919 Array, positional_args, arguments->NativeArgAt(3)); | 931 Array, positional_args, arguments->NativeArgAt(3)); |
| 920 | 932 |
| 921 intptr_t number_of_arguments = positional_args.Length(); | 933 intptr_t number_of_arguments = positional_args.Length(); |
| 922 | 934 |
| 923 const Function& function = Function::Handle( | 935 const Function& function = Function::Handle( |
| 924 klass.LookupStaticFunctionAllowPrivate(function_name)); | 936 klass.LookupStaticFunctionAllowPrivate(function_name)); |
| 925 | 937 |
| 926 if (function.IsNull() || | 938 if (function.IsNull() || |
| 927 !function.AreValidArgumentCounts(number_of_arguments, | 939 !function.AreValidArgumentCounts(number_of_arguments, |
| 928 /* named_args */ 0, | 940 /* named_args */ 0, |
| 929 NULL) || | 941 NULL) || |
| 930 !function.is_visible()) { | 942 !function.is_visible()) { |
| 931 ThrowNoSuchMethod(klass, | 943 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| 932 function_name, | 944 function_name, |
| 933 function, | 945 function, |
| 934 InvocationMirror::kStatic, | 946 InvocationMirror::kStatic, |
| 935 InvocationMirror::kMethod); | 947 InvocationMirror::kMethod); |
| 936 UNREACHABLE(); | 948 UNREACHABLE(); |
| 937 } | 949 } |
| 938 | 950 |
| 939 Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 951 Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
| 940 positional_args)); | 952 positional_args)); |
| 941 if (result.IsError()) { | 953 if (result.IsError()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 956 | 968 |
| 957 // Note static fields do not have implicit getters. | 969 // Note static fields do not have implicit getters. |
| 958 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 970 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
| 959 if (field.IsNull() || FieldIsUninitialized(field)) { | 971 if (field.IsNull() || FieldIsUninitialized(field)) { |
| 960 const String& internal_getter_name = String::Handle( | 972 const String& internal_getter_name = String::Handle( |
| 961 Field::GetterName(getter_name)); | 973 Field::GetterName(getter_name)); |
| 962 const Function& getter = Function::Handle( | 974 const Function& getter = Function::Handle( |
| 963 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 975 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
| 964 | 976 |
| 965 if (getter.IsNull() || !getter.is_visible()) { | 977 if (getter.IsNull() || !getter.is_visible()) { |
| 966 ThrowNoSuchMethod(klass, | 978 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| 967 getter_name, | 979 getter_name, |
| 968 getter, | 980 getter, |
| 969 InvocationMirror::kStatic, | 981 InvocationMirror::kStatic, |
| 970 InvocationMirror::kGetter); | 982 InvocationMirror::kGetter); |
| 971 UNREACHABLE(); | 983 UNREACHABLE(); |
| 972 } | 984 } |
| 973 | 985 |
| 974 // Invoke the getter and return the result. | 986 // Invoke the getter and return the result. |
| 975 Object& result = Object::Handle( | 987 Object& result = Object::Handle( |
| 976 DartEntry::InvokeFunction(getter, Object::empty_array())); | 988 DartEntry::InvokeFunction(getter, Object::empty_array())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 995 | 1007 |
| 996 // Check for real fields and user-defined setters. | 1008 // Check for real fields and user-defined setters. |
| 997 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1009 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
| 998 if (field.IsNull()) { | 1010 if (field.IsNull()) { |
| 999 const String& internal_setter_name = String::Handle( | 1011 const String& internal_setter_name = String::Handle( |
| 1000 Field::SetterName(setter_name)); | 1012 Field::SetterName(setter_name)); |
| 1001 const Function& setter = Function::Handle( | 1013 const Function& setter = Function::Handle( |
| 1002 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1014 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
| 1003 | 1015 |
| 1004 if (setter.IsNull() || !setter.is_visible()) { | 1016 if (setter.IsNull() || !setter.is_visible()) { |
| 1005 ThrowNoSuchMethod(klass, | 1017 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| 1006 setter_name, | 1018 setter_name, |
| 1007 setter, | 1019 setter, |
| 1008 InvocationMirror::kStatic, | 1020 InvocationMirror::kStatic, |
| 1009 InvocationMirror::kSetter); | 1021 InvocationMirror::kSetter); |
| 1010 UNREACHABLE(); | 1022 UNREACHABLE(); |
| 1011 } | 1023 } |
| 1012 | 1024 |
| 1013 // Invoke the setter and return the result. | 1025 // Invoke the setter and return the result. |
| 1014 const int kNumArgs = 1; | 1026 const int kNumArgs = 1; |
| 1015 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1027 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 if (constructor.IsNull() || | 1078 if (constructor.IsNull() || |
| 1067 (!constructor.IsConstructor() && !constructor.IsFactory()) || | 1079 (!constructor.IsConstructor() && !constructor.IsFactory()) || |
| 1068 !constructor.AreValidArgumentCounts(number_of_arguments + | 1080 !constructor.AreValidArgumentCounts(number_of_arguments + |
| 1069 constructor.NumImplicitParameters(), | 1081 constructor.NumImplicitParameters(), |
| 1070 /* named args */ 0, | 1082 /* named args */ 0, |
| 1071 NULL) || | 1083 NULL) || |
| 1072 !constructor.is_visible()) { | 1084 !constructor.is_visible()) { |
| 1073 // Pretend we didn't find the constructor at all when the arity is wrong | 1085 // Pretend we didn't find the constructor at all when the arity is wrong |
| 1074 // so as to produce the same NoSuchMethodError as the non-reflective case. | 1086 // so as to produce the same NoSuchMethodError as the non-reflective case. |
| 1075 constructor = Function::null(); | 1087 constructor = Function::null(); |
| 1076 ThrowNoSuchMethod(klass, | 1088 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| 1077 internal_constructor_name, | 1089 internal_constructor_name, |
| 1078 constructor, | 1090 constructor, |
| 1079 InvocationMirror::kConstructor, | 1091 InvocationMirror::kConstructor, |
| 1080 InvocationMirror::kMethod); | 1092 InvocationMirror::kMethod); |
| 1081 UNREACHABLE(); | 1093 UNREACHABLE(); |
| 1082 } | 1094 } |
| 1083 | 1095 |
| 1084 const Object& result = | 1096 const Object& result = |
| 1085 Object::Handle(DartEntry::InvokeConstructor(klass, | 1097 Object::Handle(DartEntry::InvokeConstructor(klass, |
| 1086 constructor, | 1098 constructor, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1115 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { | 1127 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { |
| 1116 ThrowMirroredCompilationError(ambiguity_error_msg); | 1128 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1117 UNREACHABLE(); | 1129 UNREACHABLE(); |
| 1118 } | 1130 } |
| 1119 | 1131 |
| 1120 if (function.IsNull() || | 1132 if (function.IsNull() || |
| 1121 !function.AreValidArgumentCounts(number_of_arguments, | 1133 !function.AreValidArgumentCounts(number_of_arguments, |
| 1122 0, | 1134 0, |
| 1123 NULL) || | 1135 NULL) || |
| 1124 !function.is_visible()) { | 1136 !function.is_visible()) { |
| 1125 ThrowNoSuchMethod(library, | 1137 ThrowNoSuchMethod(Instance::null_instance(), |
| 1126 function_name, | 1138 function_name, |
| 1127 function, | 1139 function, |
| 1128 InvocationMirror::kTopLevel, | 1140 InvocationMirror::kTopLevel, |
| 1129 InvocationMirror::kMethod); | 1141 InvocationMirror::kMethod); |
| 1130 UNREACHABLE(); | 1142 UNREACHABLE(); |
| 1131 } | 1143 } |
| 1132 | 1144 |
| 1133 const Object& result = Object::Handle( | 1145 const Object& result = Object::Handle( |
| 1134 DartEntry::InvokeFunction(function, positional_args)); | 1146 DartEntry::InvokeFunction(function, positional_args)); |
| 1135 if (result.IsError()) { | 1147 if (result.IsError()) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 if (result.IsError()) { | 1188 if (result.IsError()) { |
| 1177 ThrowInvokeError(Error::Cast(result)); | 1189 ThrowInvokeError(Error::Cast(result)); |
| 1178 UNREACHABLE(); | 1190 UNREACHABLE(); |
| 1179 } | 1191 } |
| 1180 return result.raw(); | 1192 return result.raw(); |
| 1181 } | 1193 } |
| 1182 if (!field.IsNull()) { | 1194 if (!field.IsNull()) { |
| 1183 return field.value(); | 1195 return field.value(); |
| 1184 } | 1196 } |
| 1185 if (ambiguity_error_msg.IsNull()) { | 1197 if (ambiguity_error_msg.IsNull()) { |
| 1186 ThrowNoSuchMethod(library, | 1198 ThrowNoSuchMethod(Instance::null_instance(), |
| 1187 getter_name, | 1199 getter_name, |
| 1188 getter, | 1200 getter, |
| 1189 InvocationMirror::kTopLevel, | 1201 InvocationMirror::kTopLevel, |
| 1190 InvocationMirror::kGetter); | 1202 InvocationMirror::kGetter); |
| 1191 } else { | 1203 } else { |
| 1192 ThrowMirroredCompilationError(ambiguity_error_msg); | 1204 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1193 } | 1205 } |
| 1194 UNREACHABLE(); | 1206 UNREACHABLE(); |
| 1195 return Instance::null(); | 1207 return Instance::null(); |
| 1196 } | 1208 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1213 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); | 1225 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); |
| 1214 | 1226 |
| 1215 if (field.IsNull() && ambiguity_error_msg.IsNull()) { | 1227 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
| 1216 const String& internal_setter_name = | 1228 const String& internal_setter_name = |
| 1217 String::Handle(Field::SetterName(setter_name)); | 1229 String::Handle(Field::SetterName(setter_name)); |
| 1218 const Function& setter = Function::Handle( | 1230 const Function& setter = Function::Handle( |
| 1219 library.LookupFunctionAllowPrivate(internal_setter_name, | 1231 library.LookupFunctionAllowPrivate(internal_setter_name, |
| 1220 &ambiguity_error_msg)); | 1232 &ambiguity_error_msg)); |
| 1221 if (setter.IsNull() || !setter.is_visible()) { | 1233 if (setter.IsNull() || !setter.is_visible()) { |
| 1222 if (ambiguity_error_msg.IsNull()) { | 1234 if (ambiguity_error_msg.IsNull()) { |
| 1223 ThrowNoSuchMethod(library, | 1235 ThrowNoSuchMethod(Instance::null_instance(), |
| 1224 setter_name, | 1236 setter_name, |
| 1225 setter, | 1237 setter, |
| 1226 InvocationMirror::kTopLevel, | 1238 InvocationMirror::kTopLevel, |
| 1227 InvocationMirror::kSetter); | 1239 InvocationMirror::kSetter); |
| 1228 } else { | 1240 } else { |
| 1229 ThrowMirroredCompilationError(ambiguity_error_msg); | 1241 ThrowMirroredCompilationError(ambiguity_error_msg); |
| 1230 } | 1242 } |
| 1231 UNREACHABLE(); | 1243 UNREACHABLE(); |
| 1232 } | 1244 } |
| 1233 | 1245 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 } | 1350 } |
| 1339 | 1351 |
| 1340 | 1352 |
| 1341 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1353 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1342 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1354 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1343 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1355 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1344 return field.type(); | 1356 return field.type(); |
| 1345 } | 1357 } |
| 1346 | 1358 |
| 1347 } // namespace dart | 1359 } // namespace dart |
| OLD | NEW |