Index: runtime/lib/mirrors_impl.dart |
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart |
index e20aa8874d603d414c29eaca193a54e8a4bcd9d7..2670f043df941599502e3ca4a65ef3a8b91ec541 100644 |
--- a/runtime/lib/mirrors_impl.dart |
+++ b/runtime/lib/mirrors_impl.dart |
@@ -159,6 +159,18 @@ class _LocalIsolateMirrorImpl extends _LocalMirrorImpl |
String toString() => "IsolateMirror on '$debugName'"; |
} |
+class _InvocationTrampoline implements Function { |
+ ObjectMirror _receiver; |
+ Symbol _selector; |
+ _InvocationTrampoline(this._receiver, this._selector); |
+ noSuchMethod(Invocation msg) { |
+ if (msg.memberName != #call) return super.noSuchMethod(msg); |
+ return _receiver.invoke(_selector, |
+ msg.positionalArguments, |
+ msg.namedArguments); |
+ } |
+} |
+ |
abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl |
implements ObjectMirror { |
_LocalObjectMirrorImpl(this._reflectee); |
@@ -317,6 +329,19 @@ class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl |
static _identityHash(reflectee) |
native "InstanceMirror_identityHash"; |
+ Function operator [](Symbol selector) { |
+ bool found = false; |
+ for (ClassMirror c = type; c != null; c = c.superclass) { |
+ var target = c.methods[selector]; |
+ if (target != null && !target.isStatic) { |
+ found = true; |
+ break; |
+ } |
+ } |
+ if (!found) return null; |
+ return new _InvocationTrampoline(this, selector); |
+ } |
+ |
// Override to include the receiver in the arguments. |
InstanceMirror invoke(Symbol memberName, |
List positionalArguments, |
@@ -646,6 +671,12 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
String toString() => "ClassMirror on '${_n(simpleName)}'"; |
+ Function operator [](Symbol selector) { |
+ var target = methods[selector]; |
+ if (target == null || !target.isStatic) return null; |
+ return new _InvocationTrampoline(this, selector); |
+ } |
+ |
InstanceMirror newInstance(Symbol constructorName, |
List positionalArguments, |
[Map<Symbol, dynamic> namedArguments]) { |
@@ -1002,6 +1033,11 @@ class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl |
String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
+ Function operator [](Symbol selector) { |
+ if (!functions.containsKey(selector)) return null; |
+ return new _InvocationTrampoline(this, selector); |
+ } |
+ |
_invoke(reflectee, memberName, arguments, argumentNames) |
native 'LibraryMirror_invoke'; |