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)); |
129 | |
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 | |
60 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 138 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
61 args.SetAt(2, owner_mirror); | 139 args.SetAt(2, owner_mirror); |
140 | |
62 Smi& pos = Smi::Handle(); | 141 Smi& pos = Smi::Handle(); |
63 String& name = String::Handle(); | 142 String& name = String::Handle(); |
64 Instance& param = Instance::Handle(); | 143 Instance& param = Instance::Handle(); |
144 Bool& is_final = Bool::Handle(); | |
145 Object& default_value = Object::Handle(); | |
146 | |
147 // Reparse the function for the following information: | |
148 // * The default value of a parameter. | |
149 // * Whether a parameters has been deflared as final. | |
150 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); | |
151 if (result.IsError()) { | |
152 ThrowInvokeError(Error::Cast(result)); | |
153 UNREACHABLE(); | |
154 } | |
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 | |
68 args.SetAt(1, name); | 165 args.SetAt(1, name); |
siva
2013/08/27 00:31:02
document here as to why arg 2 is not set.
| |
69 args.SetAt(3, pos); | 166 args.SetAt(3, pos); |
70 args.SetAt(4, (i >= index_of_first_optional_param) ? | 167 args.SetAt(4, (i >= index_of_first_optional_param) ? |
71 Bool::True() : Bool::False()); | 168 Bool::True() : Bool::False()); |
72 args.SetAt(5, (i >= index_of_first_named_param) ? | 169 args.SetAt(5, (i >= index_of_first_named_param) ? |
73 Bool::True() : Bool::False()); | 170 Bool::True() : Bool::False()); |
171 args.SetAt(6, is_final); | |
172 args.SetAt(7, default_value); | |
74 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | 173 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
75 results.SetAt(i, param); | 174 results.SetAt(i, param); |
76 } | 175 } |
77 results.MakeImmutable(); | 176 results.MakeImmutable(); |
78 return results.raw(); | 177 return results.raw(); |
79 } | 178 } |
80 | 179 |
81 | 180 |
82 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, | 181 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
83 const Instance& owner_mirror) { | 182 const Instance& owner_mirror) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 303 |
205 const Array& args = Array::Handle(Array::New(4)); | 304 const Array& args = Array::Handle(Array::New(4)); |
206 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 305 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
207 args.SetAt(1, type); | 306 args.SetAt(1, type); |
208 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 307 args.SetAt(2, String::Handle(cls.UserVisibleName())); |
209 args.SetAt(3, is_generic); | 308 args.SetAt(3, is_generic); |
210 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 309 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
211 } | 310 } |
212 | 311 |
213 | 312 |
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) { | 313 static RawInstance* CreateLibraryMirror(const Library& lib) { |
224 const Array& args = Array::Handle(Array::New(3)); | 314 const Array& args = Array::Handle(Array::New(3)); |
225 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 315 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
226 String& str = String::Handle(); | 316 String& str = String::Handle(); |
227 str = lib.name(); | 317 str = lib.name(); |
228 args.SetAt(1, str); | 318 args.SetAt(1, str); |
229 str = lib.url(); | 319 str = lib.url(); |
230 args.SetAt(2, str); | 320 args.SetAt(2, str); |
231 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); | 321 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); |
232 } | 322 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 } | 415 } |
326 } | 416 } |
327 | 417 |
328 | 418 |
329 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { | 419 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
330 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 420 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
331 return CreateTypeMirror(type); | 421 return CreateTypeMirror(type); |
332 } | 422 } |
333 | 423 |
334 | 424 |
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) { | 425 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { |
358 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); | 426 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); |
359 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); | 427 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); |
360 return Bool::Get(a.referent() == b.referent()); | 428 return Bool::Get(a.referent() == b.referent()); |
361 } | 429 } |
362 | 430 |
363 | 431 |
364 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { | 432 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { |
365 const MirrorReference& decl_ref = | 433 const MirrorReference& decl_ref = |
366 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 434 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
842 ASSERT(!closure.IsNull()); | 910 ASSERT(!closure.IsNull()); |
843 | 911 |
844 Function& function = Function::Handle(); | 912 Function& function = Function::Handle(); |
845 bool callable = closure.IsCallable(&function, NULL); | 913 bool callable = closure.IsCallable(&function, NULL); |
846 ASSERT(callable); | 914 ASSERT(callable); |
847 | 915 |
848 return CreateMethodMirror(function, Instance::null_instance()); | 916 return CreateMethodMirror(function, Instance::null_instance()); |
849 } | 917 } |
850 | 918 |
851 | 919 |
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) { | 920 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 4) { |
911 // Argument 0 is the mirror, which is unused by the native. It exists | 921 // 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 | 922 // because this native is an instance method in order to be polymorphic |
913 // with its cousins. | 923 // with its cousins. |
914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 924 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
915 const Class& klass = Class::Handle(ref.GetClassReferent()); | 925 const Class& klass = Class::Handle(ref.GetClassReferent()); |
916 GET_NON_NULL_NATIVE_ARGUMENT( | 926 GET_NON_NULL_NATIVE_ARGUMENT( |
917 String, function_name, arguments->NativeArgAt(2)); | 927 String, function_name, arguments->NativeArgAt(2)); |
918 GET_NON_NULL_NATIVE_ARGUMENT( | 928 GET_NON_NULL_NATIVE_ARGUMENT( |
919 Array, positional_args, arguments->NativeArgAt(3)); | 929 Array, positional_args, arguments->NativeArgAt(3)); |
920 | 930 |
921 intptr_t number_of_arguments = positional_args.Length(); | 931 intptr_t number_of_arguments = positional_args.Length(); |
922 | 932 |
923 const Function& function = Function::Handle( | 933 const Function& function = Function::Handle( |
924 klass.LookupStaticFunctionAllowPrivate(function_name)); | 934 klass.LookupStaticFunctionAllowPrivate(function_name)); |
925 | 935 |
926 if (function.IsNull() || | 936 if (function.IsNull() || |
927 !function.AreValidArgumentCounts(number_of_arguments, | 937 !function.AreValidArgumentCounts(number_of_arguments, |
928 /* named_args */ 0, | 938 /* named_args */ 0, |
929 NULL) || | 939 NULL) || |
930 !function.is_visible()) { | 940 !function.is_visible()) { |
931 ThrowNoSuchMethod(klass, | 941 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
932 function_name, | 942 function_name, |
933 function, | 943 function, |
934 InvocationMirror::kStatic, | 944 InvocationMirror::kStatic, |
935 InvocationMirror::kMethod); | 945 InvocationMirror::kMethod); |
936 UNREACHABLE(); | 946 UNREACHABLE(); |
937 } | 947 } |
938 | 948 |
939 Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 949 Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
940 positional_args)); | 950 positional_args)); |
941 if (result.IsError()) { | 951 if (result.IsError()) { |
(...skipping 14 matching lines...) Expand all Loading... | |
956 | 966 |
957 // Note static fields do not have implicit getters. | 967 // Note static fields do not have implicit getters. |
958 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); | 968 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); |
959 if (field.IsNull() || FieldIsUninitialized(field)) { | 969 if (field.IsNull() || FieldIsUninitialized(field)) { |
960 const String& internal_getter_name = String::Handle( | 970 const String& internal_getter_name = String::Handle( |
961 Field::GetterName(getter_name)); | 971 Field::GetterName(getter_name)); |
962 const Function& getter = Function::Handle( | 972 const Function& getter = Function::Handle( |
963 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); | 973 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
964 | 974 |
965 if (getter.IsNull() || !getter.is_visible()) { | 975 if (getter.IsNull() || !getter.is_visible()) { |
966 ThrowNoSuchMethod(klass, | 976 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
967 getter_name, | 977 getter_name, |
968 getter, | 978 getter, |
969 InvocationMirror::kStatic, | 979 InvocationMirror::kStatic, |
970 InvocationMirror::kGetter); | 980 InvocationMirror::kGetter); |
971 UNREACHABLE(); | 981 UNREACHABLE(); |
972 } | 982 } |
973 | 983 |
974 // Invoke the getter and return the result. | 984 // Invoke the getter and return the result. |
975 Object& result = Object::Handle( | 985 Object& result = Object::Handle( |
976 DartEntry::InvokeFunction(getter, Object::empty_array())); | 986 DartEntry::InvokeFunction(getter, Object::empty_array())); |
(...skipping 18 matching lines...) Expand all Loading... | |
995 | 1005 |
996 // Check for real fields and user-defined setters. | 1006 // Check for real fields and user-defined setters. |
997 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); | 1007 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); |
998 if (field.IsNull()) { | 1008 if (field.IsNull()) { |
999 const String& internal_setter_name = String::Handle( | 1009 const String& internal_setter_name = String::Handle( |
1000 Field::SetterName(setter_name)); | 1010 Field::SetterName(setter_name)); |
1001 const Function& setter = Function::Handle( | 1011 const Function& setter = Function::Handle( |
1002 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); | 1012 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
1003 | 1013 |
1004 if (setter.IsNull() || !setter.is_visible()) { | 1014 if (setter.IsNull() || !setter.is_visible()) { |
1005 ThrowNoSuchMethod(klass, | 1015 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
1006 setter_name, | 1016 setter_name, |
1007 setter, | 1017 setter, |
1008 InvocationMirror::kStatic, | 1018 InvocationMirror::kStatic, |
1009 InvocationMirror::kSetter); | 1019 InvocationMirror::kSetter); |
1010 UNREACHABLE(); | 1020 UNREACHABLE(); |
1011 } | 1021 } |
1012 | 1022 |
1013 // Invoke the setter and return the result. | 1023 // Invoke the setter and return the result. |
1014 const int kNumArgs = 1; | 1024 const int kNumArgs = 1; |
1015 const Array& args = Array::Handle(Array::New(kNumArgs)); | 1025 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() || | 1076 if (constructor.IsNull() || |
1067 (!constructor.IsConstructor() && !constructor.IsFactory()) || | 1077 (!constructor.IsConstructor() && !constructor.IsFactory()) || |
1068 !constructor.AreValidArgumentCounts(number_of_arguments + | 1078 !constructor.AreValidArgumentCounts(number_of_arguments + |
1069 constructor.NumImplicitParameters(), | 1079 constructor.NumImplicitParameters(), |
1070 /* named args */ 0, | 1080 /* named args */ 0, |
1071 NULL) || | 1081 NULL) || |
1072 !constructor.is_visible()) { | 1082 !constructor.is_visible()) { |
1073 // Pretend we didn't find the constructor at all when the arity is wrong | 1083 // 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. | 1084 // so as to produce the same NoSuchMethodError as the non-reflective case. |
1075 constructor = Function::null(); | 1085 constructor = Function::null(); |
1076 ThrowNoSuchMethod(klass, | 1086 ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
1077 internal_constructor_name, | 1087 internal_constructor_name, |
1078 constructor, | 1088 constructor, |
1079 InvocationMirror::kConstructor, | 1089 InvocationMirror::kConstructor, |
1080 InvocationMirror::kMethod); | 1090 InvocationMirror::kMethod); |
1081 UNREACHABLE(); | 1091 UNREACHABLE(); |
1082 } | 1092 } |
1083 | 1093 |
1084 const Object& result = | 1094 const Object& result = |
1085 Object::Handle(DartEntry::InvokeConstructor(klass, | 1095 Object::Handle(DartEntry::InvokeConstructor(klass, |
1086 constructor, | 1096 constructor, |
(...skipping 28 matching lines...) Expand all Loading... | |
1115 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { | 1125 if (function.IsNull() && !ambiguity_error_msg.IsNull()) { |
1116 ThrowMirroredCompilationError(ambiguity_error_msg); | 1126 ThrowMirroredCompilationError(ambiguity_error_msg); |
1117 UNREACHABLE(); | 1127 UNREACHABLE(); |
1118 } | 1128 } |
1119 | 1129 |
1120 if (function.IsNull() || | 1130 if (function.IsNull() || |
1121 !function.AreValidArgumentCounts(number_of_arguments, | 1131 !function.AreValidArgumentCounts(number_of_arguments, |
1122 0, | 1132 0, |
1123 NULL) || | 1133 NULL) || |
1124 !function.is_visible()) { | 1134 !function.is_visible()) { |
1125 ThrowNoSuchMethod(library, | 1135 ThrowNoSuchMethod(Instance::null_instance(), |
1126 function_name, | 1136 function_name, |
1127 function, | 1137 function, |
1128 InvocationMirror::kTopLevel, | 1138 InvocationMirror::kTopLevel, |
1129 InvocationMirror::kMethod); | 1139 InvocationMirror::kMethod); |
1130 UNREACHABLE(); | 1140 UNREACHABLE(); |
1131 } | 1141 } |
1132 | 1142 |
1133 const Object& result = Object::Handle( | 1143 const Object& result = Object::Handle( |
1134 DartEntry::InvokeFunction(function, positional_args)); | 1144 DartEntry::InvokeFunction(function, positional_args)); |
1135 if (result.IsError()) { | 1145 if (result.IsError()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 if (result.IsError()) { | 1186 if (result.IsError()) { |
1177 ThrowInvokeError(Error::Cast(result)); | 1187 ThrowInvokeError(Error::Cast(result)); |
1178 UNREACHABLE(); | 1188 UNREACHABLE(); |
1179 } | 1189 } |
1180 return result.raw(); | 1190 return result.raw(); |
1181 } | 1191 } |
1182 if (!field.IsNull()) { | 1192 if (!field.IsNull()) { |
1183 return field.value(); | 1193 return field.value(); |
1184 } | 1194 } |
1185 if (ambiguity_error_msg.IsNull()) { | 1195 if (ambiguity_error_msg.IsNull()) { |
1186 ThrowNoSuchMethod(library, | 1196 ThrowNoSuchMethod(Instance::null_instance(), |
1187 getter_name, | 1197 getter_name, |
1188 getter, | 1198 getter, |
1189 InvocationMirror::kTopLevel, | 1199 InvocationMirror::kTopLevel, |
1190 InvocationMirror::kGetter); | 1200 InvocationMirror::kGetter); |
1191 } else { | 1201 } else { |
1192 ThrowMirroredCompilationError(ambiguity_error_msg); | 1202 ThrowMirroredCompilationError(ambiguity_error_msg); |
1193 } | 1203 } |
1194 UNREACHABLE(); | 1204 UNREACHABLE(); |
1195 return Instance::null(); | 1205 return Instance::null(); |
1196 } | 1206 } |
(...skipping 16 matching lines...) Expand all Loading... | |
1213 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); | 1223 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg)); |
1214 | 1224 |
1215 if (field.IsNull() && ambiguity_error_msg.IsNull()) { | 1225 if (field.IsNull() && ambiguity_error_msg.IsNull()) { |
1216 const String& internal_setter_name = | 1226 const String& internal_setter_name = |
1217 String::Handle(Field::SetterName(setter_name)); | 1227 String::Handle(Field::SetterName(setter_name)); |
1218 const Function& setter = Function::Handle( | 1228 const Function& setter = Function::Handle( |
1219 library.LookupFunctionAllowPrivate(internal_setter_name, | 1229 library.LookupFunctionAllowPrivate(internal_setter_name, |
1220 &ambiguity_error_msg)); | 1230 &ambiguity_error_msg)); |
1221 if (setter.IsNull() || !setter.is_visible()) { | 1231 if (setter.IsNull() || !setter.is_visible()) { |
1222 if (ambiguity_error_msg.IsNull()) { | 1232 if (ambiguity_error_msg.IsNull()) { |
1223 ThrowNoSuchMethod(library, | 1233 ThrowNoSuchMethod(Instance::null_instance(), |
1224 setter_name, | 1234 setter_name, |
1225 setter, | 1235 setter, |
1226 InvocationMirror::kTopLevel, | 1236 InvocationMirror::kTopLevel, |
1227 InvocationMirror::kSetter); | 1237 InvocationMirror::kSetter); |
1228 } else { | 1238 } else { |
1229 ThrowMirroredCompilationError(ambiguity_error_msg); | 1239 ThrowMirroredCompilationError(ambiguity_error_msg); |
1230 } | 1240 } |
1231 UNREACHABLE(); | 1241 UNREACHABLE(); |
1232 } | 1242 } |
1233 | 1243 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1338 } | 1348 } |
1339 | 1349 |
1340 | 1350 |
1341 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1351 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
1342 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1352 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
1343 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1353 const Field& field = Field::Handle(ref.GetFieldReferent()); |
1344 return field.type(); | 1354 return field.type(); |
1345 } | 1355 } |
1346 | 1356 |
1347 } // namespace dart | 1357 } // namespace dart |
OLD | NEW |