Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 14690009: Make Completers asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 [Map<Symbol, dynamic> namedArguments]) { 192 [Map<Symbol, dynamic> namedArguments]) {
193 if (namedArguments != null) { 193 if (namedArguments != null) {
194 throw new UnimplementedError( 194 throw new UnimplementedError(
195 'named argument support is not implemented'); 195 'named argument support is not implemented');
196 } 196 }
197 // Walk the arguments and make sure they are legal. 197 // Walk the arguments and make sure they are legal.
198 for (int i = 0; i < positionalArguments.length; i++) { 198 for (int i = 0; i < positionalArguments.length; i++) {
199 var arg = positionalArguments[i]; 199 var arg = positionalArguments[i];
200 _validateArgument(i, arg); 200 _validateArgument(i, arg);
201 } 201 }
202 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
203 try { 202 try {
204 completer.complete( 203 return new Future<InstanceMirror>.value(
205 _invoke(this, _n(memberName), positionalArguments, true)); 204 _invoke(this, _n(memberName), positionalArguments, true));
206 } catch (exception, s) { 205 } catch (exception, s) {
207 completer.completeError(exception, s); 206 return new Future<InstanceMirror>.error(exception, s);
208 } 207 }
209 return completer.future;
210 } 208 }
211 209
212 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { 210 Future<InstanceMirror> getFieldAsync(Symbol fieldName) {
213 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
214 try { 211 try {
215 completer.complete(_getField(this, _n(fieldName))); 212 return new Future<InstanceMirror>.value(_getField(this, _n(fieldName)));
216 } catch (exception, s) { 213 } catch (exception, s) {
217 completer.completeError(exception, s); 214 return new Future<InstanceMirror>.error(exception, s);
218 } 215 }
219 return completer.future;
220 } 216 }
221 217
222 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) { 218 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) {
223 _validateArgument(0, arg); 219 _validateArgument(0, arg);
224 220
225 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
226 try { 221 try {
227 completer.complete(_setField(this, _n(fieldName), arg, true)); 222 return new Future<InstanceMirror>.value(
223 _setField(this, _n(fieldName), arg, true));
228 } catch (exception, s) { 224 } catch (exception, s) {
229 completer.completeError(exception, s); 225 return new Future<InstanceMirror>.error(exception, s);
230 } 226 }
231 return completer.future;
232 } 227 }
233 228
234 static _validateArgument(int i, Object arg) 229 static _validateArgument(int i, Object arg)
235 { 230 {
236 if (arg is Mirror) { 231 if (arg is Mirror) {
237 if (arg is! InstanceMirror) { 232 if (arg is! InstanceMirror) {
238 throw new MirrorException( 233 throw new MirrorException(
239 'positional argument $i ($arg) was not an InstanceMirror'); 234 'positional argument $i ($arg) was not an InstanceMirror');
240 } 235 }
241 } else if (!_isSimpleValue(arg)) { 236 } else if (!_isSimpleValue(arg)) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 [Map<Symbol, Object> namedArguments]) { 376 [Map<Symbol, Object> namedArguments]) {
382 if (namedArguments != null) { 377 if (namedArguments != null) {
383 throw new UnimplementedError( 378 throw new UnimplementedError(
384 'named argument support is not implemented'); 379 'named argument support is not implemented');
385 } 380 }
386 // Walk the arguments and make sure they are legal. 381 // Walk the arguments and make sure they are legal.
387 for (int i = 0; i < positionalArguments.length; i++) { 382 for (int i = 0; i < positionalArguments.length; i++) {
388 var arg = positionalArguments[i]; 383 var arg = positionalArguments[i];
389 _LocalObjectMirrorImpl._validateArgument(i, arg); 384 _LocalObjectMirrorImpl._validateArgument(i, arg);
390 } 385 }
391 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
392 try { 386 try {
393 completer.complete( 387 return new Future<InstanceMirror>.value(
394 _apply(this, positionalArguments, true)); 388 _apply(this, positionalArguments, true));
395 } catch (exception) { 389 } catch (exception) {
396 completer.completeError(exception); 390 return new Future<InstanceMirror>.error(exception);
397 } 391 }
398 return completer.future;
399 } 392 }
400 393
401 Future<InstanceMirror> findInContext(Symbol name) { 394 Future<InstanceMirror> findInContext(Symbol name) {
402 throw new UnimplementedError( 395 throw new UnimplementedError(
403 'ClosureMirror.findInContext() is not implemented'); 396 'ClosureMirror.findInContext() is not implemented');
404 } 397 }
405 398
406 static _apply(ref, positionalArguments, async) 399 static _apply(ref, positionalArguments, async)
407 native 'LocalClosureMirrorImpl_apply'; 400 native 'LocalClosureMirrorImpl_apply';
408 } 401 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 [Map<Symbol, dynamic> namedArguments]) { 584 [Map<Symbol, dynamic> namedArguments]) {
592 if (namedArguments != null) { 585 if (namedArguments != null) {
593 throw new UnimplementedError( 586 throw new UnimplementedError(
594 'named argument support is not implemented'); 587 'named argument support is not implemented');
595 } 588 }
596 // Walk the arguments and make sure they are legal. 589 // Walk the arguments and make sure they are legal.
597 for (int i = 0; i < positionalArguments.length; i++) { 590 for (int i = 0; i < positionalArguments.length; i++) {
598 var arg = positionalArguments[i]; 591 var arg = positionalArguments[i];
599 _LocalObjectMirrorImpl._validateArgument(i, arg); 592 _LocalObjectMirrorImpl._validateArgument(i, arg);
600 } 593 }
601 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
602 try { 594 try {
603 completer.complete( 595 return new Future<InstanceMirror>.value(
604 _invokeConstructor(this, 596 _invokeConstructor(this,
605 _n(constructorName), 597 _n(constructorName),
606 positionalArguments, 598 positionalArguments,
607 true)); 599 true));
608 } catch (exception) { 600 } catch (exception) {
609 completer.completeError(exception); 601 return new Future<InstanceMirror>.error(exception);
610 } 602 }
611 return completer.future;
612 } 603 }
613 604
614 static _invokeConstructor(ref, constructorName, positionalArguments, async) 605 static _invokeConstructor(ref, constructorName, positionalArguments, async)
615 native 'LocalClassMirrorImpl_invokeConstructor'; 606 native 'LocalClassMirrorImpl_invokeConstructor';
616 } 607 }
617 608
618 class _LazyFunctionTypeMirror { 609 class _LazyFunctionTypeMirror {
619 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} 610 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
620 611
621 ClassMirror resolve(MirrorSystem mirrors) { 612 ClassMirror resolve(MirrorSystem mirrors) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1030
1040 // The MirrorSystem for the current isolate. 1031 // The MirrorSystem for the current isolate.
1041 static MirrorSystem currentMirrorSystem() { 1032 static MirrorSystem currentMirrorSystem() {
1042 if (_currentMirrorSystem == null) { 1033 if (_currentMirrorSystem == null) {
1043 _currentMirrorSystem = makeLocalMirrorSystem(); 1034 _currentMirrorSystem = makeLocalMirrorSystem();
1044 } 1035 }
1045 return _currentMirrorSystem; 1036 return _currentMirrorSystem;
1046 } 1037 }
1047 1038
1048 static Future<MirrorSystem> mirrorSystemOf(SendPort port) { 1039 static Future<MirrorSystem> mirrorSystemOf(SendPort port) {
1049 Completer<MirrorSystem> completer = new Completer<MirrorSystem>();
1050 if (isLocalPort(port)) { 1040 if (isLocalPort(port)) {
1051 // Make a local mirror system. 1041 // Make a local mirror system.
1052 try { 1042 try {
1053 completer.complete(currentMirrorSystem()); 1043 return new Future<MirrorSystem>.value(currentMirrorSystem());
1054 } catch (exception) { 1044 } catch (exception) {
1055 completer.completeError(exception); 1045 return new Future<MirrorSystem>.error(exception);
1056 } 1046 }
1057 } else { 1047 } else {
1058 // Make a remote mirror system 1048 // Make a remote mirror system
1059 throw new UnimplementedError( 1049 throw new UnimplementedError(
1060 'Remote mirror support is not implemented'); 1050 'Remote mirror support is not implemented');
1061 } 1051 }
1062 return completer.future;
1063 } 1052 }
1064 1053
1065 // Creates a new local InstanceMirror 1054 // Creates a new local InstanceMirror
1066 static InstanceMirror makeLocalInstanceMirror(Object reflectee) 1055 static InstanceMirror makeLocalInstanceMirror(Object reflectee)
1067 native 'Mirrors_makeLocalInstanceMirror'; 1056 native 'Mirrors_makeLocalInstanceMirror';
1068 1057
1069 // Creates a new local mirror for some Object. 1058 // Creates a new local mirror for some Object.
1070 static InstanceMirror reflect(Object reflectee) { 1059 static InstanceMirror reflect(Object reflectee) {
1071 return makeLocalInstanceMirror(reflectee); 1060 return makeLocalInstanceMirror(reflectee);
1072 } 1061 }
1073 1062
1074 // Creates a new local ClassMirror. 1063 // Creates a new local ClassMirror.
1075 static ClassMirror makeLocalClassMirror(Type key) 1064 static ClassMirror makeLocalClassMirror(Type key)
1076 native "Mirrors_makeLocalClassMirror"; 1065 native "Mirrors_makeLocalClassMirror";
1077 1066
1078 static ClassMirror reflectClass(Type key) { 1067 static ClassMirror reflectClass(Type key) {
1079 return makeLocalClassMirror(key); 1068 return makeLocalClassMirror(key);
1080 } 1069 }
1081 } 1070 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698