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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // For now, all VMObjects hold a VMReference. We could consider | 132 // For now, all VMObjects hold a VMReference. We could consider |
133 // storing the Object reference itself here if the object is a Dart | 133 // storing the Object reference itself here if the object is a Dart |
134 // language objects (except for objects of type VMReference, of | 134 // language objects (except for objects of type VMReference, of |
135 // course). | 135 // course). |
136 VMReference _reference; | 136 VMReference _reference; |
137 } | 137 } |
138 | 138 |
139 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl | 139 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl |
140 implements ObjectMirror { | 140 implements ObjectMirror { |
141 _LocalObjectMirrorImpl(ref) : super(ref) {} | 141 _LocalObjectMirrorImpl(ref) : super(ref) {} |
142 | 142 |
143 Future<InstanceMirror> invoke(String memberName, | 143 Future<InstanceMirror> invokeAsync(String memberName, |
144 List positionalArguments, | 144 List positionalArguments, |
145 [Map<String,dynamic> namedArguments]) { | 145 [Map<String,dynamic> namedArguments]) { |
146 if (namedArguments != null) { | 146 if (namedArguments != null) { |
147 throw new UnimplementedError( | 147 throw new UnimplementedError( |
148 'named argument support is not implemented'); | 148 'named argument support is not implemented'); |
149 } | 149 } |
150 // Walk the arguments and make sure they are legal. | 150 // Walk the arguments and make sure they are legal. |
151 for (int i = 0; i < positionalArguments.length; i++) { | 151 for (int i = 0; i < positionalArguments.length; i++) { |
152 var arg = positionalArguments[i]; | 152 var arg = positionalArguments[i]; |
153 _validateArgument(i, arg); | 153 _validateArgument(i, arg); |
154 } | 154 } |
155 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 155 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
156 try { | 156 try { |
157 completer.complete( | 157 completer.complete( |
158 _invoke(this, memberName, positionalArguments)); | 158 _invoke(this, memberName, positionalArguments)); |
159 } catch (exception, s) { | 159 } catch (exception, s) { |
160 completer.completeError(exception, s); | 160 completer.completeError(exception, s); |
161 } | 161 } |
162 return completer.future; | 162 return completer.future; |
163 } | 163 } |
164 | 164 |
165 Future<InstanceMirror> getField(String fieldName) | 165 Future<InstanceMirror> getFieldAsync(String fieldName) { |
166 { | |
167 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 166 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
168 try { | 167 try { |
169 completer.complete(_getField(this, fieldName)); | 168 completer.complete(_getField(this, fieldName)); |
170 } catch (exception, s) { | 169 } catch (exception, s) { |
171 completer.completeError(exception, s); | 170 completer.completeError(exception, s); |
172 } | 171 } |
173 return completer.future; | 172 return completer.future; |
174 } | 173 } |
175 | 174 |
176 Future<InstanceMirror> setField(String fieldName, Object arg) | 175 Future<InstanceMirror> setFieldAsync(String fieldName, Object arg) { |
177 { | |
178 _validateArgument(0, arg); | 176 _validateArgument(0, arg); |
179 | 177 |
180 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 178 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
181 try { | 179 try { |
182 completer.complete(_setField(this, fieldName, arg)); | 180 completer.complete(_setField(this, fieldName, arg)); |
183 } catch (exception, s) { | 181 } catch (exception, s) { |
184 completer.completeError(exception, s); | 182 completer.completeError(exception, s); |
185 } | 183 } |
186 return completer.future; | 184 return completer.future; |
187 } | 185 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 reflectee, | 296 reflectee, |
299 this.function) : super(ref, type, reflectee) {} | 297 this.function) : super(ref, type, reflectee) {} |
300 | 298 |
301 final MethodMirror function; | 299 final MethodMirror function; |
302 | 300 |
303 String get source { | 301 String get source { |
304 throw new UnimplementedError( | 302 throw new UnimplementedError( |
305 'ClosureMirror.source is not implemented'); | 303 'ClosureMirror.source is not implemented'); |
306 } | 304 } |
307 | 305 |
308 Future<InstanceMirror> apply(List<Object> positionalArguments, | 306 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, |
309 [Map<String,Object> namedArguments]) { | 307 [Map<String,Object> namedArguments]) { |
310 if (namedArguments != null) { | 308 if (namedArguments != null) { |
311 throw new UnimplementedError( | 309 throw new UnimplementedError( |
312 'named argument support is not implemented'); | 310 'named argument support is not implemented'); |
313 } | 311 } |
314 // Walk the arguments and make sure they are legal. | 312 // Walk the arguments and make sure they are legal. |
315 for (int i = 0; i < positionalArguments.length; i++) { | 313 for (int i = 0; i < positionalArguments.length; i++) { |
316 var arg = positionalArguments[i]; | 314 var arg = positionalArguments[i]; |
317 _LocalObjectMirrorImpl._validateArgument(i, arg); | 315 _LocalObjectMirrorImpl._validateArgument(i, arg); |
318 } | 316 } |
319 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 317 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 'ClassMirror.isOriginalDeclaration is not implemented'); | 492 'ClassMirror.isOriginalDeclaration is not implemented'); |
495 } | 493 } |
496 | 494 |
497 ClassMirror get genericDeclaration { | 495 ClassMirror get genericDeclaration { |
498 throw new UnimplementedError( | 496 throw new UnimplementedError( |
499 'ClassMirror.originalDeclaration is not implemented'); | 497 'ClassMirror.originalDeclaration is not implemented'); |
500 } | 498 } |
501 | 499 |
502 String toString() => "ClassMirror on '$simpleName'"; | 500 String toString() => "ClassMirror on '$simpleName'"; |
503 | 501 |
504 Future<InstanceMirror> newInstance(String constructorName, | 502 Future<InstanceMirror> newInstanceAsync(String constructorName, |
505 List positionalArguments, | 503 List positionalArguments, |
506 [Map<String,dynamic> namedArguments]) { | 504 [Map<String,dynamic> namedArguments])
{ |
507 if (namedArguments != null) { | 505 if (namedArguments != null) { |
508 throw new UnimplementedError( | 506 throw new UnimplementedError( |
509 'named argument support is not implemented'); | 507 'named argument support is not implemented'); |
510 } | 508 } |
511 // Walk the arguments and make sure they are legal. | 509 // Walk the arguments and make sure they are legal. |
512 for (int i = 0; i < positionalArguments.length; i++) { | 510 for (int i = 0; i < positionalArguments.length; i++) { |
513 var arg = positionalArguments[i]; | 511 var arg = positionalArguments[i]; |
514 _LocalObjectMirrorImpl._validateArgument(i, arg); | 512 _LocalObjectMirrorImpl._validateArgument(i, arg); |
515 } | 513 } |
516 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 514 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 } | 961 } |
964 | 962 |
965 // Creates a new local InstanceMirror | 963 // Creates a new local InstanceMirror |
966 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 964 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
967 native 'Mirrors_makeLocalInstanceMirror'; | 965 native 'Mirrors_makeLocalInstanceMirror'; |
968 | 966 |
969 // Creates a new local mirror for some Object. | 967 // Creates a new local mirror for some Object. |
970 static InstanceMirror reflect(Object reflectee) { | 968 static InstanceMirror reflect(Object reflectee) { |
971 return makeLocalInstanceMirror(reflectee); | 969 return makeLocalInstanceMirror(reflectee); |
972 } | 970 } |
| 971 |
| 972 static ClassMirror reflectClass(Type reflectee) { |
| 973 throw new UnimplementedError('reflectClass is not implemented'); |
| 974 } |
973 } | 975 } |
OLD | NEW |