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

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

Issue 46893004: - Force errors when using bad types or overrides. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | tests/language/hello_dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new _UnmodifiableMapView({}); 10 final emptyMap = new _UnmodifiableMapView({});
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 V putIfAbsent(K key, V ifAbsent()) { _throw(); } 43 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
44 44
45 void addAll(Map<K, V> other) => _throw(); 45 void addAll(Map<K, V> other) => _throw();
46 46
47 V remove(K key) { _throw(); } 47 V remove(K key) { _throw(); }
48 48
49 void clear() => _throw(); 49 void clear() => _throw();
50 } 50 }
51 51
52 // These values are allowed to be passed directly over the wire. 52 class _InternalMirrorError {
53 bool _isSimpleValue(var value) { 53 const _InternalError(String this._msg);
54 return (value == null || value is num || value is String || value is bool); 54 String toString() => _msg;
55 final String _msg;
55 } 56 }
56 57
57 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 58 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
58 Map new_map = new Map<Symbol, dynamic>(); 59 Map new_map = new Map<Symbol, dynamic>();
59 old_map.forEach((key, value) { 60 old_map.forEach((key, value) {
60 if (filter(key, value)) { 61 if (filter(key, value)) {
61 new_map[key] = value; 62 new_map[key] = value;
62 } 63 }
63 }); 64 });
64 return new _UnmodifiableMapView(new_map); 65 return new _UnmodifiableMapView(new_map);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return reflect(this._invokeGetter(_reflectee, 210 return reflect(this._invokeGetter(_reflectee,
210 _n(memberName))); 211 _n(memberName)));
211 } 212 }
212 213
213 InstanceMirror setField(Symbol memberName, Object value) { 214 InstanceMirror setField(Symbol memberName, Object value) {
214 this._invokeSetter(_reflectee, 215 this._invokeSetter(_reflectee,
215 _n(memberName), 216 _n(memberName),
216 value); 217 value);
217 return reflect(value); 218 return reflect(value);
218 } 219 }
219
220 static _validateArgument(int i, Object arg)
221 {
222 if (arg is Mirror) {
223 if (arg is! InstanceMirror) {
224 throw new MirrorException(
225 'positional argument $i ($arg) was not an InstanceMirror');
226 }
227 } else if (!_isSimpleValue(arg)) {
228 throw new MirrorException(
229 'positional argument $i ($arg) was not a simple value');
230 }
231 }
232 } 220 }
233 221
234 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl 222 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl
235 implements InstanceMirror { 223 implements InstanceMirror {
236 // TODO(ahe): This is a hack, see delegate below. 224 // TODO(ahe): This is a hack, see delegate below.
237 static Function _invokeOnClosure; 225 static Function _invokeOnClosure;
238 226
239 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); 227 _LocalInstanceMirrorImpl(reflectee) : super(reflectee);
240 228
241 ClassMirror _type; 229 ClassMirror _type;
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; 1233 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor;
1246 1234
1247 Symbol _constructorName = null; 1235 Symbol _constructorName = null;
1248 Symbol get constructorName { 1236 Symbol get constructorName {
1249 if (_constructorName == null) { 1237 if (_constructorName == null) {
1250 if (!isConstructor) { 1238 if (!isConstructor) {
1251 _constructorName = _s(''); 1239 _constructorName = _s('');
1252 } else { 1240 } else {
1253 var parts = MirrorSystem.getName(simpleName).split('.'); 1241 var parts = MirrorSystem.getName(simpleName).split('.');
1254 if (parts.length > 2) { 1242 if (parts.length > 2) {
1255 throw new MirrorException( 1243 throw new _InternalMirrorError(
1256 'Internal error in MethodMirror.constructorName: ' 1244 'Internal error in MethodMirror.constructorName: '
1257 'malformed name <$simpleName>'); 1245 'malformed name <$simpleName>');
1258 } else if (parts.length == 2) { 1246 } else if (parts.length == 2) {
1259 _constructorName = _s(parts[1]); 1247 _constructorName = _s(parts[1]);
1260 } else { 1248 } else {
1261 _constructorName = _s(''); 1249 _constructorName = _s('');
1262 } 1250 }
1263 } 1251 }
1264 } 1252 }
1265 return _constructorName; 1253 return _constructorName;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 if (typeMirror == null) { 1468 if (typeMirror == null) {
1481 typeMirror = makeLocalTypeMirror(key); 1469 typeMirror = makeLocalTypeMirror(key);
1482 _instanitationCache[key] = typeMirror; 1470 _instanitationCache[key] = typeMirror;
1483 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1471 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1484 _declarationCache[key] = typeMirror; 1472 _declarationCache[key] = typeMirror;
1485 } 1473 }
1486 } 1474 }
1487 return typeMirror; 1475 return typeMirror;
1488 } 1476 }
1489 } 1477 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/hello_dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698