Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 } | 63 } |
| 64 | 64 |
| 65 Map<Uri, LibraryMirror> _createLibrariesMap(Map<String, LibraryMirror> map) { | 65 Map<Uri, LibraryMirror> _createLibrariesMap(Map<String, LibraryMirror> map) { |
| 66 var result = new Map<Uri, LibraryMirror>(); | 66 var result = new Map<Uri, LibraryMirror>(); |
| 67 map.forEach((String url, LibraryMirror mirror) { | 67 map.forEach((String url, LibraryMirror mirror) { |
| 68 result[Uri.parse(url)] = mirror; | 68 result[Uri.parse(url)] = mirror; |
| 69 }); | 69 }); |
| 70 return result; | 70 return result; |
| 71 } | 71 } |
| 72 | 72 |
| 73 List<InstanceMirror> _metadata(mirror) | 73 List _metadata(reflectee) |
|
rmacnak
2013/07/16 21:11:15
This annotation is incorrect. The native answered
| |
| 74 native 'Mirrors_metadata'; | 74 native 'DeclarationMirror_metadata'; |
| 75 | 75 |
| 76 // This will verify the argument types, unwrap them, and ensure we have a fixed | 76 // This will verify the argument types, unwrap them, and ensure we have a fixed |
| 77 // array. | 77 // array. |
| 78 List _unwarpAsyncPositionals(wrappedArgs){ | 78 List _unwarpAsyncPositionals(wrappedArgs){ |
| 79 List unwrappedArgs = new List(wrappedArgs.length); | 79 List unwrappedArgs = new List(wrappedArgs.length); |
| 80 for(int i = 0; i < wrappedArgs.length; i++){ | 80 for(int i = 0; i < wrappedArgs.length; i++){ |
| 81 var wrappedArg = wrappedArgs[i]; | 81 var wrappedArg = wrappedArgs[i]; |
| 82 if(_isSimpleValue(wrappedArg)) { | 82 if(_isSimpleValue(wrappedArg)) { |
| 83 unwrappedArgs[i] = wrappedArg; | 83 unwrappedArgs[i] = wrappedArg; |
| 84 } else if(wrappedArg is InstanceMirror) { | 84 } else if(wrappedArg is InstanceMirror) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 String toString() => "IsolateMirror on '$debugName'"; | 164 String toString() => "IsolateMirror on '$debugName'"; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // A VMReference is used to hold a reference to a VM-internal object, | 167 // A VMReference is used to hold a reference to a VM-internal object, |
| 168 // which can include things like libraries, classes, etc. | 168 // which can include things like libraries, classes, etc. |
| 169 class VMReference extends NativeFieldWrapperClass1 { | 169 class VMReference extends NativeFieldWrapperClass1 { |
| 170 } | 170 } |
| 171 | 171 |
| 172 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl { | 172 abstract class _LocalVMObjectMirrorImpl extends _LocalMirrorImpl { |
| 173 _LocalVMObjectMirrorImpl(this._reference) {} | 173 _LocalVMObjectMirrorImpl(this._reference) {} |
| 174 | 174 |
| 175 // For now, all VMObjects hold a VMReference. We could consider | 175 // For now, all VMObjects hold a VMReference. We could consider |
| 176 // storing the Object reference itself here if the object is a Dart | 176 // storing the Object reference itself here if the object is a Dart |
| 177 // language objects (except for objects of type VMReference, of | 177 // language objects (except for objects of type VMReference, of |
| 178 // course). | 178 // course). |
| 179 VMReference _reference; | 179 VMReference _reference; |
| 180 } | 180 } |
| 181 | 181 |
| 182 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl | 182 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl |
| 183 implements ObjectMirror { | 183 implements ObjectMirror { |
| 184 _LocalObjectMirrorImpl(this._reflectee, ref) : super(ref) {} | 184 _LocalObjectMirrorImpl(this._reflectee, ref) : super(ref) {} |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 _n(constructorName), | 577 _n(constructorName), |
| 578 _unwarpAsyncPositionals(positionalArgument s)); | 578 _unwarpAsyncPositionals(positionalArgument s)); |
| 579 return new Future.value(reflect(result)); | 579 return new Future.value(reflect(result)); |
| 580 } on MirroredError catch(e) { | 580 } on MirroredError catch(e) { |
| 581 return new Future.error(e); | 581 return new Future.error(e); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 // get the metadata objects, convert them into InstanceMirrors using | 585 // get the metadata objects, convert them into InstanceMirrors using |
| 586 // reflect() and then make them into a Dart list | 586 // reflect() and then make them into a Dart list |
| 587 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList(); | 587 List<InstanceMirror> get metadata => _metadata(_reflectee).map(reflect).toList (); |
| 588 | 588 |
| 589 | 589 |
| 590 static _name(reflectee) | 590 static _name(reflectee) |
| 591 native "ClassMirror_name"; | 591 native "ClassMirror_name"; |
| 592 | 592 |
| 593 _invoke(reflectee, memberName, positionalArguments) | 593 _invoke(reflectee, memberName, positionalArguments) |
| 594 native 'ClassMirror_invoke'; | 594 native 'ClassMirror_invoke'; |
| 595 | 595 |
| 596 _invokeGetter(reflectee, getterName) | 596 _invokeGetter(reflectee, getterName) |
| 597 native 'ClassMirror_invokeGetter'; | 597 native 'ClassMirror_invokeGetter'; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 } | 695 } |
| 696 | 696 |
| 697 var _upperBound; | 697 var _upperBound; |
| 698 TypeMirror get upperBound { | 698 TypeMirror get upperBound { |
| 699 if (_upperBound is! Mirror) { | 699 if (_upperBound is! Mirror) { |
| 700 _upperBound = _upperBound.resolve(mirrors); | 700 _upperBound = _upperBound.resolve(mirrors); |
| 701 } | 701 } |
| 702 return _upperBound; | 702 return _upperBound; |
| 703 } | 703 } |
| 704 | 704 |
| 705 // get the metadata objects, convert them into InstanceMirrors using | 705 List<InstanceMirror> get metadata { |
|
rmacnak
2013/07/16 21:11:15
Previously this would always answer an empty list,
| |
| 706 // reflect() and then make them into a Dart list | 706 throw new UnimplementedError( |
| 707 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList(); | 707 'TypeVariableMirror.metadata is not implemented'); |
| 708 } | |
| 708 | 709 |
| 709 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 710 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
| 710 } | 711 } |
| 711 | 712 |
| 712 | 713 |
| 713 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl | 714 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl |
| 714 implements TypedefMirror { | 715 implements TypedefMirror { |
| 715 _LocalTypedefMirrorImpl(String simpleName, | 716 _LocalTypedefMirrorImpl(String simpleName, |
| 716 this._owner, | 717 this._owner, |
| 717 this._referent) | 718 this._referent) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 Map<Symbol, VariableMirror> get variables { | 842 Map<Symbol, VariableMirror> get variables { |
| 842 if (_variables == null) { | 843 if (_variables == null) { |
| 843 _variables = _filterMap(members, | 844 _variables = _filterMap(members, |
| 844 (key, value) => (value is VariableMirror)); | 845 (key, value) => (value is VariableMirror)); |
| 845 } | 846 } |
| 846 return _variables; | 847 return _variables; |
| 847 } | 848 } |
| 848 | 849 |
| 849 // get the metadata objects, convert them into InstanceMirrors using | 850 // get the metadata objects, convert them into InstanceMirrors using |
| 850 // reflect() and then make them into a Dart list | 851 // reflect() and then make them into a Dart list |
| 851 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList(); | 852 List<InstanceMirror> get metadata => _metadata(_reflectee).map(reflect).toList (); |
| 852 | 853 |
| 853 String toString() => "LibraryMirror on '${_n(simpleName)}'"; | 854 String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
| 854 | 855 |
| 855 _invoke(reflectee, memberName, positionalArguments) | 856 _invoke(reflectee, memberName, positionalArguments) |
| 856 native 'LibraryMirror_invoke'; | 857 native 'LibraryMirror_invoke'; |
| 857 | 858 |
| 858 _invokeGetter(reflectee, getterName) | 859 _invokeGetter(reflectee, getterName) |
| 859 native 'LibraryMirror_invokeGetter'; | 860 native 'LibraryMirror_invokeGetter'; |
| 860 | 861 |
| 861 _invokeSetter(reflectee, setterName, value) | 862 _invokeSetter(reflectee, setterName, value) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 | 964 |
| 964 final bool isConstConstructor; | 965 final bool isConstConstructor; |
| 965 final bool isGenerativeConstructor; | 966 final bool isGenerativeConstructor; |
| 966 final bool isRedirectingConstructor; | 967 final bool isRedirectingConstructor; |
| 967 final bool isFactoryConstructor; | 968 final bool isFactoryConstructor; |
| 968 | 969 |
| 969 List<InstanceMirror> get metadata { | 970 List<InstanceMirror> get metadata { |
| 970 owner; // ensure owner is computed | 971 owner; // ensure owner is computed |
| 971 // get the metadata objects, convert them into InstanceMirrors using | 972 // get the metadata objects, convert them into InstanceMirrors using |
| 972 // reflect() and then make them into a Dart list | 973 // reflect() and then make them into a Dart list |
| 973 return _metadata(this).map(reflect).toList(); | 974 return _metadata(_reflectee).map(reflect).toList(); |
| 974 } | 975 } |
| 975 | 976 |
| 976 String toString() => "MethodMirror on '${_n(simpleName)}'"; | 977 String toString() => "MethodMirror on '${_n(simpleName)}'"; |
| 977 | 978 |
| 978 static String _MethodMirror_name(reflectee) | 979 static String _MethodMirror_name(reflectee) |
| 979 native "MethodMirror_name"; | 980 native "MethodMirror_name"; |
| 980 } | 981 } |
| 981 | 982 |
| 982 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 983 class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
| 983 implements VariableMirror { | 984 implements VariableMirror { |
| 984 _LocalVariableMirrorImpl(String simpleName, | 985 _LocalVariableMirrorImpl(this._reflectee, |
| 986 String simpleName, | |
| 985 this._owner, | 987 this._owner, |
| 986 this._type, | 988 this._type, |
| 987 this.isStatic, | 989 this.isStatic, |
| 988 this.isFinal) | 990 this.isFinal) |
| 989 : this.simpleName = _s(simpleName); | 991 : this.simpleName = _s(simpleName); |
| 990 | 992 |
| 993 final _MirrorReference _reflectee; | |
| 991 final Symbol simpleName; | 994 final Symbol simpleName; |
| 992 | 995 |
| 993 Symbol _qualifiedName = null; | 996 Symbol _qualifiedName = null; |
| 994 Symbol get qualifiedName { | 997 Symbol get qualifiedName { |
| 995 if (_qualifiedName == null) { | 998 if (_qualifiedName == null) { |
| 996 _qualifiedName = _computeQualifiedName(owner, simpleName); | 999 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 997 } | 1000 } |
| 998 return _qualifiedName; | 1001 return _qualifiedName; |
| 999 } | 1002 } |
| 1000 | 1003 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1024 if (_type is! Mirror) { | 1027 if (_type is! Mirror) { |
| 1025 _type = _type.resolve(mirrors); | 1028 _type = _type.resolve(mirrors); |
| 1026 } | 1029 } |
| 1027 return _type; | 1030 return _type; |
| 1028 } | 1031 } |
| 1029 | 1032 |
| 1030 final bool isStatic; | 1033 final bool isStatic; |
| 1031 final bool isFinal; | 1034 final bool isFinal; |
| 1032 | 1035 |
| 1033 List<InstanceMirror> get metadata { | 1036 List<InstanceMirror> get metadata { |
| 1034 owner; // ensure owner is computed | |
| 1035 // get the metadata objects, convert them into InstanceMirrors using | 1037 // get the metadata objects, convert them into InstanceMirrors using |
| 1036 // reflect() and then make them into a Dart list | 1038 // reflect() and then make them into a Dart list |
| 1037 return _metadata(this).map(reflect).toList(); | 1039 return _metadata(_reflectee).map(reflect).toList(); |
| 1038 } | 1040 } |
| 1039 | 1041 |
| 1040 String toString() => "VariableMirror on '${_n(simpleName)}'"; | 1042 String toString() => "VariableMirror on '${_n(simpleName)}'"; |
| 1041 } | 1043 } |
| 1042 | 1044 |
| 1043 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | 1045 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl |
| 1044 implements ParameterMirror { | 1046 implements ParameterMirror { |
| 1045 _LocalParameterMirrorImpl(type, this.isOptional) | 1047 _LocalParameterMirrorImpl(type, this.isOptional) |
| 1046 : super('<TODO:unnamed>', null, type, false, false) {} | 1048 : super(null, '<TODO:unnamed>', null, type, false, false) {} |
| 1047 | 1049 |
| 1048 final bool isOptional; | 1050 final bool isOptional; |
| 1049 | 1051 |
| 1050 String get defaultValue { | 1052 String get defaultValue { |
| 1051 throw new UnimplementedError( | 1053 throw new UnimplementedError( |
| 1052 'ParameterMirror.defaultValue is not implemented'); | 1054 'ParameterMirror.defaultValue is not implemented'); |
| 1053 } | 1055 } |
| 1054 | 1056 |
| 1055 bool get hasDefaultValue { | 1057 bool get hasDefaultValue { |
| 1056 throw new UnimplementedError( | 1058 throw new UnimplementedError( |
| 1057 'ParameterMirror.hasDefaultValue is not implemented'); | 1059 'ParameterMirror.hasDefaultValue is not implemented'); |
| 1058 } | 1060 } |
| 1061 | |
| 1062 // TODO(11418): Implement. | |
| 1063 List<InstanceMirror> get metadata { | |
|
rmacnak
2013/07/16 21:11:15
Previously this raised a fatal, non-meaningful err
| |
| 1064 throw new UnimplementedError( | |
| 1065 'ParameterMirror.metadata is not implemented'); | |
| 1066 } | |
| 1059 } | 1067 } |
| 1060 | 1068 |
| 1061 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1069 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
| 1062 implements TypeMirror, DeclarationMirror { | 1070 implements TypeMirror, DeclarationMirror { |
| 1063 _SpecialTypeMirrorImpl(this.simpleName); | 1071 _SpecialTypeMirrorImpl(this.simpleName); |
| 1064 | 1072 |
| 1065 final bool isPrivate = false; | 1073 final bool isPrivate = false; |
| 1066 final bool isTopLevel = true; | 1074 final bool isTopLevel = true; |
| 1067 | 1075 |
| 1068 // Fixed length 0, therefore immutable. | 1076 // Fixed length 0, therefore immutable. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 } | 1134 } |
| 1127 | 1135 |
| 1128 // Creates a new local ClassMirror. | 1136 // Creates a new local ClassMirror. |
| 1129 static ClassMirror makeLocalClassMirror(Type key) | 1137 static ClassMirror makeLocalClassMirror(Type key) |
| 1130 native "Mirrors_makeLocalClassMirror"; | 1138 native "Mirrors_makeLocalClassMirror"; |
| 1131 | 1139 |
| 1132 static ClassMirror reflectClass(Type key) { | 1140 static ClassMirror reflectClass(Type key) { |
| 1133 return makeLocalClassMirror(key); | 1141 return makeLocalClassMirror(key); |
| 1134 } | 1142 } |
| 1135 } | 1143 } |
| OLD | NEW |