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

Unified Diff: sdk/lib/_internal/lib/js_mirrors.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
Index: sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart
index 2887c43e96c54ee929b4c4cdeee517e96f7c0d8f..2fac925bbebcdb9563317bc6736c661fac2f303c 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -421,6 +421,11 @@ class JsLibraryMirror extends JsDeclarationMirror with JsObjectMirror
// TODO(ahe): Test this getter.
DeclarationMirror get owner => null;
+
+ Function operator [](Symbol selector) {
+ if (!functions.containsKey(selector)) return null;
+ return new _InvocationTrampoline(this, selector);
+ }
}
String n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
@@ -620,6 +625,19 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror
List<TypeMirror> get typeArguments => new List();
}
+// TODO(13766): Implement Function.
+class _InvocationTrampoline /*implements Function*/ {
+ ObjectMirror _receiver;
+ Symbol _selector;
+ _InvocationTrampoline(this._receiver, this._selector);
+ noSuchMethod(Invocation msg) {
ahe 2013/10/03 07:26:35 In no way can we use "noSuchMethod" in implementat
+ if (msg.memberName != #call) return super.noSuchMethod(msg);
+ return _receiver.invoke(_selector,
+ msg.positionalArguments,
+ msg.namedArguments);
+ }
+}
+
abstract class JsObjectMirror implements ObjectMirror {
Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value) {
return new Future<InstanceMirror>(() => this.setField(fieldName, value));
@@ -775,6 +793,19 @@ class JsInstanceMirror extends JsObjectMirror implements InstanceMirror {
return JSInvocationMirror.invokeFromMirror(invocation, reflectee);
}
+ 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);
+ }
+
operator ==(other) {
return other is JsInstanceMirror &&
identical(reflectee, other.reflectee);
@@ -1332,6 +1363,12 @@ class JsClassMirror extends JsTypeMirror with JsObjectMirror
}
List<TypeMirror> get typeArguments => new List();
+
+ Function operator [](Symbol selector) {
+ var target = methods[selector];
+ if (target == null || !target.isStatic) return null;
+ return new _InvocationTrampoline(this, selector);
+ }
}
class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {

Powered by Google App Engine
This is Rietveld 408576698