Skip to content

Commit

Permalink
More mirrors
Browse files Browse the repository at this point in the history
A little more implementation and workarounds for Angular.  See #199.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1489043002 .
  • Loading branch information
vsmenon committed Dec 1, 2015
1 parent 82f5054 commit 7f85055
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
20 changes: 13 additions & 7 deletions pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
return new JsInstanceMirror._(instance);
}
get superinterfaces() {
let interfaces = this[_cls][dart.implements];
if (interfaces == null) {
let interfaceThunk = this[_cls][dart.implements];
if (interfaceThunk == null) {
return dart.list([], mirrors.ClassMirror);
} else {
let interfaces = dart.as(dart.dcall(interfaceThunk), core.List$(core.Type));
return interfaces[dartx.map](dart.fn(t => new JsClassMirror._(dart.as(t, core.Type)), JsClassMirror, [dart.dynamic]))[dartx.toList]();
}
dart.throw(new core.UnimplementedError("ClassMirror.superinterfaces unimplemented"));
}
getField(fieldName) {
return dart.throw(new core.UnimplementedError("ClassMirror.getField unimplemented"));
Expand Down Expand Up @@ -186,7 +188,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
return dart.throw(new core.UnimplementedError("ClassMirror.mixin unimplemented"));
}
get originalDeclaration() {
return dart.throw(new core.UnimplementedError("ClassMirror.originalDeclaration unimplemented"));
return this;
}
get owner() {
return dart.throw(new core.UnimplementedError("ClassMirror.owner unimplemented"));
Expand All @@ -195,13 +197,17 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
return dart.throw(new core.UnimplementedError("ClassMirror.qualifiedName unimplemented"));
}
get reflectedType() {
return dart.throw(new core.UnimplementedError("ClassMirror.reflectedType unimplemented"));
return this[_cls];
}
get staticMembers() {
return dart.throw(new core.UnimplementedError("ClassMirror.staticMembers unimplemented"));
}
get superclass() {
return dart.throw(new core.UnimplementedError("ClassMirror.superclass unimplemented"));
if (dart.equals(this[_cls], core.Object)) {
return null;
} else {
return new JsClassMirror._(this[_cls].__proto__);
}
}
get typeArguments() {
return dart.throw(new core.UnimplementedError("ClassMirror.typeArguments unimplemented"));
Expand Down Expand Up @@ -414,7 +420,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
return dart.throw(new core.UnimplementedError("MethodMirror.location unimplemented"));
}
get metadata() {
return dart.throw(new core.UnimplementedError("MethodMirror.metadata unimplemented"));
return dart.list([], mirrors.InstanceMirror);
}
get owner() {
return dart.throw(new core.UnimplementedError("MethodMirror.owner unimplemented"));
Expand Down
33 changes: 22 additions & 11 deletions pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ class JsClassMirror implements ClassMirror {
}

List<ClassMirror> get superinterfaces {
var interfaces = JS('Function', '#[dart.implements]', _cls);
if (interfaces == null) {
var interfaceThunk = JS('Function', '#[dart.implements]', _cls);
if (interfaceThunk == null) {
return [];
} else {
List<Type> interfaces = interfaceThunk();
return interfaces.map((t) => new JsClassMirror._(t)).toList();
}
throw new UnimplementedError("ClassMirror.superinterfaces unimplemented");
}

// TODO(vsm): Implement
Expand Down Expand Up @@ -159,18 +161,25 @@ class JsClassMirror implements ClassMirror {
throw new UnimplementedError("ClassMirror.location unimplemented");
ClassMirror get mixin =>
throw new UnimplementedError("ClassMirror.mixin unimplemented");
TypeMirror get originalDeclaration => throw new UnimplementedError(
"ClassMirror.originalDeclaration unimplemented");
TypeMirror get originalDeclaration {
// TODO(vsm): Handle generic case. How should we represent an original
// declaration for a generic class?
return this;
}
DeclarationMirror get owner =>
throw new UnimplementedError("ClassMirror.owner unimplemented");
Symbol get qualifiedName =>
throw new UnimplementedError("ClassMirror.qualifiedName unimplemented");
Type get reflectedType =>
throw new UnimplementedError("ClassMirror.reflectedType unimplemented");
Type get reflectedType { return _cls; }
Map<Symbol, MethodMirror> get staticMembers =>
throw new UnimplementedError("ClassMirror.staticMembers unimplemented");
ClassMirror get superclass =>
throw new UnimplementedError("ClassMirror.superclass unimplemented");
ClassMirror get superclass {
if (_cls == Object) {
return null;
} else {
return new JsClassMirror._(JS('Type', '#.__proto__', _cls));
}
}
List<TypeMirror> get typeArguments =>
throw new UnimplementedError("ClassMirror.typeArguments unimplemented");
List<TypeVariableMirror> get typeVariables =>
Expand Down Expand Up @@ -329,8 +338,10 @@ class JsMethodMirror implements MethodMirror {
throw new UnimplementedError("MethodMirror.isTopLevel unimplemented");
SourceLocation get location =>
throw new UnimplementedError("MethodMirror.location unimplemented");
List<InstanceMirror> get metadata =>
throw new UnimplementedError("MethodMirror.metadata unimplemented");
List<InstanceMirror> get metadata {
// TODO(vsm): Parse and store method metadata
return <InstanceMirror>[];
}
DeclarationMirror get owner =>
throw new UnimplementedError("MethodMirror.owner unimplemented");
Symbol get qualifiedName =>
Expand Down
1 change: 1 addition & 0 deletions pkg/dev_compiler/tool/sdk_expected_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,4 @@ warning: [DownCastComposite] min(a.y, b.y) (num) will need runtime check to cast
warning: [DownCastComposite] max(a.y, b.y) - top (num) will need runtime check to cast to type T (dart:math/rectangle.dart, line 231, col 16)
warning: [DownCastComposite] _clampToZero(width) (num) will need runtime check to cast to type T (dart:math/rectangle.dart, line 247, col 28)
warning: [DownCastComposite] _clampToZero(height) (num) will need runtime check to cast to type T (dart:math/rectangle.dart, line 263, col 30)
warning: [DownCastComposite] interfaceThunk() (dynamic) will need runtime check to cast to type List<Type> (dart:_js_mirrors, line 127, col 31)

0 comments on commit 7f85055

Please sign in to comment.