Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2306)

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 21119002: Implement reflect() with Dart code, InstanceMirror.type and ClosureMirror.function with internal co… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/tests/vm/dart/isolate_mirror_local_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors_impl.dart
===================================================================
--- runtime/lib/mirrors_impl.dart (revision 25579)
+++ runtime/lib/mirrors_impl.dart (working copy)
@@ -268,13 +268,14 @@
// TODO(ahe): This is a hack, see delegate below.
static Function _invokeOnClosure;
- _LocalInstanceMirrorImpl(this._type,
- reflectee) : super(reflectee) {}
+ _LocalInstanceMirrorImpl(reflectee) : super(reflectee);
- var _type;
+ ClassMirror _type;
ClassMirror get type {
- if (_type is! Mirror) {
- _type = _type.resolve(mirrors);
+ if (_type == null) {
+ // Note it not safe to use reflectee.runtimeType because runtimeType may
+ // be overridden.
+ _type = reflectClass(_computeType(reflectee));
}
return _type;
}
@@ -292,9 +293,9 @@
// private method does not work.
_LocalInstanceMirrorImpl mirror =
- _Mirrors.makeLocalInstanceMirror(invocation);
- _invokeOnClosure =
- reflectClass(invocation.runtimeType).getField(const Symbol('_invokeOnClosure')).reflectee;
+ reflect(invocation);
+ _invokeOnClosure = reflectClass(invocation.runtimeType)
+ .getField(const Symbol('_invokeOnClosure')).reflectee;
}
return _invokeOnClosure(reflectee, invocation);
}
@@ -309,15 +310,22 @@
_invokeSetter(reflectee, setterName, value)
native 'InstanceMirror_invokeSetter';
+
+ static _computeType(reflectee)
+ native 'Object_runtimeType';
rmacnak 2013/07/29 18:45:06 Woo! Reusing a primitive.
}
class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl
implements ClosureMirror {
- _LocalClosureMirrorImpl(type,
- reflectee,
- this.function) : super(type, reflectee) {}
+ _LocalClosureMirrorImpl(reflectee) : super(reflectee);
- final MethodMirror function;
+ MethodMirror _function;
+ MethodMirror get function {
+ if (_function == null) {
+ _function = _computeFunction(reflectee);
+ }
+ return _function;
+ }
String get source {
throw new UnimplementedError(
@@ -352,17 +360,18 @@
}
}
-
-
Future<InstanceMirror> findInContext(Symbol name) {
throw new UnimplementedError(
'ClosureMirror.findInContext() is not implemented');
}
+ String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
+
static _apply(reflectee, positionalArguments)
native 'ClosureMirror_apply';
- String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
+ static _computeFunction(reflectee)
+ native 'ClosureMirror_function';
}
class _LazyTypeMirror {
@@ -1217,13 +1226,11 @@
}
}
- // Creates a new local InstanceMirror
- static InstanceMirror makeLocalInstanceMirror(Object reflectee)
- native 'Mirrors_makeLocalInstanceMirror';
-
// Creates a new local mirror for some Object.
static InstanceMirror reflect(Object reflectee) {
- return makeLocalInstanceMirror(reflectee);
+ return reflectee is Function
+ ? new _LocalClosureMirrorImpl(reflectee)
+ : new _LocalInstanceMirrorImpl(reflectee);
}
// Creates a new local ClassMirror.
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/tests/vm/dart/isolate_mirror_local_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698