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

Side by Side Diff: sdk/lib/mirrors/mirrors.dart

Issue 23460050: Mirror removals: async invoke, mirrorSystemOf(port), Mirror.mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: resync 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // For the purposes of the mirrors library, we adopt a naming 5 // For the purposes of the mirrors library, we adopt a naming
6 // convention with respect to getters and setters. Specifically, for 6 // convention with respect to getters and setters. Specifically, for
7 // some variable or field... 7 // some variable or field...
8 // 8 //
9 // var myField; 9 // var myField;
10 // 10 //
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 */ 118 */
119 external static Symbol getSymbol(String name, [LibraryMirror library]); 119 external static Symbol getSymbol(String name, [LibraryMirror library]);
120 } 120 }
121 121
122 /** 122 /**
123 * Returns a [MirrorSystem] for the current isolate. 123 * Returns a [MirrorSystem] for the current isolate.
124 */ 124 */
125 external MirrorSystem currentMirrorSystem(); 125 external MirrorSystem currentMirrorSystem();
126 126
127 /** 127 /**
128 * Creates a [MirrorSystem] for the isolate which is listening on
129 * the [SendPort].
130 */
131 external Future<MirrorSystem> mirrorSystemOf(SendPort port);
132
133 /**
134 * Reflects an instance. 128 * Reflects an instance.
135 * Returns an [InstanceMirror] reflecting [reflectee]. 129 * Returns an [InstanceMirror] reflecting [reflectee].
136 * If [reflectee] is a function or an instance of a class 130 * If [reflectee] is a function or an instance of a class
137 * that has a [:call:] method, the returned instance mirror 131 * that has a [:call:] method, the returned instance mirror
138 * will be a [ClosureMirror]. 132 * will be a [ClosureMirror].
139 * 133 *
140 * Note that since one cannot obtain an object from 134 * Note that since one cannot obtain an object from
141 * another isolate, this function can only be used to 135 * another isolate, this function can only be used to
142 * obtain mirrors on objects of the current isolate. 136 * obtain mirrors on objects of the current isolate.
143 */ 137 */
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 * If the invocation returns a result *r*, this method returns 406 * If the invocation returns a result *r*, this method returns
413 * the result of calling [reflect]([value]). 407 * the result of calling [reflect]([value]).
414 * If the invocation causes a compilation error 408 * If the invocation causes a compilation error
415 * the effect is the same as if a non-reflective compilation error 409 * the effect is the same as if a non-reflective compilation error
416 * had been encountered. 410 * had been encountered.
417 * If the invocation throws an exception *e* (that it does not catch) 411 * If the invocation throws an exception *e* (that it does not catch)
418 * this method throws *e*. 412 * this method throws *e*.
419 */ 413 */
420 /* TODO(turnidge): Handle ambiguous names.*/ 414 /* TODO(turnidge): Handle ambiguous names.*/
421 InstanceMirror setField(Symbol fieldName, Object value); 415 InstanceMirror setField(Symbol fieldName, Object value);
422
423 /**
424 * Invokes the named function and returns a mirror on the result.
425 * The arguments must be instances of [InstanceMirror], or of
426 * a type that is serializable across isolates (currently [num],
427 * [String], or [bool]).
428 *
429 * Let *o* be the object reflected by this mirror, let
430 * *f* be the simple name of the member denoted by [memberName],
431 * let *a1, ..., an* be the elements of [positionalArguments]
432 * let *k1, ..., km* be the identifiers denoted by the elements of
433 * [namedArguments.keys]
434 * and let *v1, ..., vm* be the elements of [namedArguments.values].
435 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi*
436 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*.
437 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let *q j*
438 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*.
439 * If any of the *pi, qj* is not an instance of [InstanceMirror] and
440 * is not serializable across isolates, an exception is thrown.
441 * Then this method will perform the method invocation
442 * *o.f(p1, ..., pn, k1: q1, ..., km: qm)*
443 * in a scope that has access to the private members
444 * of *o* (if *o* is a class or library) or the private members of the
445 * class of *o*(otherwise).
446 * The method returns a future *k*.
447 * If the invocation returns a result *r*, *k* will be completed
448 * with the result of calling [reflect](*r*).
449 * If the invocation throws an exception *e* (that it does not catch)
450 * then *k* is completed with a [MirrorError] wrapping *e*.
451 */
452 /*
453 * TODO(turnidge): Handle ambiguous names.
454 * TODO(turnidge): Handle optional & named arguments.
455 */
456 Future<InstanceMirror> invokeAsync(Symbol memberName,
457 List positionalArguments,
458 [Map<Symbol, dynamic> namedArguments]);
459
460 /**
461 * Invokes a getter and returns a mirror on the result. The getter
462 * can be the implicit getter for a field or a user-defined getter
463 * method.
464 *
465 * Let *o* be the object reflected by this mirror, let
466 * *f* be the simple name of the getter denoted by [fieldName],
467 * Then this method will perform the getter invocation
468 * *o.f*
469 * in a scope that has access to the private members
470 * of *o* (if *o* is a class or library) or the private members of the
471 * class of *o*(otherwise).
472 *
473 * If this mirror is an [InstanceMirror], and [fieldName] denotes an instance
474 * method on its reflectee, the result of the invocation is an instance
475 * mirror on a closure corresponding to that method.
476 *
477 * If this mirror is a [LibraryMirror], and [fieldName] denotes a top-level
478 * method in the corresponding library, the result of the invocation is an
479 * instance mirror on a closure corresponding to that method.
480 *
481 * If this mirror is a [ClassMirror], and [fieldName] denotes a static method
482 * in the corresponding class, the result of the invocation is an instance
483 * mirror on a closure corresponding to that method.
484 *
485 * The method returns a future *k*.
486 * If the invocation returns a result *r*, *k* will be completed
487 * with the result of calling [reflect](*r*).
488 * If the invocation throws an exception *e* (that it does not catch)
489 * then *k* is completed with a [MirrorError] wrapping *e*.
490 */
491 /* TODO(turnidge): Handle ambiguous names.*/
492 Future<InstanceMirror> getFieldAsync(Symbol fieldName);
493
494 /**
495 * Invokes a setter and returns a mirror on the result. The setter
496 * may be either the implicit setter for a non-final field or a
497 * user-defined setter method.
498 * The second argument must be an instance of [InstanceMirror], or of
499 * a type that is serializable across isolates (currently [num],
500 * [String], or [bool]).
501 *
502 * Let *o* be the object reflected by this mirror, let
503 * *f* be the simple name of the getter denoted by [fieldName],
504 * and let a be the object bound to [value]. If *a* is an instance of
505 * [InstanceMirror] let *p* be the object
506 * reflected by *a*, otherwise let *p =a*.
507 * If *p* is not an instance of [InstanceMirror], *p* must be
508 * serializable across isolates or an exception is thrown.
509 * Then this method will perform the setter invocation
510 * *o.f = a*
511 * in a scope that has access to the private members
512 * of *o* (if *o* is a class or library) or the private members of the
513 * class of *o*(otherwise).
514 * The method returns a future *k*.
515 * If the invocation returns a result *r*, *k* will be completed
516 * with the result of calling [reflect](*r*).
517 * If the invocation throws an exception *e* (that it does not catch)
518 * then *k* is completed with a [MirrorError} wrapping *e*.
519 */
520 /* TODO(turnidge): Handle ambiguous names.*/
521 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value);
522 } 416 }
523 417
524 /** 418 /**
525 * An [InstanceMirror] reflects an instance of a Dart language object. 419 * An [InstanceMirror] reflects an instance of a Dart language object.
526 */ 420 */
527 abstract class InstanceMirror implements ObjectMirror { 421 abstract class InstanceMirror implements ObjectMirror {
528 /** 422 /**
529 * A mirror on the type of the reflectee. 423 * A mirror on the type of the reflectee.
530 * 424 *
531 * Returns a mirror on the actual class of the reflectee. 425 * Returns a mirror on the actual class of the reflectee.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 * the result of calling [reflect](*r*). 503 * the result of calling [reflect](*r*).
610 * If the invocation causes a compilation error 504 * If the invocation causes a compilation error
611 * this method throws a [MirrorError]. 505 * this method throws a [MirrorError].
612 * If the invocation throws an exception *e* (that it does not catch) 506 * If the invocation throws an exception *e* (that it does not catch)
613 * this method throws *e*. 507 * this method throws *e*.
614 */ 508 */
615 InstanceMirror apply(List positionalArguments, 509 InstanceMirror apply(List positionalArguments,
616 [Map<Symbol, dynamic> namedArguments]); 510 [Map<Symbol, dynamic> namedArguments]);
617 511
618 /** 512 /**
619 * Executes the closure and returns a mirror on the result.
620 *
621 * Let *f* be the closure reflected by this mirror,
622 * let *a1, ..., an* be the elements of [positionalArguments]
623 * let *k1, ..., km* be the identifiers denoted by the elements of
624 * [namedArguments.keys]
625 * and let *v1, ..., vm* be the elements of [namedArguments.values].
626 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi*
627 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*.
628 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let
629 * *qj*
630 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*.
631 * If any of the *pi, qj* is not an instance of [InstanceMirror] and
632 * is not serializable across isolates, an exception is thrown.
633 * Then this method will perform the function invocation
634 * *f(p1, ..., pn, k1: q1, ..., km: qm)*
635 * The method returns a future *k*.
636 * If the invocation returns a result *r*, *k* will be completed
637 * with the result of calling [reflect](*r*).
638 * If the invocation throws an exception *e* (that it does not catch)
639 * then *k* is completed with a [MirrorError] wrapping *e*.
640 *
641 * The arguments must be instances of [InstanceMirror], or of
642 * a type that is serializable across isolates (currently [num],
643 * [String], or [bool]).
644 */
645 Future<InstanceMirror> applyAsync(List positionalArguments,
646 [Map<Symbol, dynamic> namedArguments]);
647
648 /**
649 * Looks up the value of a name in the scope of the closure. The 513 * Looks up the value of a name in the scope of the closure. The
650 * result is a mirror on that value. 514 * result is a mirror on that value.
651 * 515 *
652 * Let *s* be the contents of the string used to construct the symbol [name]. 516 * Let *s* be the contents of the string used to construct the symbol [name].
653 * 517 *
654 * If the expression *s* occurs within the source code of the reflectee, 518 * If the expression *s* occurs within the source code of the reflectee,
655 * and if any such occurrence refers to a declaration outside the reflectee, 519 * and if any such occurrence refers to a declaration outside the reflectee,
656 * then let *v* be the result of evaluating the expression *s* at such 520 * then let *v* be the result of evaluating the expression *s* at such
657 * an occurrence. 521 * an occurrence.
658 * If *s = this*, and the reflectee was defined within the instance scope of 522 * If *s = this*, and the reflectee was defined within the instance scope of
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 * the effect is the same as if a non-reflective compilation error 758 * the effect is the same as if a non-reflective compilation error
895 * had been encountered. 759 * had been encountered.
896 * If evaluating the expression throws an exception *e* 760 * If evaluating the expression throws an exception *e*
897 * (that it does not catch) 761 * (that it does not catch)
898 * this method throws *e*. 762 * this method throws *e*.
899 */ 763 */
900 InstanceMirror newInstance(Symbol constructorName, 764 InstanceMirror newInstance(Symbol constructorName,
901 List positionalArguments, 765 List positionalArguments,
902 [Map<Symbol,dynamic> namedArguments]); 766 [Map<Symbol,dynamic> namedArguments]);
903 767
904 /**
905 * Invokes the named function and returns a mirror on the result.
906 * The arguments must be instances of [InstanceMirror], or of
907 * a type that is serializable across isolates (currently [num],
908 * [String], or [bool]).
909 *
910 * Let *c* be the class reflected by this mirror,
911 * let *a1, ..., an* be the elements of [positionalArguments]
912 * let *k1, ..., km* be the identifiers denoted by the elements of
913 * [namedArguments.keys]
914 * and let *v1, ..., vm* be the elements of [namedArguments.values].
915 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi*
916 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*.
917 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let
918 * *qj*
919 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*.
920 * If any of the *pi, qj* is not an instance of [InstanceMirror] and
921 * is not serializable across isolates, an exception is thrown.
922 * If [constructorName] was created from the empty string
923 * Then this method will execute the instance creation expression
924 * *new c(a1, ..., an, k1: v1, ..., km: vm)*
925 * in a scope that has access to the private members
926 * of *c*. Otherwise, let
927 * *f* be the simple name of the constructor denoted by [constructorName]
928 * Then this method will execute the instance creation expression
929 * *new c.f(a1, ..., an, k1: v1, ..., km: vm)*
930 * in a scope that has access to the private members
931 * of *c*.
932 * In either case:
933 * The method returns a future *k*.
934 * If the invocation returns a result *r*, *k* will be completed
935 * with the result of calling [reflect](*r*).
936 * If the invocation throws an exception *e* (that it does not catch)
937 * then *k* is completed with a [MirrorError] wrapping *e*.
938 */
939 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
940 List positionalArguments,
941 [Map<Symbol, dynamic> namedArguments]) ;
942
943 /** 768 /**
944 * Returns [:true:] if this mirror is equal to [other]. 769 * Returns [:true:] if this mirror is equal to [other].
945 * Otherwise returns [:false:]. 770 * Otherwise returns [:false:].
946 * 771 *
947 * The equality holds if and only if 772 * The equality holds if and only if
948 * (1) [other] is a mirror of the same kind 773 * (1) [other] is a mirror of the same kind
949 * and 774 * and
950 * (2) This mirror and [other] reflect the same class. 775 * (2) This mirror and [other] reflect the same class.
951 * 776 *
952 * Note that if the reflected class is an invocation of 777 * Note that if the reflected class is an invocation of
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 * 1227 *
1403 * When used as metadata on an import of "dart:mirrors", this metadata does 1228 * When used as metadata on an import of "dart:mirrors", this metadata does
1404 * not apply to the library in which the annotation is used, but instead 1229 * not apply to the library in which the annotation is used, but instead
1405 * applies to the other libraries (all libraries if "*" is used). 1230 * applies to the other libraries (all libraries if "*" is used).
1406 */ 1231 */
1407 final override; 1232 final override;
1408 1233
1409 const MirrorsUsed( 1234 const MirrorsUsed(
1410 {this.symbols, this.targets, this.metaTargets, this.override}); 1235 {this.symbols, this.targets, this.metaTargets, this.override});
1411 } 1236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698