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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This library contains semi-private APIs for implementing typed interfaces and 6 * This library contains semi-private APIs for implementing typed interfaces and
7 * exports. 7 * exports.
8 */ 8 */
9 library js.mirrors; 9 library js.mirrors;
10 10
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 343 }
344 344
345 if (jsConstructor != null) { 345 if (jsConstructor != null) {
346 // TODO: support constructor expressions 346 // TODO: support constructor expressions
347 var ctor = getPath(jsConstructor); 347 var ctor = getPath(jsConstructor);
348 var jsObj = new JsObject(ctor, args); 348 var jsObj = new JsObject(ctor, args);
349 return classMirror.newInstance(#created, [jsObj]).reflectee; 349 return classMirror.newInstance(#created, [jsObj]).reflectee;
350 } 350 }
351 } 351 }
352 352
353 dynamic noSuchMethod(Invocation i) { 353 dynamic noSuchMethod(Invocation invocation) {
354 var mirror = mirrors.reflect(this); 354 var mirror = mirrors.reflect(this);
355 var decl = getDeclaration(mirror.type, i.memberName); 355 var decl = getDeclaration(mirror.type, invocation.memberName);
356 356
357 if (decl != null) { 357 if (decl != null) {
358 mirrors.MethodMirror method = decl; 358 mirrors.MethodMirror method = decl;
359 String name = mirrors.MirrorSystem.getName(i.memberName); 359 String name = mirrors.MirrorSystem.getName(invocation.memberName);
360 if (i.isGetter) { 360 if (invocation.isGetter) {
361 var o = toDart(toJs(this)[name]); 361 var o = toDart(toJs(this)[name]);
362 assert(o == null || 362 assert(o == null ||
363 mirrors.reflect(o).type.isSubtypeOf(method.returnType)); 363 mirrors.reflect(o).type.isSubtypeOf(method.returnType));
364 return o; 364 return o;
365 } 365 }
366 if (i.isSetter) { 366 if (invocation.isSetter) {
367 // remove the trailing '=' from the setter name 367 // remove the trailing '=' from the setter name
368 name = name.substring(0, name.length - 1); 368 name = name.substring(0, name.length - 1);
369 var v = toJs(i.positionalArguments[0]); 369 var v = toJs(invocation.positionalArguments[0]);
370 toJs(this)[name] = v; 370 toJs(this)[name] = v;
371 return null; 371 return null;
372 } 372 }
373 if (i.isMethod) { 373 if (invocation.isMethod) {
374 var jsArgs = i.positionalArguments.map(toJs).toList(); 374 MethodMirror m = decl;
375 var o = toDart(toJs(this).callMethod(name, jsArgs)); 375 var positionalParams = m.parameters.where((p) => !p.isNamed).toList();
376 var positionalArgs = invocation.positionalArguments;
377 var jsArgs = new List(positionalArgs.length);
378 for (int i = 0; i < positionalArgs.length; i++) {
379 var param = positionalParams[i];
380 var arg = positionalArgs[i];
381 var hasJsify = param.metadata.any((m) => m.reflectee == jsify);
382 if (hasJsify) {
383 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.
384 } else {
385 jsArgs[i] = toJs(arg);
386 }
387 }
388 var returnType = m.returnType.hasReflectedType
389 ? m.returnType.originalDeclaration.simpleName
390 : null;
391 var o = toDart(toJs(this).callMethod(name, jsArgs), returnType);
376 assert(o == null || 392 assert(o == null ||
377 mirrors.reflect(o).type.isSubtypeOf(method.returnType)); 393 mirrors.reflect(o).type.isSubtypeOf(method.returnType));
378 return o; 394 return o;
379 } 395 }
380 assert(false); 396 assert(false);
381 } 397 }
382 return super.noSuchMethod(i); 398 return super.noSuchMethod(invocation);
383 } 399 }
384 } 400 }
385 401
386 JsProxy _getJsProxyAnnotation(ClassMirror c) { 402 JsProxy _getJsProxyAnnotation(ClassMirror c) {
387 var jsProxyAnnotationMirror = 403 var jsProxyAnnotationMirror =
388 c.metadata 404 c.metadata
389 .firstWhere((i) => i.reflectee is JsProxy, orElse: () => null); 405 .firstWhere((i) => i.reflectee is JsProxy, orElse: () => null);
390 406
391 if (jsProxyAnnotationMirror == null) return null; 407 if (jsProxyAnnotationMirror == null) return null;
392 408
(...skipping 20 matching lines...) Expand all
413 _getDeclarations(classMirror.superclass, declarations); 429 _getDeclarations(classMirror.superclass, declarations);
414 } 430 }
415 // TODO: See if a getter can shadow an implicit setter from a field in a 431 // TODO: See if a getter can shadow an implicit setter from a field in a
416 // superclass. This could happen if a superclass has a field and a subclass 432 // superclass. This could happen if a superclass has a field and a subclass
417 // has a getter with the same name. Since the field doesn't induce a setter 433 // has a getter with the same name. Since the field doesn't induce a setter
418 // in the declarations, the field would be replaced by the getter and there 434 // in the declarations, the field would be replaced by the getter and there
419 // would be no associated setter. The solution would be to create a synthetic 435 // would be no associated setter. The solution would be to create a synthetic
420 // setter if we're adding a getter than shadows a field. 436 // setter if we're adding a getter than shadows a field.
421 declarations.addAll(classMirror.declarations); 437 declarations.addAll(classMirror.declarations);
422 } 438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698