| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 261 } |
| 262 | 262 |
| 263 Future<ObjectMirror> apply(List<Object> positionalArguments, | 263 Future<ObjectMirror> apply(List<Object> positionalArguments, |
| 264 [Map<String,Object> namedArguments]) { | 264 [Map<String,Object> namedArguments]) { |
| 265 if (namedArguments !== null) { | 265 if (namedArguments !== null) { |
| 266 throw new NotImplementedException('named arguments not implemented'); | 266 throw new NotImplementedException('named arguments not implemented'); |
| 267 } | 267 } |
| 268 // Walk the arguments and make sure they are legal. | 268 // Walk the arguments and make sure they are legal. |
| 269 for (int i = 0; i < positionalArguments.length; i++) { | 269 for (int i = 0; i < positionalArguments.length; i++) { |
| 270 var arg = positionalArguments[i]; | 270 var arg = positionalArguments[i]; |
| 271 if (arg is Mirror) { | 271 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 272 if (arg is! InstanceMirror) { | |
| 273 throw new MirrorException( | |
| 274 'positional argument $i ($arg) was not an InstanceMirror'); | |
| 275 } | |
| 276 } else if (!isSimpleValue(arg)) { | |
| 277 throw new MirrorException( | |
| 278 'positional argument $i ($arg) was not a simple value'); | |
| 279 } | |
| 280 } | 272 } |
| 281 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 273 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 282 try { | 274 try { |
| 283 completer.complete( | 275 completer.complete( |
| 284 _apply(this, positionalArguments)); | 276 _apply(this, positionalArguments)); |
| 285 } catch (var exception) { | 277 } catch (var exception) { |
| 286 completer.completeException(exception); | 278 completer.completeException(exception); |
| 287 } | 279 } |
| 288 return completer.future; | 280 return completer.future; |
| 289 } | 281 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (_variables == null) { | 378 if (_variables == null) { |
| 387 _variables = filterMap(members(), | 379 _variables = filterMap(members(), |
| 388 (key, value) => (value is VariableMirror)); | 380 (key, value) => (value is VariableMirror)); |
| 389 } | 381 } |
| 390 return _variables; | 382 return _variables; |
| 391 } | 383 } |
| 392 | 384 |
| 393 String toString() { | 385 String toString() { |
| 394 return "InterfaceMirror on '$simpleName'"; | 386 return "InterfaceMirror on '$simpleName'"; |
| 395 } | 387 } |
| 388 |
| 389 Future<InstanceMirror> newInstance(String constructorName, |
| 390 List positionalArguments, |
| 391 [Map<String,Dynamic> namedArguments]) { |
| 392 if (namedArguments !== null) { |
| 393 throw new NotImplementedException('named arguments not implemented'); |
| 394 } |
| 395 // Walk the arguments and make sure they are legal. |
| 396 for (int i = 0; i < positionalArguments.length; i++) { |
| 397 var arg = positionalArguments[i]; |
| 398 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 399 } |
| 400 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 401 try { |
| 402 completer.complete( |
| 403 _invokeConstructor(this, constructorName, positionalArguments)); |
| 404 } catch (var exception) { |
| 405 completer.completeException(exception); |
| 406 } |
| 407 return completer.future; |
| 408 } |
| 409 |
| 410 static _invokeConstructor(ref, constructorName, positionalArguments) |
| 411 native 'LocalInterfaceMirrorImpl_invokeConstructor'; |
| 396 } | 412 } |
| 397 | 413 |
| 398 class _LazyLibraryMirror { | 414 class _LazyLibraryMirror { |
| 399 _LazyLibraryMirror(this.libraryName) {} | 415 _LazyLibraryMirror(this.libraryName) {} |
| 400 | 416 |
| 401 LibraryMirror resolve(MirrorSystem mirrors) { | 417 LibraryMirror resolve(MirrorSystem mirrors) { |
| 402 return mirrors.libraries()[libraryName]; | 418 return mirrors.libraries()[libraryName]; |
| 403 } | 419 } |
| 404 | 420 |
| 405 final String libraryName; | 421 final String libraryName; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 | 597 |
| 582 // Creates a new local InstanceMirror | 598 // Creates a new local InstanceMirror |
| 583 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 599 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 584 native 'Mirrors_makeLocalInstanceMirror'; | 600 native 'Mirrors_makeLocalInstanceMirror'; |
| 585 | 601 |
| 586 // Creates a new local mirror for some Object. | 602 // Creates a new local mirror for some Object. |
| 587 static InstanceMirror mirrorOf(Object reflectee) { | 603 static InstanceMirror mirrorOf(Object reflectee) { |
| 588 return makeLocalInstanceMirror(reflectee); | 604 return makeLocalInstanceMirror(reflectee); |
| 589 } | 605 } |
| 590 } | 606 } |
| OLD | NEW |