Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 */ | 105 */ |
| 106 external static String getName(Symbol symbol); | 106 external static String getName(Symbol symbol); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Returns a [MirrorSystem] for the current isolate. | 110 * Returns a [MirrorSystem] for the current isolate. |
| 111 */ | 111 */ |
| 112 external MirrorSystem currentMirrorSystem(); | 112 external MirrorSystem currentMirrorSystem(); |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Creates a [MirrorSystem] for the isolate which is listening on | |
| 116 * the [SendPort]. | |
| 117 */ | |
| 118 external Future<MirrorSystem> mirrorSystemOf(SendPort port); | |
| 119 | |
| 120 /** | |
| 121 * Returns an [InstanceMirror] reflecting [reflectee]. | 115 * Returns an [InstanceMirror] reflecting [reflectee]. |
| 122 * If [reflectee] is function or an instance of a class | 116 * If [reflectee] is function or an instance of a class |
| 123 * that has a [:call:] method, the returned instance mirror | 117 * that has a [:call:] method, the returned instance mirror |
| 124 * will be a [ClosureMirror]. | 118 * will be a [ClosureMirror]. |
| 125 * | 119 * |
| 126 * Note that since one cannot obtain an object from | 120 * Note that since one cannot obtain an object from |
| 127 * another isolate, this function can only be used to | 121 * another isolate, this function can only be used to |
| 128 * obtain mirrors on objects of the current isolate. | 122 * obtain mirrors on objects of the current isolate. |
| 129 */ | 123 */ |
| 130 external InstanceMirror reflect(Object reflectee); | 124 external InstanceMirror reflect(Object reflectee); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 * class of *o* (otherwise). | 358 * class of *o* (otherwise). |
| 365 * If the invocation returns a result *r*, this method returns | 359 * If the invocation returns a result *r*, this method returns |
| 366 * the result of calling [reflect]([value]). | 360 * the result of calling [reflect]([value]). |
| 367 * If the invocation causes a compilation error | 361 * If the invocation causes a compilation error |
| 368 * this method throws a [MirroredCompilationError]. | 362 * this method throws a [MirroredCompilationError]. |
| 369 * If the invocation throws an exception *e* (that it does not catch) | 363 * If the invocation throws an exception *e* (that it does not catch) |
| 370 * this method throws *e*. | 364 * this method throws *e*. |
| 371 */ | 365 */ |
| 372 /* TODO(turnidge): Handle ambiguous names.*/ | 366 /* TODO(turnidge): Handle ambiguous names.*/ |
| 373 InstanceMirror setField(Symbol fieldName, Object value); | 367 InstanceMirror setField(Symbol fieldName, Object value); |
| 374 | |
| 375 /** | |
| 376 * Invokes the named function and returns a mirror on the result. | |
| 377 * The arguments must be instances of [InstanceMirror], or of | |
| 378 * a type that is serializable across isolates (currently [num], | |
| 379 * [String], or [bool]). | |
| 380 * | |
| 381 * Let *o* be the object reflected by this mirror, let | |
| 382 * *f* be the simple name of the member denoted by [memberName], | |
| 383 * let *a1, ..., an* be the elements of [positionalArguments] | |
| 384 * let *k1, ..., km* be the identifiers denoted by the elements of | |
| 385 * [namedArguments.keys] | |
| 386 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
| 387 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi* | |
| 388 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*. | |
| 389 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let *q j* | |
| 390 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*. | |
| 391 * If any of the *pi, qj* is not an instance of [InstanceMirror] and | |
| 392 * is not serializable across isolates, an exception is thrown. | |
| 393 * Then this method will perform the method invocation | |
| 394 * *o.f(p1, ..., pn, k1: q1, ..., km: qm)* | |
| 395 * in a scope that has access to the private members | |
| 396 * of *o* (if *o* is a class or library) or the private members of the | |
| 397 * class of *o*(otherwise). | |
| 398 * The method returns a future *k*. | |
| 399 * If the invocation returns a result *r*, *k* will be completed | |
| 400 * with the result of calling [reflect](*r*). | |
| 401 * If the invocation throws an exception *e* (that it does not catch) | |
| 402 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 403 */ | |
| 404 /* | |
| 405 * TODO(turnidge): Handle ambiguous names. | |
| 406 * TODO(turnidge): Handle optional & named arguments. | |
| 407 */ | |
| 408 Future<InstanceMirror> invokeAsync(Symbol memberName, | |
| 409 List positionalArguments, | |
| 410 [Map<Symbol, dynamic> namedArguments]); | |
| 411 | |
| 412 /** | |
| 413 * Invokes a getter and returns a mirror on the result. The getter | |
| 414 * can be the implicit getter for a field or a user-defined getter | |
| 415 * method. | |
| 416 * | |
| 417 * Let *o* be the object reflected by this mirror, let | |
| 418 * *f* be the simple name of the getter denoted by [fieldName], | |
| 419 * Then this method will perform the getter invocation | |
| 420 * *o.f* | |
| 421 * in a scope that has access to the private members | |
| 422 * of *o* (if *o* is a class or library) or the private members of the | |
| 423 * class of *o*(otherwise). | |
| 424 * The method returns a future *k*. | |
| 425 * If the invocation returns a result *r*, *k* will be completed | |
| 426 * with the result of calling [reflect](*r*). | |
| 427 * If the invocation throws an exception *e* (that it does not catch) | |
| 428 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 429 */ | |
| 430 /* TODO(turnidge): Handle ambiguous names.*/ | |
| 431 Future<InstanceMirror> getFieldAsync(Symbol fieldName); | |
| 432 | |
| 433 /** | |
| 434 * Invokes a setter and returns a mirror on the result. The setter | |
| 435 * may be either the implicit setter for a non-final field or a | |
| 436 * user-defined setter method. | |
| 437 * The second argument must be an instance of [InstanceMirror], or of | |
| 438 * a type that is serializable across isolates (currently [num], | |
| 439 * [String], or [bool]). | |
| 440 * | |
| 441 * Let *o* be the object reflected by this mirror, let | |
| 442 * *f* be the simple name of the getter denoted by [fieldName], | |
| 443 * and let a be the object bound to [value]. If *a* is an instance of | |
| 444 * [InstanceMirror] let *p* be the object | |
| 445 * reflected by *a*, otherwise let *p =a*. | |
| 446 * If *p* is not an instance of [InstanceMirror], *p* must be | |
| 447 * serializable across isolates or an exception is thrown. | |
| 448 * Then this method will perform the setter invocation | |
| 449 * *o.f = a* | |
| 450 * in a scope that has access to the private members | |
| 451 * of *o* (if *o* is a class or library) or the private members of the | |
| 452 * class of *o*(otherwise). | |
| 453 * The method returns a future *k*. | |
| 454 * If the invocation returns a result *r*, *k* will be completed | |
| 455 * with the result of calling [reflect](*r*). | |
| 456 * If the invocation throws an exception *e* (that it does not catch) | |
| 457 * then *k* is completed with a [MirrorError} wrapping *e*. | |
| 458 */ | |
| 459 /* TODO(turnidge): Handle ambiguous names.*/ | |
| 460 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value); | |
| 461 } | 368 } |
| 462 | 369 |
| 463 /** | 370 /** |
| 464 * An [InstanceMirror] reflects an instance of a Dart language object. | 371 * An [InstanceMirror] reflects an instance of a Dart language object. |
| 465 */ | 372 */ |
| 466 abstract class InstanceMirror implements ObjectMirror { | 373 abstract class InstanceMirror implements ObjectMirror { |
| 467 /** | 374 /** |
| 468 * A mirror on the type of the reflectee. | 375 * A mirror on the type of the reflectee. |
| 469 * | 376 * |
| 470 * Returns a mirror on the actual class of the reflectee. | 377 * Returns a mirror on the actual class of the reflectee. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 * the result of calling [reflect](*r*). | 455 * the result of calling [reflect](*r*). |
| 549 * If the invocation causes a compilation error | 456 * If the invocation causes a compilation error |
| 550 * this method throws a [MirrorError]. | 457 * this method throws a [MirrorError]. |
| 551 * If the invocation throws an exception *e* (that it does not catch) | 458 * If the invocation throws an exception *e* (that it does not catch) |
| 552 * this method throws *e*. | 459 * this method throws *e*. |
| 553 */ | 460 */ |
| 554 InstanceMirror apply(List positionalArguments, | 461 InstanceMirror apply(List positionalArguments, |
| 555 [Map<Symbol, dynamic> namedArguments]); | 462 [Map<Symbol, dynamic> namedArguments]); |
| 556 | 463 |
| 557 /** | 464 /** |
| 558 * Executes the closure and returns a mirror on the result. | |
| 559 * | |
| 560 * Let *f* be the closure reflected by this mirror, | |
| 561 * let *a1, ..., an* be the elements of [positionalArguments] | |
| 562 * let *k1, ..., km* be the identifiers denoted by the elements of | |
| 563 * [namedArguments.keys] | |
| 564 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | |
| 565 * For each *ai*, if *ai* is an instance of [InstanceMirror], let *pi* | |
| 566 * be the object reflected by *ai*; otherwise let *pi = ai, i in 1 ...n*. | |
| 567 * Likewise, for each *vj*, if *vj* is an instance of [InstanceMirror], let | |
| 568 * *qj* | |
| 569 * be the object reflected by *vj*; otherwise let *qj = vj, j in 1 ...m*. | |
| 570 * If any of the *pi, qj* is not an instance of [InstanceMirror] and | |
| 571 * is not serializable across isolates, an exception is thrown. | |
| 572 * Then this method will perform the function invocation | |
| 573 * *f(p1, ..., pn, k1: q1, ..., km: qm)* | |
| 574 * The method returns a future *k*. | |
| 575 * If the invocation returns a result *r*, *k* will be completed | |
| 576 * with the result of calling [reflect](*r*). | |
| 577 * If the invocation throws an exception *e* (that it does not catch) | |
| 578 * then *k* is completed with a [MirrorError] wrapping *e*. | |
| 579 * | |
| 580 * The arguments must be instances of [InstanceMirror], or of | |
| 581 * a type that is serializable across isolates (currently [num], | |
| 582 * [String], or [bool]). | |
| 583 */ | |
| 584 Future<InstanceMirror> applyAsync(List positionalArguments, | |
| 585 [Map<Symbol, dynamic> namedArguments]); | |
| 586 | |
| 587 /** | |
|
gbracha
2013/09/18 22:11:29
What about newInstanceAsync? It needs to go too.
| |
| 588 * Looks up the value of a name in the scope of the closure. The | 465 * Looks up the value of a name in the scope of the closure. The |
| 589 * result is a mirror on that value. | 466 * result is a mirror on that value. |
| 590 * | 467 * |
| 591 * Let *s* be the contents of the string used to construct the symbol [name]. | 468 * Let *s* be the contents of the string used to construct the symbol [name]. |
| 592 * | 469 * |
| 593 * If the expression *s* occurs within the source code of the reflectee, | 470 * If the expression *s* occurs within the source code of the reflectee, |
| 594 * and that any such occurrence refers to a declaration outside the reflectee, | 471 * and that any such occurrence refers to a declaration outside the reflectee, |
| 595 * then let *v* be the result of evaluating the expression *s* at such | 472 * then let *v* be the result of evaluating the expression *s* at such |
| 596 * an occurrence. | 473 * an occurrence. |
| 597 * If *s = this*, and the reflectee was defined within the instance scope of | 474 * If *s = this*, and the reflectee was defined within the instance scope of |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1323 * | 1200 * |
| 1324 * When used as metadata on an import of "dart:mirrors", this metadata does | 1201 * When used as metadata on an import of "dart:mirrors", this metadata does |
| 1325 * not apply to the library in which the annotation is used, but instead | 1202 * not apply to the library in which the annotation is used, but instead |
| 1326 * applies to the other libraries (all libraries if "*" is used). | 1203 * applies to the other libraries (all libraries if "*" is used). |
| 1327 */ | 1204 */ |
| 1328 final override; | 1205 final override; |
| 1329 | 1206 |
| 1330 const MirrorsUsed( | 1207 const MirrorsUsed( |
| 1331 {this.symbols, this.targets, this.metaTargets, this.override}); | 1208 {this.symbols, this.targets, this.metaTargets, this.override}); |
| 1332 } | 1209 } |
| OLD | NEW |