| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; | 240 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; |
| 241 } else { | 241 } else { |
| 242 return "InstanceMirror on <$_reflectee>"; | 242 return "InstanceMirror on <$_reflectee>"; |
| 243 } | 243 } |
| 244 } else { | 244 } else { |
| 245 return "InstanceMirror on instance of '${getClass().simpleName}'"; | 245 return "InstanceMirror on instance of '${getClass().simpleName}'"; |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl |
| 251 implements ClosureMirror { |
| 252 _LocalClosureMirrorImpl(ref, |
| 253 klass, |
| 254 reflectee) : super(ref, klass, reflectee) {} |
| 255 |
| 256 MethodMirror _function; |
| 257 MethodMirror function() => _function; |
| 258 |
| 259 String source() { |
| 260 throw new NotImplementedException('ClosureMirror.source() not implemented'); |
| 261 } |
| 262 |
| 263 Future<ObjectMirror> apply(List<Object> positionalArguments, |
| 264 [Map<String,Object> namedArguments]) { |
| 265 if (namedArguments !== null) { |
| 266 throw new NotImplementedException('named arguments not implemented'); |
| 267 } |
| 268 // Walk the arguments and make sure they are legal. |
| 269 for (int i = 0; i < positionalArguments.length; i++) { |
| 270 var arg = positionalArguments[i]; |
| 271 if (arg is Mirror) { |
| 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 } |
| 281 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 282 try { |
| 283 completer.complete( |
| 284 _apply(this, positionalArguments)); |
| 285 } catch (var exception) { |
| 286 completer.completeException(exception); |
| 287 } |
| 288 return completer.future; |
| 289 } |
| 290 |
| 291 Future<ObjectMirror> findInContext(String name) { |
| 292 throw "asYetUnimplemented"; |
| 293 } |
| 294 |
| 295 static _apply(ref, positionalArguments) |
| 296 native 'LocalClosureMirrorImpl_apply'; |
| 297 } |
| 298 |
| 250 class _LazyInterfaceMirror { | 299 class _LazyInterfaceMirror { |
| 251 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} | 300 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} |
| 252 | 301 |
| 253 InterfaceMirror resolve(MirrorSystem mirrors) { | 302 InterfaceMirror resolve(MirrorSystem mirrors) { |
| 254 if (libraryName === null) { | 303 if (libraryName === null) { |
| 255 if (interfaceName == 'Dynamic') { | 304 if (interfaceName == 'Dynamic') { |
| 256 return mirrors._dynamicMirror(); | 305 return mirrors._dynamicMirror(); |
| 257 } else if (interfaceName == 'void') { | 306 } else if (interfaceName == 'void') { |
| 258 return mirrors._dynamicMirror(); | 307 return mirrors._dynamicMirror(); |
| 259 } else { | 308 } else { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 581 |
| 533 // Creates a new local InstanceMirror | 582 // Creates a new local InstanceMirror |
| 534 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 583 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 535 native 'Mirrors_makeLocalInstanceMirror'; | 584 native 'Mirrors_makeLocalInstanceMirror'; |
| 536 | 585 |
| 537 // Creates a new local mirror for some Object. | 586 // Creates a new local mirror for some Object. |
| 538 static InstanceMirror mirrorOf(Object reflectee) { | 587 static InstanceMirror mirrorOf(Object reflectee) { |
| 539 return makeLocalInstanceMirror(reflectee); | 588 return makeLocalInstanceMirror(reflectee); |
| 540 } | 589 } |
| 541 } | 590 } |
| OLD | NEW |