Skip to content

Commit 7f85055

Browse files
committed
More mirrors
A little more implementation and workarounds for Angular. See #199. [email protected] Review URL: https://codereview.chromium.org/1489043002 .
1 parent 82f5054 commit 7f85055

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

pkg/dev_compiler/lib/runtime/dart/_js_mirrors.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
132132
return new JsInstanceMirror._(instance);
133133
}
134134
get superinterfaces() {
135-
let interfaces = this[_cls][dart.implements];
136-
if (interfaces == null) {
135+
let interfaceThunk = this[_cls][dart.implements];
136+
if (interfaceThunk == null) {
137137
return dart.list([], mirrors.ClassMirror);
138+
} else {
139+
let interfaces = dart.as(dart.dcall(interfaceThunk), core.List$(core.Type));
140+
return interfaces[dartx.map](dart.fn(t => new JsClassMirror._(dart.as(t, core.Type)), JsClassMirror, [dart.dynamic]))[dartx.toList]();
138141
}
139-
dart.throw(new core.UnimplementedError("ClassMirror.superinterfaces unimplemented"));
140142
}
141143
getField(fieldName) {
142144
return dart.throw(new core.UnimplementedError("ClassMirror.getField unimplemented"));
@@ -186,7 +188,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
186188
return dart.throw(new core.UnimplementedError("ClassMirror.mixin unimplemented"));
187189
}
188190
get originalDeclaration() {
189-
return dart.throw(new core.UnimplementedError("ClassMirror.originalDeclaration unimplemented"));
191+
return this;
190192
}
191193
get owner() {
192194
return dart.throw(new core.UnimplementedError("ClassMirror.owner unimplemented"));
@@ -195,13 +197,17 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
195197
return dart.throw(new core.UnimplementedError("ClassMirror.qualifiedName unimplemented"));
196198
}
197199
get reflectedType() {
198-
return dart.throw(new core.UnimplementedError("ClassMirror.reflectedType unimplemented"));
200+
return this[_cls];
199201
}
200202
get staticMembers() {
201203
return dart.throw(new core.UnimplementedError("ClassMirror.staticMembers unimplemented"));
202204
}
203205
get superclass() {
204-
return dart.throw(new core.UnimplementedError("ClassMirror.superclass unimplemented"));
206+
if (dart.equals(this[_cls], core.Object)) {
207+
return null;
208+
} else {
209+
return new JsClassMirror._(this[_cls].__proto__);
210+
}
205211
}
206212
get typeArguments() {
207213
return dart.throw(new core.UnimplementedError("ClassMirror.typeArguments unimplemented"));
@@ -414,7 +420,7 @@ dart_library.library('dart/_js_mirrors', null, /* Imports */[
414420
return dart.throw(new core.UnimplementedError("MethodMirror.location unimplemented"));
415421
}
416422
get metadata() {
417-
return dart.throw(new core.UnimplementedError("MethodMirror.metadata unimplemented"));
423+
return dart.list([], mirrors.InstanceMirror);
418424
}
419425
get owner() {
420426
return dart.throw(new core.UnimplementedError("MethodMirror.owner unimplemented"));

pkg/dev_compiler/tool/input_sdk/private/js_mirrors.dart

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ class JsClassMirror implements ClassMirror {
120120
}
121121

122122
List<ClassMirror> get superinterfaces {
123-
var interfaces = JS('Function', '#[dart.implements]', _cls);
124-
if (interfaces == null) {
123+
var interfaceThunk = JS('Function', '#[dart.implements]', _cls);
124+
if (interfaceThunk == null) {
125125
return [];
126+
} else {
127+
List<Type> interfaces = interfaceThunk();
128+
return interfaces.map((t) => new JsClassMirror._(t)).toList();
126129
}
127-
throw new UnimplementedError("ClassMirror.superinterfaces unimplemented");
128130
}
129131

130132
// TODO(vsm): Implement
@@ -159,18 +161,25 @@ class JsClassMirror implements ClassMirror {
159161
throw new UnimplementedError("ClassMirror.location unimplemented");
160162
ClassMirror get mixin =>
161163
throw new UnimplementedError("ClassMirror.mixin unimplemented");
162-
TypeMirror get originalDeclaration => throw new UnimplementedError(
163-
"ClassMirror.originalDeclaration unimplemented");
164+
TypeMirror get originalDeclaration {
165+
// TODO(vsm): Handle generic case. How should we represent an original
166+
// declaration for a generic class?
167+
return this;
168+
}
164169
DeclarationMirror get owner =>
165170
throw new UnimplementedError("ClassMirror.owner unimplemented");
166171
Symbol get qualifiedName =>
167172
throw new UnimplementedError("ClassMirror.qualifiedName unimplemented");
168-
Type get reflectedType =>
169-
throw new UnimplementedError("ClassMirror.reflectedType unimplemented");
173+
Type get reflectedType { return _cls; }
170174
Map<Symbol, MethodMirror> get staticMembers =>
171175
throw new UnimplementedError("ClassMirror.staticMembers unimplemented");
172-
ClassMirror get superclass =>
173-
throw new UnimplementedError("ClassMirror.superclass unimplemented");
176+
ClassMirror get superclass {
177+
if (_cls == Object) {
178+
return null;
179+
} else {
180+
return new JsClassMirror._(JS('Type', '#.__proto__', _cls));
181+
}
182+
}
174183
List<TypeMirror> get typeArguments =>
175184
throw new UnimplementedError("ClassMirror.typeArguments unimplemented");
176185
List<TypeVariableMirror> get typeVariables =>
@@ -329,8 +338,10 @@ class JsMethodMirror implements MethodMirror {
329338
throw new UnimplementedError("MethodMirror.isTopLevel unimplemented");
330339
SourceLocation get location =>
331340
throw new UnimplementedError("MethodMirror.location unimplemented");
332-
List<InstanceMirror> get metadata =>
333-
throw new UnimplementedError("MethodMirror.metadata unimplemented");
341+
List<InstanceMirror> get metadata {
342+
// TODO(vsm): Parse and store method metadata
343+
return <InstanceMirror>[];
344+
}
334345
DeclarationMirror get owner =>
335346
throw new UnimplementedError("MethodMirror.owner unimplemented");
336347
Symbol get qualifiedName =>

pkg/dev_compiler/tool/sdk_expected_errors.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,4 @@ warning: [DownCastComposite] min(a.y, b.y) (num) will need runtime check to cast
274274
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)
275275
warning: [DownCastComposite] _clampToZero(width) (num) will need runtime check to cast to type T (dart:math/rectangle.dart, line 247, col 28)
276276
warning: [DownCastComposite] _clampToZero(height) (num) will need runtime check to cast to type T (dart:math/rectangle.dart, line 263, col 30)
277+
warning: [DownCastComposite] interfaceThunk() (dynamic) will need runtime check to cast to type List<Type> (dart:_js_mirrors, line 127, col 31)

0 commit comments

Comments
 (0)