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

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

Issue 114713002: VM: Support calling through getters in InstanceMirror.delegate. Implement without accessing private… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync Created 7 years 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 | « runtime/lib/invocation_mirror_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 256
257 InstanceMirror setField(Symbol memberName, Object value) { 257 InstanceMirror setField(Symbol memberName, Object value) {
258 this._invokeSetter(_reflectee, _n(memberName), value); 258 this._invokeSetter(_reflectee, _n(memberName), value);
259 return reflect(value); 259 return reflect(value);
260 } 260 }
261 } 261 }
262 262
263 class _LocalInstanceMirror extends _LocalObjectMirror 263 class _LocalInstanceMirror extends _LocalObjectMirror
264 implements InstanceMirror { 264 implements InstanceMirror {
265 // TODO(ahe): This is a hack, see delegate below.
266 static Function _invokeOnClosure;
267 265
268 _LocalInstanceMirror(reflectee) : super(reflectee); 266 _LocalInstanceMirror(reflectee) : super(reflectee);
269 267
270 ClassMirror _type; 268 ClassMirror _type;
271 ClassMirror get type { 269 ClassMirror get type {
272 if (_type == null) { 270 if (_type == null) {
273 // Note it not safe to use reflectee.runtimeType because runtimeType may 271 // Note it not safe to use reflectee.runtimeType because runtimeType may
274 // be overridden. 272 // be overridden.
275 _type = reflectType(_computeType(reflectee)); 273 _type = reflectType(_computeType(reflectee));
276 } 274 }
277 return _type; 275 return _type;
278 } 276 }
279 277
280 // LocalInstanceMirrors always reflect local instances 278 // LocalInstanceMirrors always reflect local instances
281 bool hasReflectee = true; 279 bool hasReflectee = true;
282 280
283 get reflectee => _reflectee; 281 get reflectee => _reflectee;
284 282
285 delegate(Invocation invocation) { 283 delegate(Invocation invocation) {
286 if (_invokeOnClosure == null) { 284 if (invocation.isMethod) {
287 // TODO(ahe): This is a total hack. We're using the mirror 285 return this.invoke(invocation.memberName,
288 // system to access a private field in a different library. For 286 invocation.positionalArguments,
289 // some reason, that works. On the other hand, calling a 287 invocation.namedArguments).reflectee;
290 // private method does not work.
291 ClassMirror invocationImplClass = reflect(invocation).type;
292 Symbol fieldName = MirrorSystem.getSymbol('_invokeOnClosure',
293 invocationImplClass.owner);
294 _invokeOnClosure = invocationImplClass.getField(fieldName).reflectee;
295 } 288 }
296 return _invokeOnClosure(reflectee, invocation); 289 if (invocation.isGetter) {
290 return this.getField(invocation.memberName).reflectee;
291 }
292 if (invocation.isSetter) {
293 var unwrapped = _n(invocation.memberName);
294 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1));
295 var arg = invocation.positionalArguments[0];
296 this.setField(withoutEqual, arg).reflectee;
297 return arg;
298 }
299 throw "UNREACHABLE";
297 } 300 }
298 301
299 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; 302 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}';
300 303
301 bool operator ==(other) { 304 bool operator ==(other) {
302 return other is _LocalInstanceMirror && 305 return other is _LocalInstanceMirror &&
303 identical(_reflectee, other._reflectee); 306 identical(_reflectee, other._reflectee);
304 } 307 }
305 308
306 int get hashCode { 309 int get hashCode {
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 if (typeMirror == null) { 1466 if (typeMirror == null) {
1464 typeMirror = makeLocalTypeMirror(key); 1467 typeMirror = makeLocalTypeMirror(key);
1465 _instanitationCache[key] = typeMirror; 1468 _instanitationCache[key] = typeMirror;
1466 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1469 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1467 _declarationCache[key] = typeMirror; 1470 _declarationCache[key] = typeMirror;
1468 } 1471 }
1469 } 1472 }
1470 return typeMirror; 1473 return typeMirror;
1471 } 1474 }
1472 } 1475 }
OLDNEW
« no previous file with comments | « runtime/lib/invocation_mirror_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698