| 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 // VM-specific implementation of the dart:mirrors library. | 5 // VM-specific implementation of the dart:mirrors library. |
| 6 | 6 |
| 7 // These values are allowed to be passed directly over the wire. | 7 // These values are allowed to be passed directly over the wire. |
| 8 bool isSimpleValue(var value) { | 8 bool isSimpleValue(var value) { |
| 9 return (value === null || value is num || value is String || value is bool); | 9 return (value === null || value is num || value is String || value is bool); |
| 10 } | 10 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 // Walk the arguments and make sure they are legal. | 106 // Walk the arguments and make sure they are legal. |
| 107 for (int i = 0; i < positionalArguments.length; i++) { | 107 for (int i = 0; i < positionalArguments.length; i++) { |
| 108 var arg = positionalArguments[i]; | 108 var arg = positionalArguments[i]; |
| 109 _validateArgument(i, arg); | 109 _validateArgument(i, arg); |
| 110 } | 110 } |
| 111 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 111 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 112 try { | 112 try { |
| 113 completer.complete( | 113 completer.complete( |
| 114 _invoke(this, memberName, positionalArguments)); | 114 _invoke(this, memberName, positionalArguments)); |
| 115 } catch (var exception) { | 115 } catch (exception) { |
| 116 completer.completeException(exception); | 116 completer.completeException(exception); |
| 117 } | 117 } |
| 118 return completer.future; | 118 return completer.future; |
| 119 } | 119 } |
| 120 | 120 |
| 121 Future<InstanceMirror> getField(String fieldName) | 121 Future<InstanceMirror> getField(String fieldName) |
| 122 { | 122 { |
| 123 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 123 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 124 try { | 124 try { |
| 125 completer.complete(_getField(this, fieldName)); | 125 completer.complete(_getField(this, fieldName)); |
| 126 } catch (var exception) { | 126 } catch (exception) { |
| 127 completer.completeException(exception); | 127 completer.completeException(exception); |
| 128 } | 128 } |
| 129 return completer.future; | 129 return completer.future; |
| 130 } | 130 } |
| 131 | 131 |
| 132 Future<InstanceMirror> setField(String fieldName, Object arg) | 132 Future<InstanceMirror> setField(String fieldName, Object arg) |
| 133 { | 133 { |
| 134 _validateArgument(0, arg); | 134 _validateArgument(0, arg); |
| 135 | 135 |
| 136 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 136 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 137 try { | 137 try { |
| 138 completer.complete(_setField(this, fieldName, arg)); | 138 completer.complete(_setField(this, fieldName, arg)); |
| 139 } catch (var exception) { | 139 } catch (exception) { |
| 140 completer.completeException(exception); | 140 completer.completeException(exception); |
| 141 } | 141 } |
| 142 return completer.future; | 142 return completer.future; |
| 143 } | 143 } |
| 144 | 144 |
| 145 static _validateArgument(int i, Object arg) | 145 static _validateArgument(int i, Object arg) |
| 146 { | 146 { |
| 147 if (arg is Mirror) { | 147 if (arg is Mirror) { |
| 148 if (arg is! InstanceMirror) { | 148 if (arg is! InstanceMirror) { |
| 149 throw new MirrorException( | 149 throw new MirrorException( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 266 } |
| 267 // Walk the arguments and make sure they are legal. | 267 // Walk the arguments and make sure they are legal. |
| 268 for (int i = 0; i < positionalArguments.length; i++) { | 268 for (int i = 0; i < positionalArguments.length; i++) { |
| 269 var arg = positionalArguments[i]; | 269 var arg = positionalArguments[i]; |
| 270 _LocalObjectMirrorImpl._validateArgument(i, arg); | 270 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 271 } | 271 } |
| 272 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 272 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 273 try { | 273 try { |
| 274 completer.complete( | 274 completer.complete( |
| 275 _apply(this, positionalArguments)); | 275 _apply(this, positionalArguments)); |
| 276 } catch (var exception) { | 276 } catch (exception) { |
| 277 completer.completeException(exception); | 277 completer.completeException(exception); |
| 278 } | 278 } |
| 279 return completer.future; | 279 return completer.future; |
| 280 } | 280 } |
| 281 | 281 |
| 282 Future<ObjectMirror> findInContext(String name) { | 282 Future<ObjectMirror> findInContext(String name) { |
| 283 throw new NotImplementedException( | 283 throw new NotImplementedException( |
| 284 'ClosureMirror.findInContext() not implemented'); | 284 'ClosureMirror.findInContext() not implemented'); |
| 285 } | 285 } |
| 286 | 286 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 456 } |
| 457 // Walk the arguments and make sure they are legal. | 457 // Walk the arguments and make sure they are legal. |
| 458 for (int i = 0; i < positionalArguments.length; i++) { | 458 for (int i = 0; i < positionalArguments.length; i++) { |
| 459 var arg = positionalArguments[i]; | 459 var arg = positionalArguments[i]; |
| 460 _LocalObjectMirrorImpl._validateArgument(i, arg); | 460 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 461 } | 461 } |
| 462 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 462 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 463 try { | 463 try { |
| 464 completer.complete( | 464 completer.complete( |
| 465 _invokeConstructor(this, constructorName, positionalArguments)); | 465 _invokeConstructor(this, constructorName, positionalArguments)); |
| 466 } catch (var exception) { | 466 } catch (exception) { |
| 467 completer.completeException(exception); | 467 completer.completeException(exception); |
| 468 } | 468 } |
| 469 return completer.future; | 469 return completer.future; |
| 470 } | 470 } |
| 471 | 471 |
| 472 static _invokeConstructor(ref, constructorName, positionalArguments) | 472 static _invokeConstructor(ref, constructorName, positionalArguments) |
| 473 native 'LocalClassMirrorImpl_invokeConstructor'; | 473 native 'LocalClassMirrorImpl_invokeConstructor'; |
| 474 } | 474 } |
| 475 | 475 |
| 476 class _LazyLibraryMirror { | 476 class _LazyLibraryMirror { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 745 } |
| 746 return _currentMirrorSystem; | 746 return _currentMirrorSystem; |
| 747 } | 747 } |
| 748 | 748 |
| 749 static Future<MirrorSystem> mirrorSystemOf(SendPort port) { | 749 static Future<MirrorSystem> mirrorSystemOf(SendPort port) { |
| 750 Completer<MirrorSystem> completer = new Completer<MirrorSystem>(); | 750 Completer<MirrorSystem> completer = new Completer<MirrorSystem>(); |
| 751 if (isLocalPort(port)) { | 751 if (isLocalPort(port)) { |
| 752 // Make a local mirror system. | 752 // Make a local mirror system. |
| 753 try { | 753 try { |
| 754 completer.complete(currentMirrorSystem()); | 754 completer.complete(currentMirrorSystem()); |
| 755 } catch (var exception) { | 755 } catch (exception) { |
| 756 completer.completeException(exception); | 756 completer.completeException(exception); |
| 757 } | 757 } |
| 758 } else { | 758 } else { |
| 759 // Make a remote mirror system | 759 // Make a remote mirror system |
| 760 throw new NotImplementedException('Remote mirrors not yet implemented'); | 760 throw new NotImplementedException('Remote mirrors not yet implemented'); |
| 761 } | 761 } |
| 762 return completer.future; | 762 return completer.future; |
| 763 } | 763 } |
| 764 | 764 |
| 765 // Creates a new local InstanceMirror | 765 // Creates a new local InstanceMirror |
| 766 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 766 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 767 native 'Mirrors_makeLocalInstanceMirror'; | 767 native 'Mirrors_makeLocalInstanceMirror'; |
| 768 | 768 |
| 769 // Creates a new local mirror for some Object. | 769 // Creates a new local mirror for some Object. |
| 770 static InstanceMirror reflect(Object reflectee) { | 770 static InstanceMirror reflect(Object reflectee) { |
| 771 return makeLocalInstanceMirror(reflectee); | 771 return makeLocalInstanceMirror(reflectee); |
| 772 } | 772 } |
| 773 } | 773 } |
| OLD | NEW |