| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // storing the Object reference itself here if the object is a Dart | 155 // storing the Object reference itself here if the object is a Dart |
| 156 // language objects (except for objects of type VMReference, of | 156 // language objects (except for objects of type VMReference, of |
| 157 // course). | 157 // course). |
| 158 VMReference _reference; | 158 VMReference _reference; |
| 159 } | 159 } |
| 160 | 160 |
| 161 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl | 161 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl |
| 162 implements ObjectMirror { | 162 implements ObjectMirror { |
| 163 _LocalObjectMirrorImpl(ref) : super(ref) {} | 163 _LocalObjectMirrorImpl(ref) : super(ref) {} |
| 164 | 164 |
| 165 InstanceMirror invoke(Symbol memberName, |
| 166 List positionalArguments, |
| 167 [Map<Symbol, dynamic> namedArguments]) { |
| 168 if (namedArguments != null) { |
| 169 throw new UnimplementedError( |
| 170 'named argument support is not implemented'); |
| 171 } |
| 172 return _invoke(this, _n(memberName), positionalArguments, false); |
| 173 } |
| 174 |
| 175 InstanceMirror getField(Symbol fieldName) { |
| 176 return _getField(this, _n(fieldName)); |
| 177 } |
| 178 |
| 179 InstanceMirror setField(Symbol fieldName, Object arg) { |
| 180 return _setField(this, _n(fieldName), arg, false); |
| 181 } |
| 182 |
| 165 Future<InstanceMirror> invokeAsync(Symbol memberName, | 183 Future<InstanceMirror> invokeAsync(Symbol memberName, |
| 166 List positionalArguments, | 184 List positionalArguments, |
| 167 [Map<Symbol, dynamic> namedArguments]) { | 185 [Map<Symbol, dynamic> namedArguments]) { |
| 168 if (namedArguments != null) { | 186 if (namedArguments != null) { |
| 169 throw new UnimplementedError( | 187 throw new UnimplementedError( |
| 170 'named argument support is not implemented'); | 188 'named argument support is not implemented'); |
| 171 } | 189 } |
| 172 // Walk the arguments and make sure they are legal. | 190 // Walk the arguments and make sure they are legal. |
| 173 for (int i = 0; i < positionalArguments.length; i++) { | 191 for (int i = 0; i < positionalArguments.length; i++) { |
| 174 var arg = positionalArguments[i]; | 192 var arg = positionalArguments[i]; |
| 175 _validateArgument(i, arg); | 193 _validateArgument(i, arg); |
| 176 } | 194 } |
| 177 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 195 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 178 try { | 196 try { |
| 179 completer.complete( | 197 completer.complete( |
| 180 _invoke(this, _n(memberName), positionalArguments)); | 198 _invoke(this, _n(memberName), positionalArguments), true); |
| 181 } catch (exception, s) { | 199 } catch (exception, s) { |
| 182 completer.completeError(exception, s); | 200 completer.completeError(exception, s); |
| 183 } | 201 } |
| 184 return completer.future; | 202 return completer.future; |
| 185 } | 203 } |
| 186 | 204 |
| 187 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { | 205 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { |
| 188 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 206 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 189 try { | 207 try { |
| 190 completer.complete(_getField(this, _n(fieldName))); | 208 completer.complete(_getField(this, _n(fieldName))); |
| 191 } catch (exception, s) { | 209 } catch (exception, s) { |
| 192 completer.completeError(exception, s); | 210 completer.completeError(exception, s); |
| 193 } | 211 } |
| 194 return completer.future; | 212 return completer.future; |
| 195 } | 213 } |
| 196 | 214 |
| 197 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) { | 215 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) { |
| 198 _validateArgument(0, arg); | 216 _validateArgument(0, arg); |
| 199 | 217 |
| 200 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 218 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 201 try { | 219 try { |
| 202 completer.complete(_setField(this, _n(fieldName), arg)); | 220 completer.complete(_setField(this, _n(fieldName), arg, true)); |
| 203 } catch (exception, s) { | 221 } catch (exception, s) { |
| 204 completer.completeError(exception, s); | 222 completer.completeError(exception, s); |
| 205 } | 223 } |
| 206 return completer.future; | 224 return completer.future; |
| 207 } | 225 } |
| 208 | 226 |
| 209 static _validateArgument(int i, Object arg) | 227 static _validateArgument(int i, Object arg) |
| 210 { | 228 { |
| 211 if (arg is Mirror) { | 229 if (arg is Mirror) { |
| 212 if (arg is! InstanceMirror) { | 230 if (arg is! InstanceMirror) { |
| 213 throw new MirrorException( | 231 throw new MirrorException( |
| 214 'positional argument $i ($arg) was not an InstanceMirror'); | 232 'positional argument $i ($arg) was not an InstanceMirror'); |
| 215 } | 233 } |
| 216 } else if (!_isSimpleValue(arg)) { | 234 } else if (!_isSimpleValue(arg)) { |
| 217 throw new MirrorException( | 235 throw new MirrorException( |
| 218 'positional argument $i ($arg) was not a simple value'); | 236 'positional argument $i ($arg) was not a simple value'); |
| 219 } | 237 } |
| 220 } | 238 } |
| 221 | 239 |
| 222 static _invoke(ref, memberName, positionalArguments) | 240 static _invoke(ref, memberName, positionalArguments, async) |
| 223 native 'LocalObjectMirrorImpl_invoke'; | 241 native 'LocalObjectMirrorImpl_invoke'; |
| 224 | 242 |
| 225 static _getField(ref, fieldName) | 243 static _getField(ref, fieldName) // same for sync and async versions |
| 226 native 'LocalObjectMirrorImpl_getField'; | 244 native 'LocalObjectMirrorImpl_getField'; |
| 227 | 245 |
| 228 static _setField(ref, fieldName, value) | 246 static _setField(ref, fieldName, value, async) |
| 229 native 'LocalObjectMirrorImpl_setField'; | 247 native 'LocalObjectMirrorImpl_setField'; |
| 230 } | 248 } |
| 231 | 249 |
| 232 // Prints a string as it might appear in dart program text. | 250 // Prints a string as it might appear in dart program text. |
| 233 // TODO(turnidge): Consider truncating. | 251 // TODO(turnidge): Consider truncating. |
| 234 String _dartEscape(String str) { | 252 String _dartEscape(String str) { |
| 235 bool isNice(int code) => (code >= 32 && code <= 126); | 253 bool isNice(int code) => (code >= 32 && code <= 126); |
| 236 | 254 |
| 237 StringBuffer buf = new StringBuffer(); | 255 StringBuffer buf = new StringBuffer(); |
| 238 for (int i = 0; i < str.length; i++) { | 256 for (int i = 0; i < str.length; i++) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 reflectee, | 336 reflectee, |
| 319 this.function) : super(ref, type, reflectee) {} | 337 this.function) : super(ref, type, reflectee) {} |
| 320 | 338 |
| 321 final MethodMirror function; | 339 final MethodMirror function; |
| 322 | 340 |
| 323 String get source { | 341 String get source { |
| 324 throw new UnimplementedError( | 342 throw new UnimplementedError( |
| 325 'ClosureMirror.source is not implemented'); | 343 'ClosureMirror.source is not implemented'); |
| 326 } | 344 } |
| 327 | 345 |
| 346 InstanceMirror apply(List<Object> positionalArguments, |
| 347 [Map<Symbol, Object> namedArguments]) { |
| 348 if (namedArguments != null) { |
| 349 throw new UnimplementedError( |
| 350 'named argument support is not implemented'); |
| 351 } |
| 352 return _apply(this, positionalArguments, false); |
| 353 } |
| 354 |
| 328 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, | 355 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, |
| 329 [Map<Symbol, Object> namedArguments]) { | 356 [Map<Symbol, Object> namedArguments]) { |
| 330 if (namedArguments != null) { | 357 if (namedArguments != null) { |
| 331 throw new UnimplementedError( | 358 throw new UnimplementedError( |
| 332 'named argument support is not implemented'); | 359 'named argument support is not implemented'); |
| 333 } | 360 } |
| 334 // Walk the arguments and make sure they are legal. | 361 // Walk the arguments and make sure they are legal. |
| 335 for (int i = 0; i < positionalArguments.length; i++) { | 362 for (int i = 0; i < positionalArguments.length; i++) { |
| 336 var arg = positionalArguments[i]; | 363 var arg = positionalArguments[i]; |
| 337 _LocalObjectMirrorImpl._validateArgument(i, arg); | 364 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 338 } | 365 } |
| 339 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 366 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 340 try { | 367 try { |
| 341 completer.complete( | 368 completer.complete( |
| 342 _apply(this, positionalArguments)); | 369 _apply(this, positionalArguments, true)); |
| 343 } catch (exception) { | 370 } catch (exception) { |
| 344 completer.completeError(exception); | 371 completer.completeError(exception); |
| 345 } | 372 } |
| 346 return completer.future; | 373 return completer.future; |
| 347 } | 374 } |
| 348 | 375 |
| 349 Future<InstanceMirror> findInContext(Symbol name) { | 376 Future<InstanceMirror> findInContext(Symbol name) { |
| 350 throw new UnimplementedError( | 377 throw new UnimplementedError( |
| 351 'ClosureMirror.findInContext() is not implemented'); | 378 'ClosureMirror.findInContext() is not implemented'); |
| 352 } | 379 } |
| 353 | 380 |
| 354 static _apply(ref, positionalArguments) | 381 static _apply(ref, positionalArguments, async) |
| 355 native 'LocalClosureMirrorImpl_apply'; | 382 native 'LocalClosureMirrorImpl_apply'; |
| 356 } | 383 } |
| 357 | 384 |
| 358 class _LazyTypeMirror { | 385 class _LazyTypeMirror { |
| 359 _LazyTypeMirror(String libraryName, String typeName) | 386 _LazyTypeMirror(String libraryName, String typeName) |
| 360 : this.libraryName = _s(libraryName), | 387 : this.libraryName = _s(libraryName), |
| 361 this.typeName = _s(typeName); | 388 this.typeName = _s(typeName); |
| 362 | 389 |
| 363 TypeMirror resolve(MirrorSystem mirrors) { | 390 TypeMirror resolve(MirrorSystem mirrors) { |
| 364 if (libraryName == null) { | 391 if (libraryName == null) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 'ClassMirror.isOriginalDeclaration is not implemented'); | 542 'ClassMirror.isOriginalDeclaration is not implemented'); |
| 516 } | 543 } |
| 517 | 544 |
| 518 ClassMirror get genericDeclaration { | 545 ClassMirror get genericDeclaration { |
| 519 throw new UnimplementedError( | 546 throw new UnimplementedError( |
| 520 'ClassMirror.originalDeclaration is not implemented'); | 547 'ClassMirror.originalDeclaration is not implemented'); |
| 521 } | 548 } |
| 522 | 549 |
| 523 String toString() => "ClassMirror on '$simpleName'"; | 550 String toString() => "ClassMirror on '$simpleName'"; |
| 524 | 551 |
| 552 InstanceMirror newInstance(Symbol constructorName, |
| 553 List positionalArguments, |
| 554 [Map<Symbol, dynamic> namedArguments]) { |
| 555 if (namedArguments != null) { |
| 556 throw new UnimplementedError( |
| 557 'named argument support is not implemented'); |
| 558 } |
| 559 return _invokeConstructor(this, |
| 560 _n(constructorName), |
| 561 positionalArguments, |
| 562 false); |
| 563 } |
| 564 |
| 525 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, | 565 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, |
| 526 List positionalArguments, | 566 List positionalArguments, |
| 527 [Map<Symbol, dynamic> namedArguments])
{ | 567 [Map<Symbol, dynamic> namedArguments])
{ |
| 528 if (namedArguments != null) { | 568 if (namedArguments != null) { |
| 529 throw new UnimplementedError( | 569 throw new UnimplementedError( |
| 530 'named argument support is not implemented'); | 570 'named argument support is not implemented'); |
| 531 } | 571 } |
| 532 // Walk the arguments and make sure they are legal. | 572 // Walk the arguments and make sure they are legal. |
| 533 for (int i = 0; i < positionalArguments.length; i++) { | 573 for (int i = 0; i < positionalArguments.length; i++) { |
| 534 var arg = positionalArguments[i]; | 574 var arg = positionalArguments[i]; |
| 535 _LocalObjectMirrorImpl._validateArgument(i, arg); | 575 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 536 } | 576 } |
| 537 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 577 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 538 try { | 578 try { |
| 539 completer.complete( | 579 completer.complete( |
| 540 _invokeConstructor(this, _n(constructorName), positionalArguments)); | 580 _invokeConstructor(this, |
| 581 _n(constructorName), |
| 582 positionalArguments, |
| 583 true)); |
| 541 } catch (exception) { | 584 } catch (exception) { |
| 542 completer.completeError(exception); | 585 completer.completeError(exception); |
| 543 } | 586 } |
| 544 return completer.future; | 587 return completer.future; |
| 545 } | 588 } |
| 546 | 589 |
| 547 static _invokeConstructor(ref, constructorName, positionalArguments) | 590 static _invokeConstructor(ref, constructorName, positionalArguments, async) |
| 548 native 'LocalClassMirrorImpl_invokeConstructor'; | 591 native 'LocalClassMirrorImpl_invokeConstructor'; |
| 549 } | 592 } |
| 550 | 593 |
| 551 class _LazyFunctionTypeMirror { | 594 class _LazyFunctionTypeMirror { |
| 552 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} | 595 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} |
| 553 | 596 |
| 554 ClassMirror resolve(MirrorSystem mirrors) { | 597 ClassMirror resolve(MirrorSystem mirrors) { |
| 555 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), | 598 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), |
| 556 parameters); | 599 parameters); |
| 557 } | 600 } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1044 |
| 1002 // Creates a new local mirror for some Object. | 1045 // Creates a new local mirror for some Object. |
| 1003 static InstanceMirror reflect(Object reflectee) { | 1046 static InstanceMirror reflect(Object reflectee) { |
| 1004 return makeLocalInstanceMirror(reflectee); | 1047 return makeLocalInstanceMirror(reflectee); |
| 1005 } | 1048 } |
| 1006 | 1049 |
| 1007 static ClassMirror reflectClass(Type reflectee) { | 1050 static ClassMirror reflectClass(Type reflectee) { |
| 1008 throw new UnimplementedError('reflectClass is not implemented'); | 1051 throw new UnimplementedError('reflectClass is not implemented'); |
| 1009 } | 1052 } |
| 1010 } | 1053 } |
| OLD | NEW |