| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (namedArguments != null) { | 205 if (namedArguments != null) { |
| 206 throw new UnimplementedError( | 206 throw new UnimplementedError( |
| 207 'named argument support is not implemented'); | 207 'named argument support is not implemented'); |
| 208 } | 208 } |
| 209 | 209 |
| 210 try { | 210 try { |
| 211 var result = this._invoke(_reflectee, | 211 var result = this._invoke(_reflectee, |
| 212 _n(memberName), | 212 _n(memberName), |
| 213 _unwarpAsyncPositionals(positionalArguments)); | 213 _unwarpAsyncPositionals(positionalArguments)); |
| 214 return new Future.value(reflect(result)); | 214 return new Future.value(reflect(result)); |
| 215 } on MirroredError catch(e) { | 215 } catch(e) { |
| 216 return new Future.error(e); | 216 return new Future.error(e); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 Future<InstanceMirror> getFieldAsync(Symbol memberName) { | 220 Future<InstanceMirror> getFieldAsync(Symbol memberName) { |
| 221 try { | 221 try { |
| 222 var result = this._invokeGetter(_reflectee, | 222 var result = this._invokeGetter(_reflectee, |
| 223 _n(memberName)); | 223 _n(memberName)); |
| 224 return new Future.value(reflect(result)); | 224 return new Future.value(reflect(result)); |
| 225 } on MirroredError catch(e) { | 225 } catch(e) { |
| 226 return new Future.error(e); | 226 return new Future.error(e); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 Future<InstanceMirror> setFieldAsync(Symbol memberName, Object value) { | 230 Future<InstanceMirror> setFieldAsync(Symbol memberName, Object value) { |
| 231 try { | 231 try { |
| 232 var unwrappedValue; | 232 var unwrappedValue; |
| 233 if(_isSimpleValue(value)) { | 233 if(_isSimpleValue(value)) { |
| 234 unwrappedValue = value; | 234 unwrappedValue = value; |
| 235 } else if(value is InstanceMirror) { | 235 } else if(value is InstanceMirror) { |
| 236 unwrappedValue = value._reflectee; | 236 unwrappedValue = value._reflectee; |
| 237 } else { | 237 } else { |
| 238 throw "setter argument ($value) must be" | 238 throw "setter argument ($value) must be" |
| 239 "a simple value or InstanceMirror"; | 239 "a simple value or InstanceMirror"; |
| 240 } | 240 } |
| 241 | 241 |
| 242 var result = this._invokeSetter(_reflectee, | 242 var result = this._invokeSetter(_reflectee, |
| 243 _n(memberName), | 243 _n(memberName), |
| 244 unwrappedValue); | 244 unwrappedValue); |
| 245 return new Future.value(reflect(result)); | 245 return new Future.value(reflect(result)); |
| 246 } on MirroredError catch(e) { | 246 } catch(e) { |
| 247 return new Future.error(e); | 247 return new Future.error(e); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 static _validateArgument(int i, Object arg) | 251 static _validateArgument(int i, Object arg) |
| 252 { | 252 { |
| 253 if (arg is Mirror) { | 253 if (arg is Mirror) { |
| 254 if (arg is! InstanceMirror) { | 254 if (arg is! InstanceMirror) { |
| 255 throw new MirrorException( | 255 throw new MirrorException( |
| 256 'positional argument $i ($arg) was not an InstanceMirror'); | 256 'positional argument $i ($arg) was not an InstanceMirror'); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (namedArguments != null) { | 567 if (namedArguments != null) { |
| 568 throw new UnimplementedError( | 568 throw new UnimplementedError( |
| 569 'named argument support is not implemented'); | 569 'named argument support is not implemented'); |
| 570 } | 570 } |
| 571 | 571 |
| 572 try { | 572 try { |
| 573 var result = _invokeConstructor(_reflectee, | 573 var result = _invokeConstructor(_reflectee, |
| 574 _n(constructorName), | 574 _n(constructorName), |
| 575 _unwarpAsyncPositionals(positionalArgument
s)); | 575 _unwarpAsyncPositionals(positionalArgument
s)); |
| 576 return new Future.value(reflect(result)); | 576 return new Future.value(reflect(result)); |
| 577 } on MirroredError catch(e) { | 577 } catch(e) { |
| 578 return new Future.error(e); | 578 return new Future.error(e); |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 List<InstanceMirror> get metadata { | 582 List<InstanceMirror> get metadata { |
| 583 // Get the metadata objects, convert them into InstanceMirrors using | 583 // Get the metadata objects, convert them into InstanceMirrors using |
| 584 // reflect() and then make them into a Dart list. | 584 // reflect() and then make them into a Dart list. |
| 585 return _metadata(_reflectee).map(reflect).toList(growable:false); | 585 return _metadata(_reflectee).map(reflect).toList(growable:false); |
| 586 } | 586 } |
| 587 | 587 |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); | 1193 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); |
| 1194 static ClassMirror reflectClass(Type key) { | 1194 static ClassMirror reflectClass(Type key) { |
| 1195 var classMirror = _classMirrorCache[key]; | 1195 var classMirror = _classMirrorCache[key]; |
| 1196 if (classMirror == null) { | 1196 if (classMirror == null) { |
| 1197 classMirror = makeLocalClassMirror(key); | 1197 classMirror = makeLocalClassMirror(key); |
| 1198 _classMirrorCache[key] = classMirror; | 1198 _classMirrorCache[key] = classMirror; |
| 1199 } | 1199 } |
| 1200 return classMirror; | 1200 return classMirror; |
| 1201 } | 1201 } |
| 1202 } | 1202 } |
| OLD | NEW |