Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
| 6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/port.h" | 10 #include "vm/port.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 100 |
| 101 static RawInstance* CreateTypedefMirror(const Class& cls, | 101 static RawInstance* CreateTypedefMirror(const Class& cls, |
| 102 const Instance& owner_mirror) { | 102 const Instance& owner_mirror) { |
| 103 const Array& args = Array::Handle(Array::New(3)); | 103 const Array& args = Array::Handle(Array::New(3)); |
| 104 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 104 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 105 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 105 args.SetAt(1, String::Handle(cls.UserVisibleName())); |
| 106 args.SetAt(2, owner_mirror); | 106 args.SetAt(2, owner_mirror); |
| 107 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); | 107 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 static RawInstance* CreateFunctionTypeMirror(const Class& cls, |
| 111 static RawInstance* CreateFunctionTypeMirror(const Class& cls) { | 111 const Instance& owner_mirror) { |
| 112 const Array& args = Array::Handle(Array::New(1)); | 112 const Array& args = Array::Handle(Array::New(2)); |
| 113 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 113 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 114 args.SetAt(1, owner_mirror); | |
| 114 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 115 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
| 115 } | 116 } |
| 116 | 117 |
| 118 static RawInstance* CreateClosureTypeMirror(const Class& cls) { | |
| 119 const Array& args = Array::Handle(Array::New(1)); | |
| 120 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | |
| 121 return CreateMirror(Symbols::_LocalClosureTypeMirrorImpl(), args); | |
| 122 } | |
| 117 | 123 |
| 124 | |
| 118 static RawInstance* CreateMethodMirror(const Function& func, | 125 static RawInstance* CreateMethodMirror(const Function& func, |
| 119 const Instance& owner_mirror) { | 126 const Instance& owner_mirror) { |
| 120 const Array& args = Array::Handle(Array::New(12)); | 127 const Array& args = Array::Handle(Array::New(12)); |
| 121 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 128 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 122 args.SetAt(1, String::Handle(func.UserVisibleName())); | 129 args.SetAt(1, String::Handle(func.UserVisibleName())); |
| 123 args.SetAt(2, owner_mirror); | 130 args.SetAt(2, owner_mirror); |
| 124 args.SetAt(3, func.is_static() ? Bool::True() : Bool::False()); | 131 args.SetAt(3, func.is_static() ? Bool::True() : Bool::False()); |
| 125 args.SetAt(4, func.is_abstract() ? Bool::True() : Bool::False()); | 132 args.SetAt(4, func.is_abstract() ? Bool::True() : Bool::False()); |
| 126 args.SetAt(5, func.IsGetterFunction() ? Bool::True() : Bool::False()); | 133 args.SetAt(5, func.IsGetterFunction() ? Bool::True() : Bool::False()); |
| 127 args.SetAt(6, func.IsSetterFunction() ? Bool::True() : Bool::False()); | 134 args.SetAt(6, func.IsSetterFunction() ? Bool::True() : Bool::False()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 146 args.SetAt(0, field_ref); | 153 args.SetAt(0, field_ref); |
| 147 args.SetAt(1, name); | 154 args.SetAt(1, name); |
| 148 args.SetAt(2, owner_mirror); | 155 args.SetAt(2, owner_mirror); |
| 149 args.SetAt(3, Instance::Handle()); // Null for type. | 156 args.SetAt(3, Instance::Handle()); // Null for type. |
| 150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 157 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 158 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 152 | 159 |
| 153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 160 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 154 } | 161 } |
| 155 | 162 |
| 163 static RawFunction* CallMethod(const Class& cls) { | |
|
rmacnak
2013/08/06 20:22:31
Compare Instance::IsCallable().
| |
| 164 if (cls.IsSignatureClass()) { | |
| 165 return cls.signature_function(); | |
| 166 } | |
| 167 | |
| 168 Class& lookup_cls = Class::Handle(cls.raw()); | |
| 169 Function& call_function = Function::Handle(); | |
| 170 do { | |
| 171 call_function = lookup_cls.LookupDynamicFunction(Symbols::Call()); | |
| 172 if (!call_function.IsNull()) { | |
| 173 return call_function.raw(); | |
| 174 } | |
| 175 lookup_cls = lookup_cls.SuperClass(); | |
| 176 } while (!lookup_cls.IsNull()); | |
| 177 return Function::null(); | |
| 178 } | |
| 156 | 179 |
| 157 static RawInstance* CreateClassMirror(const Class& cls, | 180 static RawInstance* CreateClassMirror(const Class& cls, |
| 158 const Instance& owner_mirror) { | 181 const Instance& owner_mirror) { |
| 159 if (cls.IsSignatureClass()) { | 182 if (cls.IsSignatureClass()) { |
| 160 if (cls.IsCanonicalSignatureClass()) { | 183 if (cls.IsCanonicalSignatureClass()) { |
| 161 // We represent function types as canonical signature classes. | 184 // We represent function types as canonical signature classes. |
| 162 return CreateFunctionTypeMirror(cls); | 185 return CreateClosureTypeMirror(cls); |
| 163 } else { | 186 } else { |
| 164 // We represent typedefs as non-canonical signature classes. | 187 // We represent typedefs as non-canonical signature classes. |
| 165 return CreateTypedefMirror(cls, owner_mirror); | 188 return CreateTypedefMirror(cls, owner_mirror); |
| 166 } | 189 } |
| 167 } | 190 } |
| 168 | 191 |
| 192 const Function& call_function = Function::Handle(CallMethod(cls)); | |
| 193 if (!call_function.IsNull()) { | |
| 194 // A user-defined class that implements the call operator. | |
| 195 return CreateFunctionTypeMirror(cls, owner_mirror); | |
| 196 } | |
| 197 | |
| 169 const Array& args = Array::Handle(Array::New(2)); | 198 const Array& args = Array::Handle(Array::New(2)); |
| 170 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 199 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 171 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 200 args.SetAt(1, String::Handle(cls.UserVisibleName())); |
| 172 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 201 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 173 } | 202 } |
| 174 | 203 |
| 175 | 204 |
| 176 static RawInstance* CreateLibraryMirror(const Library& lib) { | 205 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 177 const Array& args = Array::Handle(Array::New(3)); | 206 const Array& args = Array::Handle(Array::New(3)); |
| 178 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 207 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 345 } |
| 317 | 346 |
| 318 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 347 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 319 if (metadata.IsError()) { | 348 if (metadata.IsError()) { |
| 320 ThrowInvokeError(Error::Cast(metadata)); | 349 ThrowInvokeError(Error::Cast(metadata)); |
| 321 } | 350 } |
| 322 return metadata.raw(); | 351 return metadata.raw(); |
| 323 } | 352 } |
| 324 | 353 |
| 325 | 354 |
| 355 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { | |
| 356 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | |
| 357 owner_mirror, | |
| 358 arguments->NativeArgAt(0)); | |
| 359 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | |
| 360 const Class& cls = Class::Handle(ref.GetClassReferent()); | |
| 361 const Function& func = Function::Handle(CallMethod(cls)); | |
| 362 return CreateMethodMirror(func, owner_mirror); | |
| 363 } | |
| 364 | |
| 365 | |
| 326 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 366 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { |
| 327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 367 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 328 const Class& cls = Class::Handle(ref.GetClassReferent()); | 368 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 329 const Function& func = Function::Handle(cls.signature_function()); | 369 const Function& func = Function::Handle(CallMethod(cls)); |
| 330 return CreateParameterMirrorList(func); | 370 return CreateParameterMirrorList(func); |
| 331 } | 371 } |
| 332 | 372 |
| 333 | 373 |
| 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 374 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 375 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 336 const Class& cls = Class::Handle(ref.GetClassReferent()); | 376 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 337 const Function& func = Function::Handle(cls.signature_function()); | 377 const Function& func = Function::Handle(CallMethod(cls)); |
| 338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 378 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 339 return CreateTypeMirror(return_type); | 379 return CreateTypeMirror(return_type); |
| 340 } | 380 } |
| 341 | 381 |
| 342 | 382 |
| 343 static bool FieldIsUninitialized(const Field& field) { | 383 static bool FieldIsUninitialized(const Field& field) { |
| 344 ASSERT(!field.IsNull()); | 384 ASSERT(!field.IsNull()); |
| 345 | 385 |
| 346 // Return getter method for uninitialized fields, rather than the | 386 // Return getter method for uninitialized fields, rather than the |
| 347 // field object, since the value in the field object will not be | 387 // field object, since the value in the field object will not be |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 if (obj.IsError()) { | 756 if (obj.IsError()) { |
| 717 ThrowInvokeError(Error::Cast(obj)); | 757 ThrowInvokeError(Error::Cast(obj)); |
| 718 UNREACHABLE(); | 758 UNREACHABLE(); |
| 719 } | 759 } |
| 720 return obj.raw(); | 760 return obj.raw(); |
| 721 } | 761 } |
| 722 | 762 |
| 723 | 763 |
| 724 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { | 764 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { |
| 725 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 765 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 726 ASSERT(closure.IsClosure()); | 766 ASSERT(!closure.IsNull()); |
| 727 | 767 |
| 728 const Function& func = Function::Handle(Closure::function(closure)); | 768 Function& function = Function::Handle(); |
| 729 return CreateMethodMirror(func, Instance::null_instance()); | 769 bool callable = closure.IsCallable(&function, NULL); |
|
rmacnak
2013/08/06 20:22:31
Use CallMethod() instead?
| |
| 770 ASSERT(callable); | |
| 771 | |
| 772 return CreateMethodMirror(function, Instance::null_instance()); | |
| 730 } | 773 } |
| 731 | 774 |
| 732 | 775 |
| 733 static void ThrowNoSuchMethod(const Instance& receiver, | 776 static void ThrowNoSuchMethod(const Instance& receiver, |
| 734 const String& function_name, | 777 const String& function_name, |
| 735 const Function& function, | 778 const Function& function, |
| 736 const InvocationMirror::Call call, | 779 const InvocationMirror::Call call, |
| 737 const InvocationMirror::Type type) { | 780 const InvocationMirror::Type type) { |
| 738 const Smi& invocation_type = Smi::Handle(Smi::New( | 781 const Smi& invocation_type = Smi::Handle(Smi::New( |
| 739 InvocationMirror::EncodeType(call, type))); | 782 InvocationMirror::EncodeType(call, type))); |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1193 | 1236 |
| 1194 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1237 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1195 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1238 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1196 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1239 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1197 | 1240 |
| 1198 const AbstractType& type = AbstractType::Handle(field.type()); | 1241 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1199 return CreateTypeMirror(type); | 1242 return CreateTypeMirror(type); |
| 1200 } | 1243 } |
| 1201 | 1244 |
| 1202 } // namespace dart | 1245 } // namespace dart |
| OLD | NEW |