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

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 25741005: Implement ObjectMirror.[] (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « no previous file | sdk/lib/mirrors/mirrors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/mirrors_impl.dart
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart
index cdcf3e35ddd2416bb4fb0e3f4d4c2d46af5cedb9..85bbae8387d0bdcee6a7ab820692fef7ebdcf681 100644
--- a/runtime/lib/mirrors_impl.dart
+++ b/runtime/lib/mirrors_impl.dart
@@ -200,6 +200,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);
@@ -348,6 +360,23 @@ class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl
return identityHashCode(_reflectee) ^ 0x36363636;
}
+ 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 && target.isRegularMethod) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new ArgumentError(
+ "${MirrorSystem.getName(type.simpleName)} has no instance method "
+ "${MirrorSystem.getName(selector)}");
+ }
+ return new _InvocationTrampoline(this, selector);
+ }
+
// Override to include the receiver in the arguments.
InstanceMirror invoke(Symbol memberName,
List positionalArguments,
@@ -711,6 +740,16 @@ class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
String toString() => "ClassMirror on '${MirrorSystem.getName(simpleName)}'";
+ Function operator [](Symbol selector) {
+ var target = methods[selector];
+ if (target == null || !target.isStatic || !target.isRegularMethod) {
+ throw new ArgumentError(
+ "${MirrorSystem.getName(simpleName)} has no static method "
+ "${MirrorSystem.getName(selector)}");
+ }
+ return new _InvocationTrampoline(this, selector);
+ }
+
InstanceMirror newInstance(Symbol constructorName,
List positionalArguments,
[Map<Symbol, dynamic> namedArguments]) {
@@ -1188,6 +1227,16 @@ class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl
String toString() => "LibraryMirror on '${_n(simpleName)}'";
+ Function operator [](Symbol selector) {
+ var target = functions[selector];
+ if (target == null || !target.isRegularMethod) {
+ throw new ArgumentError(
+ "${MirrorSystem.getName(simpleName)} has no top-level method "
+ "${MirrorSystem.getName(selector)}");
+ }
+ return new _InvocationTrampoline(this, selector);
+ }
+
_invoke(reflectee, memberName, arguments, argumentNames)
native 'LibraryMirror_invoke';
« no previous file with comments | « no previous file | sdk/lib/mirrors/mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698