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 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. | 265 // TODO(ahe): This is a hack, see delegate below. |
| 266 static Function _invokeOnClosure; | 266 static Function _invokeOnClosure; |
|
Florian Schneider
2013/12/13 12:26:24
With your cleanup I think this member can go away
rmacnak
2013/12/13 18:16:48
Yes, done.
| |
| 267 | 267 |
| 268 _LocalInstanceMirror(reflectee) : super(reflectee); | 268 _LocalInstanceMirror(reflectee) : super(reflectee); |
| 269 | 269 |
| 270 ClassMirror _type; | 270 ClassMirror _type; |
| 271 ClassMirror get type { | 271 ClassMirror get type { |
| 272 if (_type == null) { | 272 if (_type == null) { |
| 273 // Note it not safe to use reflectee.runtimeType because runtimeType may | 273 // Note it not safe to use reflectee.runtimeType because runtimeType may |
| 274 // be overridden. | 274 // be overridden. |
| 275 _type = reflectType(_computeType(reflectee)); | 275 _type = reflectType(_computeType(reflectee)); |
| 276 } | 276 } |
| 277 return _type; | 277 return _type; |
| 278 } | 278 } |
| 279 | 279 |
| 280 // LocalInstanceMirrors always reflect local instances | 280 // LocalInstanceMirrors always reflect local instances |
| 281 bool hasReflectee = true; | 281 bool hasReflectee = true; |
| 282 | 282 |
| 283 get reflectee => _reflectee; | 283 get reflectee => _reflectee; |
| 284 | 284 |
| 285 delegate(Invocation invocation) { | 285 delegate(Invocation invocation) { |
| 286 if (_invokeOnClosure == null) { | 286 if (invocation.isMethod) { |
| 287 // TODO(ahe): This is a total hack. We're using the mirror | 287 return this.invoke(invocation.memberName, |
| 288 // system to access a private field in a different library. For | 288 invocation.positionalArguments, |
| 289 // some reason, that works. On the other hand, calling a | 289 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 } | 290 } |
| 296 return _invokeOnClosure(reflectee, invocation); | 291 if (invocation.isGetter) { |
| 292 return this.getField(invocation.memberName).reflectee; | |
| 293 } | |
| 294 if (invocation.isSetter) { | |
| 295 var unwrapped = _n(invocation.memberName); | |
| 296 var withoutEqual = _s(unwrapped.substring(0, unwrapped.length - 1)); | |
| 297 var arg = invocation.positionalArguments[0]; | |
| 298 this.setField(withoutEqual, arg).reflectee; | |
| 299 return arg; | |
| 300 } | |
| 301 throw "UNREACHABLE"; | |
| 297 } | 302 } |
| 298 | 303 |
| 299 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; | 304 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; |
| 300 | 305 |
| 301 bool operator ==(other) { | 306 bool operator ==(other) { |
| 302 return other is _LocalInstanceMirror && | 307 return other is _LocalInstanceMirror && |
| 303 identical(_reflectee, other._reflectee); | 308 identical(_reflectee, other._reflectee); |
| 304 } | 309 } |
| 305 | 310 |
| 306 int get hashCode { | 311 int get hashCode { |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1463 if (typeMirror == null) { | 1468 if (typeMirror == null) { |
| 1464 typeMirror = makeLocalTypeMirror(key); | 1469 typeMirror = makeLocalTypeMirror(key); |
| 1465 _instanitationCache[key] = typeMirror; | 1470 _instanitationCache[key] = typeMirror; |
| 1466 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1471 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1467 _declarationCache[key] = typeMirror; | 1472 _declarationCache[key] = typeMirror; |
| 1468 } | 1473 } |
| 1469 } | 1474 } |
| 1470 return typeMirror; | 1475 return typeMirror; |
| 1471 } | 1476 } |
| 1472 } | 1477 } |
| OLD | NEW |