Chromium Code Reviews| Index: sdk/lib/_internal/lib/js_mirrors.dart |
| diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart |
| index 002865d56e9cbba0c43b4502b35e0f461118022f..42e37b04634291f7bb00e8cd7a4bc71d8bf14ecb 100644 |
| --- a/sdk/lib/_internal/lib/js_mirrors.dart |
| +++ b/sdk/lib/_internal/lib/js_mirrors.dart |
| @@ -477,18 +477,20 @@ TypeMirror reflectType(Type key) { |
| return reflectClassByMangledName(getMangledTypeName(key)); |
| } |
| -TypeMirror reflectClassByMangledName(String mangledName) { |
| +TypeMirror reflectClassByMangledName(String mangledName, |
| + {ClassMirror context}) { |
|
ahe
2013/11/21 15:15:33
I'm not sure about this. Let's talk face to face t
|
| String unmangledName = mangledGlobalNames[mangledName]; |
| if (unmangledName == null) unmangledName = mangledName; |
| - return reflectClassByName(s(unmangledName), mangledName); |
| + return reflectClassByName(s(unmangledName), mangledName, context); |
| } |
| var classMirrors; |
| -TypeMirror reflectClassByName(Symbol symbol, String mangledName) { |
| +TypeMirror reflectClassByName(Symbol symbol, String mangledName, |
| + ClassMirror context) { |
|
Johnni Winther
2013/11/25 07:19:20
Either both or none of [reflectClassByName] and [r
zarah
2013/12/19 10:53:34
Done.
|
| if (classMirrors == null) classMirrors = JsCache.allocate(); |
| var mirror = JsCache.fetch(classMirrors, mangledName); |
| - if (mirror != null) return mirror; |
| + if (mirror != null && mirror is! JsMixinApplication) return mirror; |
| disableTreeShaking(); |
| int typeArgIndex = mangledName.indexOf("<"); |
| if (typeArgIndex != -1) { |
| @@ -537,7 +539,7 @@ TypeMirror reflectClassByName(Symbol symbol, String mangledName) { |
| var superclassName = fields.split(';')[0]; |
| var mixins = superclassName.split('+'); |
| if (mixins.length > 1 && mangledGlobalNames[mangledName] == null) { |
| - mirror = reflectMixinApplication(mixins, mangledName); |
| + mirror = reflectMixinApplication(mixins, mangledName, context); |
| } else { |
| mirror = new JsClassMirror( |
| symbol, mangledName, constructorOrInterceptor, fields, fieldsMetadata); |
| @@ -619,31 +621,32 @@ Map<Symbol, Mirror> filterMembers(List<MethodMirror> methods, |
| int counter = 0; |
| -ClassMirror reflectMixinApplication(mixinNames, String mangledName) { |
| +ClassMirror reflectMixinApplication(mixinNames, String mangledName, |
| + DeclarationMirror context) { |
| disableTreeShaking(); |
| var mixins = []; |
| for (String mangledName in mixinNames) { |
| - mixins.add(reflectClassByMangledName(mangledName)); |
| + mixins.add(reflectClassByMangledName(mangledName, context: context)); |
| } |
| var it = mixins.iterator; |
| it.moveNext(); |
| var superclass = it.current; |
| while (it.moveNext()) { |
| - superclass = new JsMixinApplication(superclass, it.current, mangledName); |
| + superclass = new JsMixinApplication(mangledName, context); |
| } |
| return superclass; |
| } |
| class JsMixinApplication extends JsTypeMirror with JsObjectMirror |
| implements ClassMirror { |
| - final ClassMirror superclass; |
| - final ClassMirror mixin; |
| + ClassMirror _superclass; |
| + ClassMirror _mixin; |
| + ClassMirror _context; |
|
Johnni Winther
2013/11/25 07:19:20
Make this final.
zarah
2013/12/19 10:53:34
Done.
|
| Symbol _cachedSimpleName; |
| + String _mangledName; |
| - JsMixinApplication(ClassMirror superclass, ClassMirror mixin, |
| - String mangledName) |
| - : this.superclass = superclass, |
| - this.mixin = mixin, |
| + JsMixinApplication(String mangledName, this._context) |
|
Johnni Winther
2013/11/25 07:19:20
Assert that _context is not Null.
zarah
2013/12/19 10:53:34
Done.
|
| + : this._mangledName = mangledName, |
| super(s(mangledName)); |
| String get _prettyName => 'ClassMirror'; |
| @@ -658,8 +661,26 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror |
| Symbol get qualifiedName => simpleName; |
| - // TODO(ahe): Remove this method, only here to silence warning. |
| - get _mixin => mixin; |
| + ClassMirror _getTypeAtTypeInformationIndex(int index) { |
| + List<int> typeInformation = |
| + JS('List|Null', 'init.typeInformation[#]', _mangledName); |
| + if (typeInformation != null) { |
| + var type = getMetadata(typeInformation[index]); |
| + return typeMirrorFromRuntimeTypeRepresentation(_context, type); |
| + } |
| + return null; |
| + } |
| + |
| + ClassMirror get superclass { |
| + if (_superclass != null) return _superclass; |
| + return _superclass = _getTypeAtTypeInformationIndex(0); |
| + } |
| + |
| + ClassMirror get mixin { |
| + if (_mixin != null) return _mixin; |
| + var mixin = _getTypeAtTypeInformationIndex(1); |
| + return _mixin = mixin; |
| + } |
| Map<Symbol, Mirror> get members => _mixin.members; |
| @@ -704,14 +725,11 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror |
| "Can't instantiate mixin application '${n(qualifiedName)}'"); |
| } |
| - bool get isOriginalDeclaration => true; |
| + bool get isOriginalDeclaration => false; |
| ClassMirror get originalDeclaration => this; |
|
Johnni Winther
2013/11/25 07:19:20
These can't be true: Either it is the original dec
zarah
2013/12/19 10:53:34
Done.
|
| - // TODO(ahe): Implement this. |
| - List<TypeVariableMirror> get typeVariables { |
| - throw new UnimplementedError(); |
| - } |
| + List<TypeVariableMirror> get typeVariables => const <TypeVariableMirror>[]; |
| List<TypeMirror> get typeArguments => const <TypeMirror>[]; |
| } |
| @@ -1037,7 +1055,6 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror implements ClassMirror |
| ClassMirror get superclass { |
| if (_superclass != null) return _superclass; |
| - |
| List<int> typeInformation = |
| JS('List|Null', 'init.typeInformation[#]', _class._mangledName); |
| assert(typeInformation != null); |
| @@ -1356,7 +1373,7 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror |
| if (mixins.length != 2) { |
| throw new RuntimeError('Strange mixin: $_fieldsDescriptor'); |
| } |
| - _superclass = reflectClassByMangledName(mixins[0]); |
| + _superclass = reflectClassByMangledName(mixins[0], context: this); |
| } else { |
| // Use _superclass == this to represent class with no superclass |
| // (Object). |
| @@ -1950,11 +1967,22 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation( |
| representation = runtimeTypeToString(type); |
| } |
| } else { |
| - String substituteTypeVariable(int index) { |
| + getTypeArgument(int index) { |
| TypeVariable typeVariable = getMetadata(index); |
| int variableIndex = |
| findTypeVariableIndex(ownerClass.typeVariables, typeVariable.name); |
| - var typeArgument = ownerClass.typeArguments[variableIndex]; |
| + return ownerClass.typeArguments[variableIndex]; |
| + } |
| + |
| + if (type is int) { |
| + // [type] represents a type variable used as type argument for example |
| + // the type argument of Bar: class Foo<T> extends Bar<T> {} |
| + TypeMirror typeArgument = getTypeArgument(type); |
| + if (typeArgument is JsTypeVariableMirror) |
| + return typeArgument; |
| + } |
| + String substituteTypeVariable(int index) { |
| + var typeArgument = getTypeArgument(index); |
| assert(typeArgument is JsClassMirror || |
| typeArgument is JsTypeBoundClassMirror); |
| return typeArgument._mangledName; |
| @@ -1963,7 +1991,9 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation( |
| runtimeTypeToString(type, onTypeVariable: substituteTypeVariable); |
| } |
| if (representation != null) { |
| - return reflectType(createRuntimeType(representation)); |
| + return reflectClassByMangledName( |
| + getMangledTypeName(createRuntimeType(representation)), |
| + context: ownerClass); |
| } |
| return reflectClass(Function); |
| } |