Chromium Code Reviews| Index: pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart |
| diff --git a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart |
| index cb46e8892fe93206a8c4039082df70af341ce65c..3abbfb173de35fcb0b677fc64b8377bbee859b32 100644 |
| --- a/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart |
| +++ b/pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart |
| @@ -311,12 +311,22 @@ class JsClosureMirror extends JsInstanceMirror implements ClosureMirror { |
| } |
| } |
| +// For generic classes, mirrors uses the same representation, [ClassMirror], |
| +// for the instantiated and uninstantiated type. Somewhat awkwardly, most APIs |
| +// (e.g., [newInstance]) treat the uninstantiated type as if instantiated |
| +// with all dynamic. The representation below is correspondingly a bit wonky. |
| +// For an uninstantiated generic class, [_cls] is the instantiated type (with |
| +// dynamic) and [_raw] is null. For an instantiated generic class, [_cls] is |
| +// the instantiated type (with the corresponding type parameters), and [_raw] |
| +// is the generic factory. |
| class JsClassMirror extends JsMirror implements ClassMirror { |
| final Type _cls; |
| final Symbol simpleName; |
| - // Generic class factory |
| + // Generic class factory for instantiated types. |
| final dynamic _raw; |
| + ClassMirror _originalDeclaration; |
| + |
| // TODO(vsm): Do this properly |
| ClassMirror _mixin = null; |
| List<TypeMirror> _typeArguments; |
| @@ -414,11 +424,8 @@ class JsClassMirror extends JsMirror implements ClassMirror { |
| return _declarations; |
| } |
| - JsClassMirror._(Type cls) |
| - : _cls = cls, |
| - _raw = _getGenericClass(_unwrap(cls)), |
| - simpleName = new Symbol(JS('String', '#.name', _unwrap(cls))) { |
| - var typeArgs = _getGenericArgs(_unwrap(cls)); |
| + void _initialize() { |
| + var typeArgs = _getGenericArgs(_unwrap(_cls)); |
| if (typeArgs == null) { |
| _typeArguments = const []; |
| } else { |
| @@ -427,6 +434,20 @@ class JsClassMirror extends JsMirror implements ClassMirror { |
| } |
| } |
| + JsClassMirror._(Type cls) |
| + : _cls = cls, |
| + _raw = _getGenericClass(_unwrap(cls)), |
| + simpleName = new Symbol(JS('String', '#.name', _unwrap(cls))) { |
| + _initialize(); |
| + } |
| + |
| + JsClassMirror._uninstantiated(Type cls) |
| + : _cls = cls, |
| + _raw = null, |
|
Bob Nystrom
2017/05/25 20:16:05
There's some duplication between these. Maybe a si
vsm
2017/05/25 20:26:52
That is cleaner. :-)
Done and re-inlined initi
|
| + simpleName = new Symbol(JS('String', '#.name', _unwrap(cls))) { |
| + _initialize(); |
| + } |
| + |
| InstanceMirror newInstance(Symbol constructorName, List args, |
| [Map<Symbol, dynamic> namedArgs]) { |
| // TODO(vsm): Support factory constructors and named arguments. |
| @@ -490,8 +511,12 @@ class JsClassMirror extends JsMirror implements ClassMirror { |
| if (_raw == null) { |
| return this; |
| } |
| - throw new UnimplementedError( |
| - "ClassMirror.originalDeclaration unimplemented"); |
| + if (_originalDeclaration != null) { |
| + return _originalDeclaration; |
| + } |
| + _originalDeclaration = |
| + new JsClassMirror._uninstantiated(_wrap(JS('', '#()', _raw))); |
| + return _originalDeclaration; |
| } |
| ClassMirror get superclass { |