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

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

Issue 21381002: Implement mirror equality on the VM. Resolves issue 12026. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 _LocalInstanceMirrorImpl mirror = 289 _LocalInstanceMirrorImpl mirror =
290 reflect(invocation); 290 reflect(invocation);
291 _invokeOnClosure = reflectClass(invocation.runtimeType) 291 _invokeOnClosure = reflectClass(invocation.runtimeType)
292 .getField(const Symbol('_invokeOnClosure')).reflectee; 292 .getField(const Symbol('_invokeOnClosure')).reflectee;
293 } 293 }
294 return _invokeOnClosure(reflectee, invocation); 294 return _invokeOnClosure(reflectee, invocation);
295 } 295 }
296 296
297 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; 297 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}';
298 298
299 bool operator ==(other) {
300 return other is _LocalInstanceMirrorImpl &&
301 identical(_reflectee, other._reflectee);
302 }
303
304 int get hashCode => _reflectee.hashCode;
rmacnak 2013/07/31 18:38:01 _reflectee.hashCode could raise an exception. It t
siva 2013/08/01 00:05:06 Could you explain under what circumstances reflect
ahe 2013/08/06 15:28:11 This hashCode implementation is not compatible wit
305
299 _invoke(reflectee, functionName, positionalArguments) 306 _invoke(reflectee, functionName, positionalArguments)
300 native 'InstanceMirror_invoke'; 307 native 'InstanceMirror_invoke';
301 308
302 _invokeGetter(reflectee, getterName) 309 _invokeGetter(reflectee, getterName)
303 native 'InstanceMirror_invokeGetter'; 310 native 'InstanceMirror_invokeGetter';
304 311
305 _invokeSetter(reflectee, setterName, value) 312 _invokeSetter(reflectee, setterName, value)
306 native 'InstanceMirror_invokeSetter'; 313 native 'InstanceMirror_invokeSetter';
307 314
308 static _computeType(reflectee) 315 static _computeType(reflectee)
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 return new Future.error(e); 597 return new Future.error(e);
591 } 598 }
592 } 599 }
593 600
594 List<InstanceMirror> get metadata { 601 List<InstanceMirror> get metadata {
595 // Get the metadata objects, convert them into InstanceMirrors using 602 // Get the metadata objects, convert them into InstanceMirrors using
596 // reflect() and then make them into a Dart list. 603 // reflect() and then make them into a Dart list.
597 return _metadata(_reflectee).map(reflect).toList(growable:false); 604 return _metadata(_reflectee).map(reflect).toList(growable:false);
598 } 605 }
599 606
607 bool operator ==(other) {
608 return this.runtimeType == other.runtimeType &&
rmacnak 2013/07/31 18:38:01 other.runtimeType should raise an exception. Is th
siva 2013/08/01 00:05:06 Ditto question about when an exception is raised.
609 this._reflectee == other._reflectee;
610 }
611
612 int get hashCode => simpleName.hashCode;
613
600 static _name(reflectee) 614 static _name(reflectee)
601 native "ClassMirror_name"; 615 native "ClassMirror_name";
602 616
603 static _library(reflectee) 617 static _library(reflectee)
604 native "ClassMirror_library"; 618 native "ClassMirror_library";
605 619
606 static _supertype(reflectee) 620 static _supertype(reflectee)
607 native "ClassMirror_supertype"; 621 native "ClassMirror_supertype";
608 622
609 static _interfaces(reflectee) 623 static _interfaces(reflectee)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 _qualifiedName = _computeQualifiedName(owner, simpleName); 699 _qualifiedName = _computeQualifiedName(owner, simpleName);
686 } 700 }
687 return _qualifiedName; 701 return _qualifiedName;
688 } 702 }
689 703
690 List<InstanceMirror> get metadata { 704 List<InstanceMirror> get metadata {
691 // Get the metadata objects, convert them into InstanceMirrors using 705 // Get the metadata objects, convert them into InstanceMirrors using
692 // reflect() and then make them into a Dart list. 706 // reflect() and then make them into a Dart list.
693 return _metadata(_reflectee).map(reflect).toList(growable:false); 707 return _metadata(_reflectee).map(reflect).toList(growable:false);
694 } 708 }
709
710 bool operator ==(other) {
711 return this.runtimeType == other.runtimeType &&
712 this._reflectee == other._reflectee;
713 }
714
715 int get hashCode => simpleName.hashCode;
695 } 716 }
696 717
697 class _LazyTypeVariableMirror { 718 class _LazyTypeVariableMirror {
698 _LazyTypeVariableMirror(String variableName, this._owner) 719 _LazyTypeVariableMirror(String variableName, this._owner)
699 : this._variableName = _s(variableName); 720 : this._variableName = _s(variableName);
700 721
701 TypeVariableMirror resolve(MirrorSystem mirrors) { 722 TypeVariableMirror resolve(MirrorSystem mirrors) {
702 ClassMirror owner = _owner.resolve(mirrors); 723 ClassMirror owner = _owner.resolve(mirrors);
703 return owner.typeVariables[_variableName]; 724 return owner.typeVariables[_variableName];
704 } 725 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 } 915 }
895 916
896 List<InstanceMirror> get metadata { 917 List<InstanceMirror> get metadata {
897 // Get the metadata objects, convert them into InstanceMirrors using 918 // Get the metadata objects, convert them into InstanceMirrors using
898 // reflect() and then make them into a Dart list. 919 // reflect() and then make them into a Dart list.
899 return _metadata(_reflectee).map(reflect).toList(growable:false); 920 return _metadata(_reflectee).map(reflect).toList(growable:false);
900 } 921 }
901 922
902 String toString() => "LibraryMirror on '${_n(simpleName)}'"; 923 String toString() => "LibraryMirror on '${_n(simpleName)}'";
903 924
925 bool operator ==(other) {
926 return this.runtimeType == other.runtimeType &&
927 this._reflectee == other._reflectee;
928 }
929
930 int get hashCode => simpleName.hashCode;
931
904 _invoke(reflectee, memberName, positionalArguments) 932 _invoke(reflectee, memberName, positionalArguments)
905 native 'LibraryMirror_invoke'; 933 native 'LibraryMirror_invoke';
906 934
907 _invokeGetter(reflectee, getterName) 935 _invokeGetter(reflectee, getterName)
908 native 'LibraryMirror_invokeGetter'; 936 native 'LibraryMirror_invokeGetter';
909 937
910 _invokeSetter(reflectee, setterName, value) 938 _invokeSetter(reflectee, setterName, value)
911 native 'LibraryMirror_invokeSetter'; 939 native 'LibraryMirror_invokeSetter';
912 940
913 _computeMembers(reflectee) 941 _computeMembers(reflectee)
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1165 }
1138 1166
1139 Symbol get qualifiedName { 1167 Symbol get qualifiedName {
1140 return simpleName; 1168 return simpleName;
1141 } 1169 }
1142 1170
1143 String toString() => "TypeMirror on '${_n(simpleName)}'"; 1171 String toString() => "TypeMirror on '${_n(simpleName)}'";
1144 1172
1145 // TODO(11955): Remove once dynamicType and voidType are canonical objects in 1173 // TODO(11955): Remove once dynamicType and voidType are canonical objects in
1146 // the object store. 1174 // the object store.
1147 operator ==(other) { 1175 bool operator ==(other) {
1148 if (other is! _SpecialTypeMirrorImpl) { 1176 if (other is! _SpecialTypeMirrorImpl) {
1149 return false; 1177 return false;
1150 } 1178 }
1151 return this.simpleName == other.simpleName; 1179 return this.simpleName == other.simpleName;
1152 } 1180 }
1153 1181
1154 int get hashCode => simpleName.hashCode; 1182 int get hashCode => simpleName.hashCode;
1155 } 1183 }
1156 1184
1157 class _Mirrors { 1185 class _Mirrors {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1229 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1202 static ClassMirror reflectClass(Type key) { 1230 static ClassMirror reflectClass(Type key) {
1203 var classMirror = _classMirrorCache[key]; 1231 var classMirror = _classMirrorCache[key];
1204 if (classMirror == null) { 1232 if (classMirror == null) {
1205 classMirror = makeLocalClassMirror(key); 1233 classMirror = makeLocalClassMirror(key);
1206 _classMirrorCache[key] = classMirror; 1234 _classMirrorCache[key] = classMirror;
1207 } 1235 }
1208 return classMirror; 1236 return classMirror;
1209 } 1237 }
1210 } 1238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698