| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 291 } |
| 292 break; | 292 break; |
| 293 } | 293 } |
| 294 buf.write(output); | 294 buf.write(output); |
| 295 } | 295 } |
| 296 return buf.toString(); | 296 return buf.toString(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl | 299 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl |
| 300 implements InstanceMirror { | 300 implements InstanceMirror { |
| 301 // TODO(ahe): This is a hack, see delegate below. |
| 302 static Function _invokeOnClosure; |
| 303 |
| 301 _LocalInstanceMirrorImpl(ref, | 304 _LocalInstanceMirrorImpl(ref, |
| 302 this._type, | 305 this._type, |
| 303 this._reflectee) : super(ref) {} | 306 this._reflectee) : super(ref) {} |
| 304 | 307 |
| 305 var _type; | 308 var _type; |
| 306 ClassMirror get type { | 309 ClassMirror get type { |
| 307 if (_type is! Mirror) { | 310 if (_type is! Mirror) { |
| 308 _type = _type.resolve(mirrors); | 311 _type = _type.resolve(mirrors); |
| 309 } | 312 } |
| 310 return _type; | 313 return _type; |
| 311 } | 314 } |
| 312 | 315 |
| 313 // LocalInstanceMirrors always reflect local instances | 316 // LocalInstanceMirrors always reflect local instances |
| 314 bool hasReflectee = true; | 317 bool hasReflectee = true; |
| 315 | 318 |
| 316 var _reflectee; | 319 var _reflectee; |
| 317 get reflectee => _reflectee; | 320 get reflectee => _reflectee; |
| 318 | 321 |
| 322 delegate(Invocation invocation) { |
| 323 if (_invokeOnClosure == null) { |
| 324 // TODO(ahe): This is a total hack. We're using the mirror |
| 325 // system to access a private field in a different library. For |
| 326 // some reason, that works. On the other hand, calling a |
| 327 // private method does not work. |
| 328 _LocalInstanceMirrorImpl mirror = |
| 329 _Mirrors.makeLocalInstanceMirror(invocation); |
| 330 _invokeOnClosure = |
| 331 _LocalObjectMirrorImpl._getField(mirror.type, '_invokeOnClosure') |
| 332 .reflectee; |
| 333 } |
| 334 return _invokeOnClosure(reflectee, invocation); |
| 335 } |
| 336 |
| 319 String toString() { | 337 String toString() { |
| 320 if (_isSimpleValue(_reflectee)) { | 338 if (_isSimpleValue(_reflectee)) { |
| 321 if (_reflectee is String) { | 339 if (_reflectee is String) { |
| 322 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; | 340 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; |
| 323 } else { | 341 } else { |
| 324 return "InstanceMirror on <$_reflectee>"; | 342 return "InstanceMirror on <$_reflectee>"; |
| 325 } | 343 } |
| 326 } else { | 344 } else { |
| 327 return "InstanceMirror on instance of '${type.simpleName}'"; | 345 return "InstanceMirror on instance of '${type.simpleName}'"; |
| 328 } | 346 } |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 } | 1066 } |
| 1049 | 1067 |
| 1050 // Creates a new local ClassMirror. | 1068 // Creates a new local ClassMirror. |
| 1051 static ClassMirror makeLocalClassMirror(Type key) | 1069 static ClassMirror makeLocalClassMirror(Type key) |
| 1052 native "Mirrors_makeLocalClassMirror"; | 1070 native "Mirrors_makeLocalClassMirror"; |
| 1053 | 1071 |
| 1054 static ClassMirror reflectClass(Type key) { | 1072 static ClassMirror reflectClass(Type key) { |
| 1055 return makeLocalClassMirror(key); | 1073 return makeLocalClassMirror(key); |
| 1056 } | 1074 } |
| 1057 } | 1075 } |
| OLD | NEW |