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

Unified Diff: lib/src/mirrors.dart

Issue 615913004: Add @jsify annotation. Support automatically proxying Lists and Maps to Dart in Proxies. Support co… (Closed) Base URL: https://github.com/dart-lang/js-interop.git@master
Patch Set: Created 6 years, 3 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: lib/src/mirrors.dart
diff --git a/lib/src/mirrors.dart b/lib/src/mirrors.dart
index 92ac6a0551309e22590d2d23c6167466f5c3fbab..5eabdc4d1f8cd6a7819072204eb3b2f0824a4c2a 100644
--- a/lib/src/mirrors.dart
+++ b/lib/src/mirrors.dart
@@ -350,36 +350,52 @@ class JsInterface extends jsi.JsInterface {
}
}
- dynamic noSuchMethod(Invocation i) {
+ dynamic noSuchMethod(Invocation invocation) {
var mirror = mirrors.reflect(this);
- var decl = getDeclaration(mirror.type, i.memberName);
+ var decl = getDeclaration(mirror.type, invocation.memberName);
if (decl != null) {
mirrors.MethodMirror method = decl;
- String name = mirrors.MirrorSystem.getName(i.memberName);
- if (i.isGetter) {
+ String name = mirrors.MirrorSystem.getName(invocation.memberName);
+ if (invocation.isGetter) {
var o = toDart(toJs(this)[name]);
assert(o == null ||
mirrors.reflect(o).type.isSubtypeOf(method.returnType));
return o;
}
- if (i.isSetter) {
+ if (invocation.isSetter) {
// remove the trailing '=' from the setter name
name = name.substring(0, name.length - 1);
- var v = toJs(i.positionalArguments[0]);
+ var v = toJs(invocation.positionalArguments[0]);
toJs(this)[name] = v;
return null;
}
- if (i.isMethod) {
- var jsArgs = i.positionalArguments.map(toJs).toList();
- var o = toDart(toJs(this).callMethod(name, jsArgs));
+ if (invocation.isMethod) {
+ MethodMirror m = decl;
+ var positionalParams = m.parameters.where((p) => !p.isNamed).toList();
+ var positionalArgs = invocation.positionalArguments;
+ var jsArgs = new List(positionalArgs.length);
+ for (int i = 0; i < positionalArgs.length; i++) {
+ var param = positionalParams[i];
+ var arg = positionalArgs[i];
+ var hasJsify = param.metadata.any((m) => m.reflectee == jsify);
+ if (hasJsify) {
+ jsArgs[i] = new js.JsObject.jsify(arg);
alexandre.ardhuin 2014/10/01 20:36:52 Even if @jsify is used we shouldn't jsify an JsObj
justinfagnani 2014/10/07 20:32:24 Done.
+ } else {
+ jsArgs[i] = toJs(arg);
+ }
+ }
+ var returnType = m.returnType.hasReflectedType
+ ? m.returnType.originalDeclaration.simpleName
+ : null;
+ var o = toDart(toJs(this).callMethod(name, jsArgs), returnType);
assert(o == null ||
mirrors.reflect(o).type.isSubtypeOf(method.returnType));
return o;
}
assert(false);
}
- return super.noSuchMethod(i);
+ return super.noSuchMethod(invocation);
}
}

Powered by Google App Engine
This is Rietveld 408576698