Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index 0d1a4aff997acea6285d4ef0b62f20c0ace704e3..04b5495eaf1b672a4cc64325fa76c13c3008da3f 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -357,112 +357,32 @@ static Dart_Handle CreateImplementsList(Dart_Handle intf) { |
| } |
| -static Dart_Handle CreateTypeVariableMirrorUsingApi(Dart_Handle type_var, |
| - Dart_Handle type_var_name, |
| - Dart_Handle owner_mirror) { |
| - ASSERT(Dart_IsTypeVariable(type_var)); |
| - Dart_Handle cls_name = NewString("_LocalTypeVariableMirrorImpl"); |
| - Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| - if (Dart_IsError(type)) { |
| - return type; |
| - } |
| - |
| - Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var); |
| - if (Dart_IsError(upper_bound)) { |
| - return upper_bound; |
| - } |
| - |
| - Dart_Handle args[] = { |
| - CreateMirrorReference(type_var), |
| - type_var_name, |
| - owner_mirror, |
| - CreateLazyMirror(upper_bound), |
| - }; |
| - Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| - return mirror; |
| -} |
| - |
| - |
| static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
| const Instance& owner_mirror) { |
| - Instance& retvalue = Instance::Handle(); |
| - Dart_EnterScope(); |
| - Isolate* isolate = Isolate::Current(); |
| - Dart_Handle param_handle = Api::NewHandle(isolate, param.raw()); |
| - if (Dart_IsError(param_handle)) { |
| - Dart_PropagateError(param_handle); |
| - } |
| - Dart_Handle name_handle = Api::NewHandle(isolate, param.Name()); |
| - if (Dart_IsError(name_handle)) { |
| - Dart_PropagateError(name_handle); |
| - } |
| - // Until we get rid of lazy mirrors, we must have owners. |
| - Dart_Handle owner_handle; |
| - if (owner_mirror.IsNull()) { |
| - owner_handle = Api::NewHandle(isolate, param.parameterized_class()); |
| - if (Dart_IsError(owner_handle)) { |
| - Dart_PropagateError(owner_handle); |
| - } |
| - owner_handle = CreateLazyMirror(owner_handle); |
| - if (Dart_IsError(owner_handle)) { |
| - Dart_PropagateError(owner_handle); |
| - } |
| - } else { |
| - owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); |
| - if (Dart_IsError(owner_handle)) { |
| - Dart_PropagateError(owner_handle); |
| - } |
| - } |
| - // TODO(11742): At some point the handle calls will be replaced by inlined |
| - // functionality. |
| - Dart_Handle result = CreateTypeVariableMirrorUsingApi(param_handle, |
| - name_handle, |
| - owner_handle); |
| - if (Dart_IsError(result)) { |
| - Dart_PropagateError(result); |
| - } |
| - retvalue ^= Api::UnwrapHandle(result); |
| - Dart_ExitScope(); |
| - return retvalue.raw(); |
| + const Array& args = Array::Handle(Array::New(3)); |
| + args.SetAt(0, MirrorReference::Handle(MirrorReference::New(param))); |
| + args.SetAt(1, String::Handle(param.name())); |
| + args.SetAt(2, owner_mirror); |
| + return CreateMirror(Symbols::_LocalTypeVariableMirrorImpl(), args); |
| } |
| -static Dart_Handle CreateTypeVariableMap(Dart_Handle owner, |
| - Dart_Handle owner_mirror) { |
| - ASSERT(Dart_IsClass(owner)); |
| - // TODO(turnidge): This should be an immutable map. |
| - Dart_Handle map = MapNew(); |
| - if (Dart_IsError(map)) { |
| - return map; |
| - } |
| - |
| - Dart_Handle names = Dart_GetTypeVariableNames(owner); |
| - if (Dart_IsError(names)) { |
| - return names; |
| - } |
| - intptr_t len; |
| - Dart_Handle result = Dart_ListLength(names, &len); |
| - if (Dart_IsError(result)) { |
| - return result; |
| +// We create a list in native code and let Dart code create the actual ordered |
| +// map then. |
| +static RawInstance* CreateTypeVariableList(const Class& cls, |
| + const Instance& cls_mirror) { |
| + ASSERT(cls.IsClass()); |
| + TypeArguments& args = TypeArguments::Handle(cls.type_parameters()); |
| + const Array& result = Array::Handle(Array::New(args.Length())); |
| + TypeParameter& type = TypeParameter::Handle(); |
| + Instance& mirror = Instance::Handle(); |
| + for (intptr_t i = 0; i < args.Length(); ++i) { |
| + type ^= args.TypeAt(i); |
| + ASSERT(type.IsTypeParameter()); |
| + mirror ^= CreateTypeVariableMirror(type, cls_mirror); |
| + result.SetAt(i, mirror); |
| } |
|
siva
2013/07/25 22:48:43
As discussed offline, let us investigate if we cou
|
| - for (intptr_t i = 0; i < len; i++) { |
| - Dart_Handle type_var_name = Dart_ListGetAt(names, i); |
| - Dart_Handle type_var = Dart_LookupTypeVariable(owner, type_var_name); |
| - if (Dart_IsError(type_var)) { |
| - return type_var; |
| - } |
| - ASSERT(!Dart_IsNull(type_var)); |
| - Dart_Handle type_var_mirror = |
| - CreateTypeVariableMirrorUsingApi(type_var, type_var_name, owner_mirror); |
| - if (Dart_IsError(type_var_mirror)) { |
| - return type_var_mirror; |
| - } |
| - result = MapAdd(map, type_var_name, type_var_mirror); |
| - if (Dart_IsError(result)) { |
| - return result; |
| - } |
| - } |
| - return map; |
| + return result.raw(); |
| } |
| @@ -528,10 +448,6 @@ static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf, |
| if (Dart_IsError(constructor_map)) { |
| return constructor_map; |
| } |
| - Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror); |
| - if (Dart_IsError(type_var_map)) { |
| - return type_var_map; |
| - } |
| Dart_Handle args[] = { |
| CreateMirrorReference(intf), |
| @@ -541,8 +457,7 @@ static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf, |
| CreateLazyMirror(super_class), |
| CreateImplementsList(intf), |
| CreateLazyMirror(default_class), |
| - constructor_map, |
| - type_var_map, |
| + constructor_map |
| }; |
| Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| return mirror; |
| @@ -1147,6 +1062,31 @@ DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { |
| } |
| +DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 2) { |
| + GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| + GET_NON_NULL_NATIVE_ARGUMENT(Instance, mirror, arguments->NativeArgAt(1)); |
| + const Class& klass = Class::Handle(ref.GetClassReferent()); |
| + return CreateTypeVariableList(klass, mirror); |
| +} |
| + |
| + |
| +DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) { |
| + GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| + const TypeParameter& param = TypeParameter::Handle( |
| + ref.GetTypeParameterReferent()); |
| + return CreateClassMirror(Class::Handle(param.parameterized_class()), |
| + Instance::null_instance()); |
| +} |
| + |
| + |
| +DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) { |
| + GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| + const TypeParameter& param = TypeParameter::Handle( |
| + ref.GetTypeParameterReferent()); |
| + return CreateTypeMirror(AbstractType::Handle(param.bound())); |
| +} |
| + |
| + |
| // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled |
| // exceptions. Wrap and propagate any compilation errors. |
| static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, |