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

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/_internal/lib/js_mirrors.dart » ('j') | sdk/lib/_internal/lib/js_mirrors.dart » ('J')
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 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';
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/js_mirrors.dart » ('j') | sdk/lib/_internal/lib/js_mirrors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698