Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index b42a00a9232d22c6ffcaa653d5cb3d683f51926d..854a2458946aa2ad92d96b3bdccdc525d7b0b819 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -29,15 +29,6 @@ static RawInstance* CreateMirror(const String& mirror_class_name, |
| } |
| -// Note a "raw type" is not the same as a RawType. |
| -static RawAbstractType* RawTypeOfClass(const Class& cls) { |
|
rmacnak
2013/09/11 21:10:21
Moved to a method on Class because it is also need
|
| - Type& type = Type::Handle(Type::New(cls, |
| - Object::null_abstract_type_arguments(), |
| - Scanner::kDummyTokenIndex)); |
| - return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); |
| -} |
| - |
| - |
| static void ThrowMirroredCompilationError(const String& message) { |
| Array& args = Array::Handle(Array::New(1)); |
| args.SetAt(0, message); |
| @@ -663,7 +654,7 @@ DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { |
| !RawObject::IsImplementationClassId(klass.id())) { |
| if (klass.NumTypeParameters() == 0) { |
| // Include runtime type for non-generics only. |
| - type = RawTypeOfClass(klass); |
| + type = klass.BasicType(); |
| } else { |
| type = AbstractType::null(); |
| } |
| @@ -967,7 +958,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) { |
| if (function.IsNull() || |
| !function.AreValidArguments(args_descriptor, NULL) || |
| !function.is_visible()) { |
| - ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| + ThrowNoSuchMethod(AbstractType::Handle(klass.BasicType()), |
| function_name, |
| function, |
| InvocationMirror::kStatic, |
| @@ -1002,7 +993,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeGetter, 3) { |
| klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); |
| if (getter.IsNull() || !getter.is_visible()) { |
| - ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| + ThrowNoSuchMethod(AbstractType::Handle(klass.BasicType()), |
| getter_name, |
| getter, |
| InvocationMirror::kStatic, |
| @@ -1041,7 +1032,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { |
| klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); |
| if (setter.IsNull() || !setter.is_visible()) { |
| - ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| + ThrowNoSuchMethod(AbstractType::Handle(klass.BasicType()), |
| setter_name, |
| setter, |
| InvocationMirror::kStatic, |
| @@ -1077,13 +1068,14 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeSetter, 4) { |
| } |
| -DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 4) { |
| +DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 5) { |
| GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| const Class& klass = Class::Handle(ref.GetClassReferent()); |
| + GET_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(1)); |
| GET_NON_NULL_NATIVE_ARGUMENT( |
| - String, constructor_name, arguments->NativeArgAt(1)); |
| - GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(2)); |
| - GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(3)); |
| + String, constructor_name, arguments->NativeArgAt(2)); |
| + GET_NON_NULL_NATIVE_ARGUMENT(Array, explicit_args, arguments->NativeArgAt(3)); |
| + GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); |
| // By convention, the static function implementing a named constructor 'C' |
| // for class 'A' is labeled 'A.C', and the static function implementing the |
| @@ -1106,7 +1098,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 4) { |
| // Pretend we didn't find the constructor at all when the arity is wrong |
| // so as to produce the same NoSuchMethodError as the non-reflective case. |
| lookup_constructor = Function::null(); |
| - ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| + ThrowNoSuchMethod(AbstractType::Handle(klass.BasicType()), |
| internal_constructor_name, |
| lookup_constructor, |
| InvocationMirror::kConstructor, |
| @@ -1147,7 +1139,7 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 4) { |
| // Pretend we didn't find the constructor at all when the arity is wrong |
| // so as to produce the same NoSuchMethodError as the non-reflective case. |
| redirected_constructor = Function::null(); |
| - ThrowNoSuchMethod(AbstractType::Handle(RawTypeOfClass(klass)), |
| + ThrowNoSuchMethod(AbstractType::Handle(klass.BasicType()), |
| internal_constructor_name, |
| redirected_constructor, |
| InvocationMirror::kConstructor, |
| @@ -1155,19 +1147,30 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 4) { |
| UNREACHABLE(); |
| } |
| + if (type.IsNull()) { |
| + // If the ClassMirror is on the declaration of a generic class. |
| + type ^= klass.BasicType(); |
| + } |
| + const AbstractTypeArguments& type_arguments = |
| + AbstractTypeArguments::Handle(type.arguments()); |
| + |
| Instance& new_object = Instance::Handle(); |
| if (redirected_constructor.IsConstructor()) { |
| // Constructors get the uninitialized object and a constructor phase. Note |
| // we have delayed allocation until after the function type and argument |
| // matching checks. |
| new_object = Instance::New(redirected_klass); |
| + if (!type_arguments.IsNull()) { |
| + // The type arguments will be null if the class has no type parameters, in |
| + // which case the following call would fail because there is no slot |
| + // reserved in the object for the type vector. |
| + new_object.SetTypeArguments(type_arguments); |
|
regis
2013/09/11 21:37:40
Who is checking that this type_argument vector has
|
| + } |
| args.SetAt(0, new_object); |
| args.SetAt(1, Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
| } else { |
| // Factories get type arguments. |
| - // TODO(12921): Should we allow the user to specify type arguments? Use type |
| - // arguments from the mirror? |
| - args.SetAt(0, Object::null_abstract_type_arguments()); |
| + args.SetAt(0, type_arguments); |
| } |
| // Invoke the constructor and return the new object. |
| @@ -1350,7 +1353,7 @@ DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { |
| AbstractType& type = AbstractType::Handle(); |
| if (owner.NumTypeParameters() == 0) { |
| // Include runtime type for non-generics only. |
| - type = RawTypeOfClass(owner); |
| + type = owner.BasicType(); |
| } |
| return CreateClassMirror(owner, type, Object::null_instance()); |
| } |