| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 args.SetAt(0, field_ref); | 149 args.SetAt(0, field_ref); |
| 150 args.SetAt(1, name); | 150 args.SetAt(1, name); |
| 151 args.SetAt(2, owner_mirror); | 151 args.SetAt(2, owner_mirror); |
| 152 args.SetAt(3, Instance::Handle()); // Null for type. | 152 args.SetAt(3, Instance::Handle()); // Null for type. |
| 153 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 153 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 154 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 154 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 155 | 155 |
| 156 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 156 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 157 } | 157 } |
| 158 | 158 |
| 159 static RawFunction* CallMethod(const Class& cls) { |
| 160 if (cls.IsSignatureClass()) { |
| 161 return cls.signature_function(); |
| 162 } |
| 163 |
| 164 Class& lookup_cls = Class::Handle(cls.raw()); |
| 165 Function& call_function = Function::Handle(); |
| 166 do { |
| 167 call_function = lookup_cls.LookupDynamicFunction(Symbols::Call()); |
| 168 if (!call_function.IsNull()) { |
| 169 return call_function.raw(); |
| 170 } |
| 171 lookup_cls = lookup_cls.SuperClass(); |
| 172 } while (!lookup_cls.IsNull()); |
| 173 return Function::null(); |
| 174 } |
| 159 | 175 |
| 160 static RawInstance* CreateClassMirror(const Class& cls, | 176 static RawInstance* CreateClassMirror(const Class& cls, |
| 161 const AbstractType& type, | 177 const AbstractType& type, |
| 162 const Instance& owner_mirror) { | 178 const Instance& owner_mirror) { |
| 163 if (cls.IsSignatureClass()) { | 179 if (cls.IsSignatureClass()) { |
| 164 if (cls.IsCanonicalSignatureClass()) { | 180 if (cls.IsCanonicalSignatureClass()) { |
| 165 // We represent function types as canonical signature classes. | 181 // We represent function types as canonical signature classes. |
| 166 return CreateFunctionTypeMirror(cls, type); | 182 return CreateFunctionTypeMirror(cls, type); |
| 167 } else { | 183 } else { |
| 168 // We represent typedefs as non-canonical signature classes. | 184 // We represent typedefs as non-canonical signature classes. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 359 } |
| 344 | 360 |
| 345 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 361 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 346 if (metadata.IsError()) { | 362 if (metadata.IsError()) { |
| 347 ThrowInvokeError(Error::Cast(metadata)); | 363 ThrowInvokeError(Error::Cast(metadata)); |
| 348 } | 364 } |
| 349 return metadata.raw(); | 365 return metadata.raw(); |
| 350 } | 366 } |
| 351 | 367 |
| 352 | 368 |
| 369 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { |
| 370 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
| 371 owner_mirror, |
| 372 arguments->NativeArgAt(0)); |
| 373 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 374 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 375 const Function& func = Function::Handle(CallMethod(cls)); |
| 376 ASSERT(!func.IsNull()); |
| 377 return CreateMethodMirror(func, owner_mirror); |
| 378 } |
| 379 |
| 380 |
| 353 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 381 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { |
| 354 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 382 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 355 const Class& cls = Class::Handle(ref.GetClassReferent()); | 383 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 356 const Function& func = Function::Handle(cls.signature_function()); | 384 const Function& func = Function::Handle(CallMethod(cls)); |
| 385 ASSERT(!func.IsNull()); |
| 357 return CreateParameterMirrorList(func); | 386 return CreateParameterMirrorList(func); |
| 358 } | 387 } |
| 359 | 388 |
| 360 | 389 |
| 361 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 390 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 362 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 391 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 363 const Class& cls = Class::Handle(ref.GetClassReferent()); | 392 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 364 const Function& func = Function::Handle(cls.signature_function()); | 393 const Function& func = Function::Handle(CallMethod(cls)); |
| 394 ASSERT(!func.IsNull()); |
| 365 return func.result_type(); | 395 return func.result_type(); |
| 366 } | 396 } |
| 367 | 397 |
| 368 | 398 |
| 369 static bool FieldIsUninitialized(const Field& field) { | 399 static bool FieldIsUninitialized(const Field& field) { |
| 370 ASSERT(!field.IsNull()); | 400 ASSERT(!field.IsNull()); |
| 371 | 401 |
| 372 // Return getter method for uninitialized fields, rather than the | 402 // Return getter method for uninitialized fields, rather than the |
| 373 // field object, since the value in the field object will not be | 403 // field object, since the value in the field object will not be |
| 374 // initialized until the first time the getter is invoked. | 404 // initialized until the first time the getter is invoked. |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 if (obj.IsError()) { | 800 if (obj.IsError()) { |
| 771 ThrowInvokeError(Error::Cast(obj)); | 801 ThrowInvokeError(Error::Cast(obj)); |
| 772 UNREACHABLE(); | 802 UNREACHABLE(); |
| 773 } | 803 } |
| 774 return obj.raw(); | 804 return obj.raw(); |
| 775 } | 805 } |
| 776 | 806 |
| 777 | 807 |
| 778 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { | 808 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { |
| 779 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 809 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 780 ASSERT(closure.IsClosure()); | 810 ASSERT(!closure.IsNull()); |
| 781 | 811 |
| 782 const Function& func = Function::Handle(Closure::function(closure)); | 812 Function& function = Function::Handle(); |
| 783 return CreateMethodMirror(func, Instance::null_instance()); | 813 bool callable = closure.IsCallable(&function, NULL); |
| 814 ASSERT(callable); |
| 815 |
| 816 return CreateMethodMirror(function, Instance::null_instance()); |
| 784 } | 817 } |
| 785 | 818 |
| 786 | 819 |
| 787 static void ThrowNoSuchMethod(const Instance& receiver, | 820 static void ThrowNoSuchMethod(const Instance& receiver, |
| 788 const String& function_name, | 821 const String& function_name, |
| 789 const Function& function, | 822 const Function& function, |
| 790 const InvocationMirror::Call call, | 823 const InvocationMirror::Call call, |
| 791 const InvocationMirror::Type type) { | 824 const InvocationMirror::Type type) { |
| 792 const Smi& invocation_type = Smi::Handle(Smi::New( | 825 const Smi& invocation_type = Smi::Handle(Smi::New( |
| 793 InvocationMirror::EncodeType(call, type))); | 826 InvocationMirror::EncodeType(call, type))); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 } | 1273 } |
| 1241 | 1274 |
| 1242 | 1275 |
| 1243 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1276 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1244 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1277 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1245 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1278 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1246 return field.type(); | 1279 return field.type(); |
| 1247 } | 1280 } |
| 1248 | 1281 |
| 1249 } // namespace dart | 1282 } // namespace dart |
| OLD | NEW |