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/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
11 #include "vm/object_store.h" | 11 #include "vm/object_store.h" |
12 #include "vm/parser.h" | 12 #include "vm/parser.h" |
13 #include "vm/port.h" | 13 #include "vm/port.h" |
14 #include "vm/resolver.h" | 14 #include "vm/resolver.h" |
15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 | 18 |
19 DEFINE_FLAG(bool, use_mirrored_compilation_error, false, | |
20 "Wrap compilation errors that occur during reflective access in a " | |
21 "MirroredCompilationError, rather than suspending the isolate."); | |
22 | |
23 static RawInstance* CreateMirror(const String& mirror_class_name, | 19 static RawInstance* CreateMirror(const String& mirror_class_name, |
24 const Array& constructor_arguments) { | 20 const Array& constructor_arguments) { |
25 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); | 21 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); |
26 const String& constructor_name = Symbols::Dot(); | 22 const String& constructor_name = Symbols::Dot(); |
27 | 23 |
28 const Object& result = Object::Handle( | 24 const Object& result = Object::Handle( |
29 DartLibraryCalls::InstanceCreate(mirrors_lib, | 25 DartLibraryCalls::InstanceCreate(mirrors_lib, |
30 mirror_class_name, | 26 mirror_class_name, |
31 constructor_name, | 27 constructor_name, |
32 constructor_arguments)); | 28 constructor_arguments)); |
33 ASSERT(!result.IsError()); | 29 ASSERT(!result.IsError()); |
34 return Instance::Cast(result).raw(); | 30 return Instance::Cast(result).raw(); |
35 } | 31 } |
36 | 32 |
37 | 33 |
38 static void ThrowMirroredCompilationError(const String& message) { | |
39 Array& args = Array::Handle(Array::New(1)); | |
40 args.SetAt(0, message); | |
41 | |
42 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); | |
43 UNREACHABLE(); | |
44 } | |
45 | |
46 | |
47 static void ThrowInvokeError(const Error& error) { | |
48 if (FLAG_use_mirrored_compilation_error && error.IsLanguageError()) { | |
49 // A compilation error that was delayed by lazy compilation. | |
50 const LanguageError& compilation_error = LanguageError::Cast(error); | |
51 String& message = String::Handle(compilation_error.FormatMessage()); | |
52 ThrowMirroredCompilationError(message); | |
53 UNREACHABLE(); | |
54 } | |
55 Exceptions::PropagateError(error); | |
56 UNREACHABLE(); | |
57 } | |
58 | |
59 | |
60 // Conventions: | 34 // Conventions: |
61 // * For throwing a NSM in a class klass we use its runtime type as receiver, | 35 // * For throwing a NSM in a class klass we use its runtime type as receiver, |
62 // i.e., klass.RareType(). | 36 // i.e., klass.RareType(). |
63 // * For throwing a NSM in a library, we just pass the null instance as | 37 // * For throwing a NSM in a library, we just pass the null instance as |
64 // receiver. | 38 // receiver. |
65 static void ThrowNoSuchMethod(const Instance& receiver, | 39 static void ThrowNoSuchMethod(const Instance& receiver, |
66 const String& function_name, | 40 const String& function_name, |
67 const Function& function, | 41 const Function& function, |
68 const Array& arguments, | 42 const Array& arguments, |
69 const InvocationMirror::Call call, | 43 const InvocationMirror::Call call, |
(...skipping 25 matching lines...) Expand all Loading... |
95 | 69 |
96 static void EnsureConstructorsAreCompiled(const Function& func) { | 70 static void EnsureConstructorsAreCompiled(const Function& func) { |
97 // Only generative constructors can have initializing formals. | 71 // Only generative constructors can have initializing formals. |
98 if (!func.IsConstructor()) return; | 72 if (!func.IsConstructor()) return; |
99 | 73 |
100 Isolate* isolate = Isolate::Current(); | 74 Isolate* isolate = Isolate::Current(); |
101 const Class& cls = Class::Handle(isolate, func.Owner()); | 75 const Class& cls = Class::Handle(isolate, func.Owner()); |
102 const Error& error = Error::Handle( | 76 const Error& error = Error::Handle( |
103 isolate, cls.EnsureIsFinalized(Isolate::Current())); | 77 isolate, cls.EnsureIsFinalized(Isolate::Current())); |
104 if (!error.IsNull()) { | 78 if (!error.IsNull()) { |
105 ThrowInvokeError(error); | 79 Exceptions::PropagateError(error); |
106 UNREACHABLE(); | 80 UNREACHABLE(); |
107 } | 81 } |
108 if (!func.HasCode()) { | 82 if (!func.HasCode()) { |
109 const Error& error = Error::Handle( | 83 const Error& error = Error::Handle( |
110 isolate, Compiler::CompileFunction(isolate, func)); | 84 isolate, Compiler::CompileFunction(isolate, func)); |
111 if (!error.IsNull()) { | 85 if (!error.IsNull()) { |
112 ThrowInvokeError(error); | 86 Exceptions::PropagateError(error); |
113 UNREACHABLE(); | 87 UNREACHABLE(); |
114 } | 88 } |
115 } | 89 } |
116 } | 90 } |
117 | 91 |
118 static RawInstance* CreateParameterMirrorList(const Function& func, | 92 static RawInstance* CreateParameterMirrorList(const Function& func, |
119 const Instance& owner_mirror) { | 93 const Instance& owner_mirror) { |
120 HANDLESCOPE(Isolate::Current()); | 94 HANDLESCOPE(Isolate::Current()); |
121 const intptr_t implicit_param_count = func.NumImplicitParameters(); | 95 const intptr_t implicit_param_count = func.NumImplicitParameters(); |
122 const intptr_t non_implicit_param_count = func.NumParameters() - | 96 const intptr_t non_implicit_param_count = func.NumParameters() - |
(...skipping 28 matching lines...) Expand all Loading... |
151 | 125 |
152 Array& param_descriptor = Array::Handle(); | 126 Array& param_descriptor = Array::Handle(); |
153 if (has_extra_parameter_info) { | 127 if (has_extra_parameter_info) { |
154 // Reparse the function for the following information: | 128 // Reparse the function for the following information: |
155 // * The default value of a parameter. | 129 // * The default value of a parameter. |
156 // * Whether a parameters has been deflared as final. | 130 // * Whether a parameters has been deflared as final. |
157 // * Any metadata associated with the parameter. | 131 // * Any metadata associated with the parameter. |
158 const Object& result = | 132 const Object& result = |
159 Object::Handle(Parser::ParseFunctionParameters(func)); | 133 Object::Handle(Parser::ParseFunctionParameters(func)); |
160 if (result.IsError()) { | 134 if (result.IsError()) { |
161 ThrowInvokeError(Error::Cast(result)); | 135 Exceptions::PropagateError(Error::Cast(result)); |
162 UNREACHABLE(); | 136 UNREACHABLE(); |
163 } | 137 } |
164 param_descriptor ^= result.raw(); | 138 param_descriptor ^= result.raw(); |
165 ASSERT(param_descriptor.Length() == | 139 ASSERT(param_descriptor.Length() == |
166 (Parser::kParameterEntrySize * non_implicit_param_count)); | 140 (Parser::kParameterEntrySize * non_implicit_param_count)); |
167 } | 141 } |
168 | 142 |
169 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 143 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
170 args.SetAt(2, owner_mirror); | 144 args.SetAt(2, owner_mirror); |
171 | 145 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // We represent function types as canonical signature classes. | 317 // We represent function types as canonical signature classes. |
344 return CreateFunctionTypeMirror(cls, type); | 318 return CreateFunctionTypeMirror(cls, type); |
345 } else { | 319 } else { |
346 // We represent typedefs as non-canonical signature classes. | 320 // We represent typedefs as non-canonical signature classes. |
347 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); | 321 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); |
348 } | 322 } |
349 } | 323 } |
350 | 324 |
351 const Error& error = Error::Handle(cls.EnsureIsFinalized(Isolate::Current())); | 325 const Error& error = Error::Handle(cls.EnsureIsFinalized(Isolate::Current())); |
352 if (!error.IsNull()) { | 326 if (!error.IsNull()) { |
353 ThrowInvokeError(error); | 327 Exceptions::PropagateError(error); |
354 UNREACHABLE(); | 328 UNREACHABLE(); |
355 } | 329 } |
356 | 330 |
357 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); | 331 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
358 const Bool& is_mixin_app_alias = Bool::Get(cls.is_mixin_app_alias()); | 332 const Bool& is_mixin_app_alias = Bool::Get(cls.is_mixin_app_alias()); |
359 | 333 |
360 const Array& args = Array::Handle(Array::New(8)); | 334 const Array& args = Array::Handle(Array::New(8)); |
361 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 335 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
362 args.SetAt(1, type); | 336 args.SetAt(1, type); |
363 // Note that the VM does not consider mixin application aliases to be mixin | 337 // Note that the VM does not consider mixin application aliases to be mixin |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 combinators.SetAt(i++, t); | 401 combinators.SetAt(i++, t); |
428 } | 402 } |
429 for (intptr_t j = 0; j < m; j++) { | 403 for (intptr_t j = 0; j < m; j++) { |
430 t = hide_names.At(j); | 404 t = hide_names.At(j); |
431 t = CreateCombinatorMirror(t, false); | 405 t = CreateCombinatorMirror(t, false); |
432 combinators.SetAt(i++, t); | 406 combinators.SetAt(i++, t); |
433 } | 407 } |
434 | 408 |
435 Object& metadata = Object::Handle(ns.GetMetadata()); | 409 Object& metadata = Object::Handle(ns.GetMetadata()); |
436 if (metadata.IsError()) { | 410 if (metadata.IsError()) { |
437 ThrowInvokeError(Error::Cast(metadata)); | 411 Exceptions::PropagateError(Error::Cast(metadata)); |
438 UNREACHABLE(); | 412 UNREACHABLE(); |
439 } | 413 } |
440 | 414 |
441 const Array& args = Array::Handle(Array::New(6)); | 415 const Array& args = Array::Handle(Array::New(6)); |
442 args.SetAt(0, importer); | 416 args.SetAt(0, importer); |
443 args.SetAt(1, importee_mirror); | 417 args.SetAt(1, importee_mirror); |
444 args.SetAt(2, combinators); | 418 args.SetAt(2, combinators); |
445 args.SetAt(3, prefix); | 419 args.SetAt(3, prefix); |
446 args.SetAt(4, Bool::Get(is_import)); | 420 args.SetAt(4, Bool::Get(is_import)); |
447 args.SetAt(5, metadata); | 421 args.SetAt(5, metadata); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 557 |
584 const Array& args = Array::Handle(Array::New(2)); | 558 const Array& args = Array::Handle(Array::New(2)); |
585 args.SetAt(0, library_mirrors); | 559 args.SetAt(0, library_mirrors); |
586 args.SetAt(1, isolate_mirror); | 560 args.SetAt(1, isolate_mirror); |
587 return CreateMirror(Symbols::_LocalMirrorSystem(), args); | 561 return CreateMirror(Symbols::_LocalMirrorSystem(), args); |
588 } | 562 } |
589 | 563 |
590 | 564 |
591 static RawInstance* ReturnResult(const Object& result) { | 565 static RawInstance* ReturnResult(const Object& result) { |
592 if (result.IsError()) { | 566 if (result.IsError()) { |
593 ThrowInvokeError(Error::Cast(result)); | 567 Exceptions::PropagateError(Error::Cast(result)); |
594 UNREACHABLE(); | 568 UNREACHABLE(); |
595 } | 569 } |
596 if (result.IsInstance()) { | 570 if (result.IsInstance()) { |
597 return Instance::Cast(result).raw(); | 571 return Instance::Cast(result).raw(); |
598 } | 572 } |
599 ASSERT(result.IsNull()); | 573 ASSERT(result.IsNull()); |
600 return Instance::null(); | 574 return Instance::null(); |
601 } | 575 } |
602 | 576 |
603 | 577 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 ASSERT(!instantiator.IsNull()); | 751 ASSERT(!instantiator.IsNull()); |
778 ASSERT(instantiator.IsFinalized()); | 752 ASSERT(instantiator.IsFinalized()); |
779 ASSERT(!instantiator.IsMalformed()); | 753 ASSERT(!instantiator.IsMalformed()); |
780 | 754 |
781 const TypeArguments& type_args = | 755 const TypeArguments& type_args = |
782 TypeArguments::Handle(instantiator.arguments()); | 756 TypeArguments::Handle(instantiator.arguments()); |
783 Error& bound_error = Error::Handle(); | 757 Error& bound_error = Error::Handle(); |
784 AbstractType& result = | 758 AbstractType& result = |
785 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); | 759 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); |
786 if (!bound_error.IsNull()) { | 760 if (!bound_error.IsNull()) { |
787 ThrowInvokeError(bound_error); | 761 Exceptions::PropagateError(bound_error); |
788 UNREACHABLE(); | 762 UNREACHABLE(); |
789 } | 763 } |
790 ASSERT(result.IsFinalized()); | 764 ASSERT(result.IsFinalized()); |
791 return result.Canonicalize(); | 765 return result.Canonicalize(); |
792 } | 766 } |
793 | 767 |
794 | 768 |
795 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { | 769 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { |
796 return CreateMirrorSystem(); | 770 return CreateMirrorSystem(); |
797 } | 771 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 library ^= decl.raw(); | 840 library ^= decl.raw(); |
867 } else if (decl.IsTypeParameter()) { | 841 } else if (decl.IsTypeParameter()) { |
868 klass ^= TypeParameter::Cast(decl).parameterized_class(); | 842 klass ^= TypeParameter::Cast(decl).parameterized_class(); |
869 library = klass.library(); | 843 library = klass.library(); |
870 } else { | 844 } else { |
871 return Object::empty_array().raw(); | 845 return Object::empty_array().raw(); |
872 } | 846 } |
873 | 847 |
874 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 848 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
875 if (metadata.IsError()) { | 849 if (metadata.IsError()) { |
876 ThrowInvokeError(Error::Cast(metadata)); | 850 Exceptions::PropagateError(Error::Cast(metadata)); |
877 } | 851 } |
878 return metadata.raw(); | 852 return metadata.raw(); |
879 } | 853 } |
880 | 854 |
881 | 855 |
882 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { | 856 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { |
883 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 857 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
884 owner_mirror, | 858 owner_mirror, |
885 arguments->NativeArgAt(0)); | 859 arguments->NativeArgAt(0)); |
886 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 860 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 929 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
956 ASSERT(!type.IsMalformed()); | 930 ASSERT(!type.IsMalformed()); |
957 ASSERT(type.IsFinalized()); | 931 ASSERT(type.IsFinalized()); |
958 if (!type.HasResolvedTypeClass()) { | 932 if (!type.HasResolvedTypeClass()) { |
959 Exceptions::ThrowArgumentError(type); | 933 Exceptions::ThrowArgumentError(type); |
960 UNREACHABLE(); | 934 UNREACHABLE(); |
961 } | 935 } |
962 const Class& cls = Class::Handle(type.type_class()); | 936 const Class& cls = Class::Handle(type.type_class()); |
963 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 937 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); |
964 if (!error.IsNull()) { | 938 if (!error.IsNull()) { |
965 ThrowInvokeError(error); | 939 Exceptions::PropagateError(error); |
966 } | 940 } |
967 | 941 |
968 return cls.interfaces(); | 942 return cls.interfaces(); |
969 } | 943 } |
970 | 944 |
971 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { | 945 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { |
972 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 946 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
973 ASSERT(!type.IsMalformed()); | 947 ASSERT(!type.IsMalformed()); |
974 ASSERT(type.IsFinalized()); | 948 ASSERT(type.IsFinalized()); |
975 if (!type.HasResolvedTypeClass()) { | 949 if (!type.HasResolvedTypeClass()) { |
976 Exceptions::ThrowArgumentError(type); | 950 Exceptions::ThrowArgumentError(type); |
977 UNREACHABLE(); | 951 UNREACHABLE(); |
978 } | 952 } |
979 const Class& cls = Class::Handle(type.type_class()); | 953 const Class& cls = Class::Handle(type.type_class()); |
980 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 954 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); |
981 if (!error.IsNull()) { | 955 if (!error.IsNull()) { |
982 ThrowInvokeError(error); | 956 Exceptions::PropagateError(error); |
983 } | 957 } |
984 | 958 |
985 Array& interfaces = Array::Handle(cls.interfaces()); | 959 Array& interfaces = Array::Handle(cls.interfaces()); |
986 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); | 960 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); |
987 AbstractType& interface = AbstractType::Handle(); | 961 AbstractType& interface = AbstractType::Handle(); |
988 | 962 |
989 for (int i = 0; i < interfaces.Length(); i++) { | 963 for (int i = 0; i < interfaces.Length(); i++) { |
990 interface ^= interfaces.At(i); | 964 interface ^= interfaces.At(i); |
991 interface = InstantiateType(interface, type); | 965 interface = InstantiateType(interface, type); |
992 interfaces_inst.SetAt(i, interface); | 966 interfaces_inst.SetAt(i, interface); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 | 1008 |
1035 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { | 1009 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { |
1036 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 1010 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
1037 owner_mirror, | 1011 owner_mirror, |
1038 arguments->NativeArgAt(0)); | 1012 arguments->NativeArgAt(0)); |
1039 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1013 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1040 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1014 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1041 | 1015 |
1042 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1016 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
1043 if (!error.IsNull()) { | 1017 if (!error.IsNull()) { |
1044 ThrowInvokeError(error); | 1018 Exceptions::PropagateError(error); |
1045 } | 1019 } |
1046 | 1020 |
1047 const Array& fields = Array::Handle(klass.fields()); | 1021 const Array& fields = Array::Handle(klass.fields()); |
1048 const intptr_t num_fields = fields.Length(); | 1022 const intptr_t num_fields = fields.Length(); |
1049 | 1023 |
1050 const Array& functions = Array::Handle(klass.functions()); | 1024 const Array& functions = Array::Handle(klass.functions()); |
1051 const intptr_t num_functions = functions.Length(); | 1025 const intptr_t num_functions = functions.Length(); |
1052 | 1026 |
1053 Instance& member_mirror = Instance::Handle(); | 1027 Instance& member_mirror = Instance::Handle(); |
1054 const GrowableObjectArray& member_mirrors = GrowableObjectArray::Handle( | 1028 const GrowableObjectArray& member_mirrors = GrowableObjectArray::Handle( |
(...skipping 26 matching lines...) Expand all Loading... |
1081 | 1055 |
1082 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { | 1056 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { |
1083 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 1057 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
1084 owner_mirror, | 1058 owner_mirror, |
1085 arguments->NativeArgAt(0)); | 1059 arguments->NativeArgAt(0)); |
1086 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1060 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
1087 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1061 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1088 | 1062 |
1089 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1063 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); |
1090 if (!error.IsNull()) { | 1064 if (!error.IsNull()) { |
1091 ThrowInvokeError(error); | 1065 Exceptions::PropagateError(error); |
1092 } | 1066 } |
1093 | 1067 |
1094 const Array& functions = Array::Handle(klass.functions()); | 1068 const Array& functions = Array::Handle(klass.functions()); |
1095 const intptr_t num_functions = functions.Length(); | 1069 const intptr_t num_functions = functions.Length(); |
1096 | 1070 |
1097 Instance& constructor_mirror = Instance::Handle(); | 1071 Instance& constructor_mirror = Instance::Handle(); |
1098 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( | 1072 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( |
1099 GrowableObjectArray::New(num_functions)); | 1073 GrowableObjectArray::New(num_functions)); |
1100 | 1074 |
1101 Function& func = Function::Handle(); | 1075 Function& func = Function::Handle(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 function, | 1277 function, |
1304 getter_name, | 1278 getter_name, |
1305 getter_args, | 1279 getter_args, |
1306 getter_args_descriptor)); | 1280 getter_args_descriptor)); |
1307 // Replace the closure as the receiver in the arguments list. | 1281 // Replace the closure as the receiver in the arguments list. |
1308 args.SetAt(0, getter_result); | 1282 args.SetAt(0, getter_result); |
1309 // Call the closure. | 1283 // Call the closure. |
1310 const Object& call_result = | 1284 const Object& call_result = |
1311 Object::Handle(DartEntry::InvokeClosure(args, args_descriptor)); | 1285 Object::Handle(DartEntry::InvokeClosure(args, args_descriptor)); |
1312 if (call_result.IsError()) { | 1286 if (call_result.IsError()) { |
1313 ThrowInvokeError(Error::Cast(call_result)); | 1287 Exceptions::PropagateError(Error::Cast(call_result)); |
1314 UNREACHABLE(); | 1288 UNREACHABLE(); |
1315 } | 1289 } |
1316 return call_result.raw(); | 1290 return call_result.raw(); |
1317 } | 1291 } |
1318 } | 1292 } |
1319 | 1293 |
1320 // Found an ordinary method. | 1294 // Found an ordinary method. |
1321 return InvokeDynamicFunction(reflectee, | 1295 return InvokeDynamicFunction(reflectee, |
1322 function, | 1296 function, |
1323 function_name, | 1297 function_name, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 if (function.IsNull()) { | 1379 if (function.IsNull()) { |
1406 // Didn't find a method: try to find a getter and invoke call on its result. | 1380 // Didn't find a method: try to find a getter and invoke call on its result. |
1407 const String& getter_name = | 1381 const String& getter_name = |
1408 String::Handle(Field::GetterName(function_name)); | 1382 String::Handle(Field::GetterName(function_name)); |
1409 function = klass.LookupStaticFunction(getter_name); | 1383 function = klass.LookupStaticFunction(getter_name); |
1410 if (!function.IsNull()) { | 1384 if (!function.IsNull()) { |
1411 // Invoke the getter. | 1385 // Invoke the getter. |
1412 const Object& getter_result = Object::Handle( | 1386 const Object& getter_result = Object::Handle( |
1413 DartEntry::InvokeFunction(function, Object::empty_array())); | 1387 DartEntry::InvokeFunction(function, Object::empty_array())); |
1414 if (getter_result.IsError()) { | 1388 if (getter_result.IsError()) { |
1415 ThrowInvokeError(Error::Cast(getter_result)); | 1389 Exceptions::PropagateError(Error::Cast(getter_result)); |
1416 UNREACHABLE(); | 1390 UNREACHABLE(); |
1417 } | 1391 } |
1418 // Make room for the closure (receiver) in the argument list. | 1392 // Make room for the closure (receiver) in the argument list. |
1419 intptr_t numArgs = args.Length(); | 1393 intptr_t numArgs = args.Length(); |
1420 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); | 1394 const Array& call_args = Array::Handle(Array::New(numArgs + 1)); |
1421 Object& temp = Object::Handle(); | 1395 Object& temp = Object::Handle(); |
1422 for (int i = 0; i < numArgs; i++) { | 1396 for (int i = 0; i < numArgs; i++) { |
1423 temp = args.At(i); | 1397 temp = args.At(i); |
1424 call_args.SetAt(i + 1, temp); | 1398 call_args.SetAt(i + 1, temp); |
1425 } | 1399 } |
1426 call_args.SetAt(0, getter_result); | 1400 call_args.SetAt(0, getter_result); |
1427 const Array& call_args_descriptor_array = | 1401 const Array& call_args_descriptor_array = |
1428 Array::Handle(ArgumentsDescriptor::New(call_args.Length(), arg_names)); | 1402 Array::Handle(ArgumentsDescriptor::New(call_args.Length(), arg_names)); |
1429 // Call the closure. | 1403 // Call the closure. |
1430 const Object& call_result = Object::Handle( | 1404 const Object& call_result = Object::Handle( |
1431 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); | 1405 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); |
1432 if (call_result.IsError()) { | 1406 if (call_result.IsError()) { |
1433 ThrowInvokeError(Error::Cast(call_result)); | 1407 Exceptions::PropagateError(Error::Cast(call_result)); |
1434 UNREACHABLE(); | 1408 UNREACHABLE(); |
1435 } | 1409 } |
1436 return call_result.raw(); | 1410 return call_result.raw(); |
1437 } | 1411 } |
1438 } | 1412 } |
1439 | 1413 |
1440 const Array& args_descriptor_array = | 1414 const Array& args_descriptor_array = |
1441 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1415 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1442 | 1416 |
1443 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1417 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1444 | 1418 |
1445 if (function.IsNull() || | 1419 if (function.IsNull() || |
1446 !function.AreValidArguments(args_descriptor, NULL) || | 1420 !function.AreValidArguments(args_descriptor, NULL) || |
1447 !function.is_visible()) { | 1421 !function.is_visible()) { |
1448 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1422 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1449 function_name, | 1423 function_name, |
1450 function, | 1424 function, |
1451 Object::null_array(), | 1425 Object::null_array(), |
1452 InvocationMirror::kStatic, | 1426 InvocationMirror::kStatic, |
1453 InvocationMirror::kMethod); | 1427 InvocationMirror::kMethod); |
1454 UNREACHABLE(); | 1428 UNREACHABLE(); |
1455 } | 1429 } |
1456 | 1430 |
1457 Object& result = Object::Handle( | 1431 Object& result = Object::Handle( |
1458 DartEntry::InvokeFunction(function, args, args_descriptor_array)); | 1432 DartEntry::InvokeFunction(function, args, args_descriptor_array)); |
1459 if (result.IsError()) { | 1433 if (result.IsError()) { |
1460 ThrowInvokeError(Error::Cast(result)); | 1434 Exceptions::PropagateError(Error::Cast(result)); |
1461 UNREACHABLE(); | 1435 UNREACHABLE(); |
1462 } | 1436 } |
1463 return result.raw(); | 1437 return result.raw(); |
1464 } | 1438 } |
1465 | 1439 |
1466 | 1440 |
1467 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { | 1441 DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { |
1468 // Argument 0 is the mirror, which is unused by the native. It exists | 1442 // Argument 0 is the mirror, which is unused by the native. It exists |
1469 // because this native is an instance method in order to be polymorphic | 1443 // because this native is an instance method in order to be polymorphic |
1470 // with its cousins. | 1444 // with its cousins. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 args, | 1478 args, |
1505 InvocationMirror::kStatic, | 1479 InvocationMirror::kStatic, |
1506 InvocationMirror::kSetter); | 1480 InvocationMirror::kSetter); |
1507 UNREACHABLE(); | 1481 UNREACHABLE(); |
1508 } | 1482 } |
1509 | 1483 |
1510 // Invoke the setter and return the result. | 1484 // Invoke the setter and return the result. |
1511 Object& result = Object::Handle( | 1485 Object& result = Object::Handle( |
1512 DartEntry::InvokeFunction(setter, args)); | 1486 DartEntry::InvokeFunction(setter, args)); |
1513 if (result.IsError()) { | 1487 if (result.IsError()) { |
1514 ThrowInvokeError(Error::Cast(result)); | 1488 Exceptions::PropagateError(Error::Cast(result)); |
1515 UNREACHABLE(); | 1489 UNREACHABLE(); |
1516 } | 1490 } |
1517 return result.raw(); | 1491 return result.raw(); |
1518 } | 1492 } |
1519 | 1493 |
1520 if (field.is_final()) { | 1494 if (field.is_final()) { |
1521 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), | 1495 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), |
1522 internal_setter_name, | 1496 internal_setter_name, |
1523 setter, | 1497 setter, |
1524 Object::null_array(), | 1498 Object::null_array(), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor); | 1570 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor); |
1597 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType()); | 1571 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType()); |
1598 | 1572 |
1599 if (!redirect_type.IsInstantiated()) { | 1573 if (!redirect_type.IsInstantiated()) { |
1600 // The type arguments of the redirection type are instantiated from the | 1574 // The type arguments of the redirection type are instantiated from the |
1601 // type arguments of the type reflected by the class mirror. | 1575 // type arguments of the type reflected by the class mirror. |
1602 Error& bound_error = Error::Handle(); | 1576 Error& bound_error = Error::Handle(); |
1603 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, | 1577 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, |
1604 &bound_error); | 1578 &bound_error); |
1605 if (!bound_error.IsNull()) { | 1579 if (!bound_error.IsNull()) { |
1606 ThrowInvokeError(bound_error); | 1580 Exceptions::PropagateError(bound_error); |
1607 UNREACHABLE(); | 1581 UNREACHABLE(); |
1608 } | 1582 } |
1609 redirect_type ^= redirect_type.Canonicalize(); | 1583 redirect_type ^= redirect_type.Canonicalize(); |
1610 } | 1584 } |
1611 | 1585 |
1612 type = redirect_type.raw(); | 1586 type = redirect_type.raw(); |
1613 type_arguments = redirect_type.arguments(); | 1587 type_arguments = redirect_type.arguments(); |
1614 | 1588 |
1615 redirected_constructor = lookup_constructor.RedirectionTarget(); | 1589 redirected_constructor = lookup_constructor.RedirectionTarget(); |
1616 ASSERT(!redirected_constructor.IsNull()); | 1590 ASSERT(!redirected_constructor.IsNull()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 // Factories get type arguments. | 1641 // Factories get type arguments. |
1668 args.SetAt(0, type_arguments); | 1642 args.SetAt(0, type_arguments); |
1669 } | 1643 } |
1670 | 1644 |
1671 // Invoke the constructor and return the new object. | 1645 // Invoke the constructor and return the new object. |
1672 const Object& result = | 1646 const Object& result = |
1673 Object::Handle(DartEntry::InvokeFunction(redirected_constructor, | 1647 Object::Handle(DartEntry::InvokeFunction(redirected_constructor, |
1674 args, | 1648 args, |
1675 args_descriptor_array)); | 1649 args_descriptor_array)); |
1676 if (result.IsError()) { | 1650 if (result.IsError()) { |
1677 ThrowInvokeError(Error::Cast(result)); | 1651 Exceptions::PropagateError(Error::Cast(result)); |
1678 UNREACHABLE(); | 1652 UNREACHABLE(); |
1679 } | 1653 } |
1680 | 1654 |
1681 // Factories may return null. | 1655 // Factories may return null. |
1682 ASSERT(result.IsInstance() || result.IsNull()); | 1656 ASSERT(result.IsInstance() || result.IsNull()); |
1683 | 1657 |
1684 if (redirected_constructor.IsConstructor()) { | 1658 if (redirected_constructor.IsConstructor()) { |
1685 return new_object.raw(); | 1659 return new_object.raw(); |
1686 } else { | 1660 } else { |
1687 return result.raw(); | 1661 return result.raw(); |
(...skipping 28 matching lines...) Expand all Loading... |
1716 temp = args.At(i); | 1690 temp = args.At(i); |
1717 call_args.SetAt(i + 1, temp); | 1691 call_args.SetAt(i + 1, temp); |
1718 } | 1692 } |
1719 call_args.SetAt(0, getter_result); | 1693 call_args.SetAt(0, getter_result); |
1720 const Array& call_args_descriptor_array = Array::Handle( | 1694 const Array& call_args_descriptor_array = Array::Handle( |
1721 ArgumentsDescriptor::New(call_args.Length(), arg_names)); | 1695 ArgumentsDescriptor::New(call_args.Length(), arg_names)); |
1722 // Call closure. | 1696 // Call closure. |
1723 const Object& call_result = Object::Handle( | 1697 const Object& call_result = Object::Handle( |
1724 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); | 1698 DartEntry::InvokeClosure(call_args, call_args_descriptor_array)); |
1725 if (call_result.IsError()) { | 1699 if (call_result.IsError()) { |
1726 ThrowInvokeError(Error::Cast(call_result)); | 1700 Exceptions::PropagateError(Error::Cast(call_result)); |
1727 UNREACHABLE(); | 1701 UNREACHABLE(); |
1728 } | 1702 } |
1729 return call_result.raw(); | 1703 return call_result.raw(); |
1730 } | 1704 } |
1731 } | 1705 } |
1732 | 1706 |
1733 const Array& args_descriptor_array = | 1707 const Array& args_descriptor_array = |
1734 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); | 1708 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); |
1735 ArgumentsDescriptor args_descriptor(args_descriptor_array); | 1709 ArgumentsDescriptor args_descriptor(args_descriptor_array); |
1736 | 1710 |
1737 if (function.IsNull() || | 1711 if (function.IsNull() || |
1738 !function.AreValidArguments(args_descriptor, NULL) || | 1712 !function.AreValidArguments(args_descriptor, NULL) || |
1739 !function.is_visible()) { | 1713 !function.is_visible()) { |
1740 ThrowNoSuchMethod(Instance::null_instance(), | 1714 ThrowNoSuchMethod(Instance::null_instance(), |
1741 function_name, | 1715 function_name, |
1742 function, | 1716 function, |
1743 Object::null_array(), | 1717 Object::null_array(), |
1744 InvocationMirror::kTopLevel, | 1718 InvocationMirror::kTopLevel, |
1745 InvocationMirror::kMethod); | 1719 InvocationMirror::kMethod); |
1746 UNREACHABLE(); | 1720 UNREACHABLE(); |
1747 } | 1721 } |
1748 | 1722 |
1749 const Object& result = Object::Handle( | 1723 const Object& result = Object::Handle( |
1750 DartEntry::InvokeFunction(function, args, args_descriptor_array)); | 1724 DartEntry::InvokeFunction(function, args, args_descriptor_array)); |
1751 if (result.IsError()) { | 1725 if (result.IsError()) { |
1752 ThrowInvokeError(Error::Cast(result)); | 1726 Exceptions::PropagateError(Error::Cast(result)); |
1753 UNREACHABLE(); | 1727 UNREACHABLE(); |
1754 } | 1728 } |
1755 return result.raw(); | 1729 return result.raw(); |
1756 } | 1730 } |
1757 | 1731 |
1758 | 1732 |
1759 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeGetter, 3) { | 1733 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeGetter, 3) { |
1760 // Argument 0 is the mirror, which is unused by the native. It exists | 1734 // Argument 0 is the mirror, which is unused by the native. It exists |
1761 // because this native is an instance method in order to be polymorphic | 1735 // because this native is an instance method in order to be polymorphic |
1762 // with its cousins. | 1736 // with its cousins. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1799 args, | 1773 args, |
1800 InvocationMirror::kTopLevel, | 1774 InvocationMirror::kTopLevel, |
1801 InvocationMirror::kSetter); | 1775 InvocationMirror::kSetter); |
1802 UNREACHABLE(); | 1776 UNREACHABLE(); |
1803 } | 1777 } |
1804 | 1778 |
1805 // Invoke the setter and return the result. | 1779 // Invoke the setter and return the result. |
1806 const Object& result = Object::Handle( | 1780 const Object& result = Object::Handle( |
1807 DartEntry::InvokeFunction(setter, args)); | 1781 DartEntry::InvokeFunction(setter, args)); |
1808 if (result.IsError()) { | 1782 if (result.IsError()) { |
1809 ThrowInvokeError(Error::Cast(result)); | 1783 Exceptions::PropagateError(Error::Cast(result)); |
1810 UNREACHABLE(); | 1784 UNREACHABLE(); |
1811 } | 1785 } |
1812 return result.raw(); | 1786 return result.raw(); |
1813 } | 1787 } |
1814 | 1788 |
1815 if (field.is_final()) { | 1789 if (field.is_final()) { |
1816 ThrowNoSuchMethod(Instance::null_instance(), | 1790 ThrowNoSuchMethod(Instance::null_instance(), |
1817 internal_setter_name, | 1791 internal_setter_name, |
1818 setter, | 1792 setter, |
1819 Object::null_array(), | 1793 Object::null_array(), |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 } | 1956 } |
1983 | 1957 |
1984 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { | 1958 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { |
1985 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 1959 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
1986 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 1960 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
1987 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); | 1961 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); |
1988 } | 1962 } |
1989 | 1963 |
1990 | 1964 |
1991 } // namespace dart | 1965 } // namespace dart |
OLD | NEW |