Chromium Code Reviews| Index: runtime/lib/mirrors_impl.dart |
| diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart |
| index 310c9f7b48b997589ce658ab2ed42fdff2009365..baca1e56fe32d48e0624e3d8cab9b4ce98a15dda 100644 |
| --- a/runtime/lib/mirrors_impl.dart |
| +++ b/runtime/lib/mirrors_impl.dart |
| @@ -332,6 +332,52 @@ class _LocalInstanceMirror extends _LocalObjectMirror |
| return new _InvocationTrampoline(this, selector); |
| } |
| + // TODO(16539): Make these weak. |
|
kasperl
2014/02/05 08:34:26
I guess there's no need for complex weak handling
rmacnak
2014/02/05 18:53:41
Soft would do as well. Though I wonder if this wou
|
| + static Map _getFieldClosures = new HashMap(); |
| + static Map _setFieldClosures = new HashMap(); |
| + |
| + InstanceMirror getField(Symbol memberName) { |
| + var f = _getFieldClosures[_n(memberName)]; |
| + if (f == null) { |
|
kasperl
2014/02/05 08:32:13
Consider splitting this method in two so it become
|
| + var unwrapped = _n(memberName); |
|
kasperl
2014/02/05 08:32:13
Cache _n(memberName) in a local?
kasperl
2014/02/05 09:05:40
I guess what I meant was: Use unwrapped consistent
|
| + var at_pos = unwrapped.indexOf('@'); |
|
kasperl
2014/02/05 08:32:13
Follow Dart coding style: at_pos -> atPosition or
|
| + if (at_pos == -1) { |
| + // Public symbol. |
| + f = _eval('(x) => x.$unwrapped', null); |
| + } else { |
| + // Private symbol. |
| + var withoutKey = unwrapped.substring(0, at_pos); |
| + var privateKey = unwrapped.substring(at_pos); |
| + f = _eval('(x) => x.$withoutKey', privateKey); |
| + } |
| + _getFieldClosures[_n(memberName)] = f; |
| + } |
| + return reflect(f(_reflectee)); |
| + } |
| + |
| + InstanceMirror setField(Symbol memberName, arg) { |
| + var f = _setFieldClosures[_n(memberName)]; |
|
kasperl
2014/02/05 08:32:13
Cache _n(memberName) in a local?
|
| + if (f == null) { |
| + var unwrapped = _n(memberName); |
| + var at_pos = unwrapped.indexOf('@'); |
|
kasperl
2014/02/05 08:32:13
Follow Dart coding style: at_pos -> atPosition or
|
| + if (at_pos == -1) { |
| + // Public symbol. |
| + f = _eval('(x, v) => x.$unwrapped = v', null); |
| + } else { |
| + // Private symbol. |
| + var withoutKey = unwrapped.substring(0, at_pos); |
| + var privateKey = unwrapped.substring(at_pos); |
| + f = _eval('(x, v) => x.$withoutKey = v', privateKey); |
| + } |
| + _setFieldClosures[_n(memberName)] = f; |
| + } |
| + f(_reflectee, arg); |
| + return reflect(arg); |
| + } |
| + |
| + static _eval(expression, privateKey) |
| + native "Mirrors_evalInLibraryWithPrivateKey"; |
| + |
| // Override to include the receiver in the arguments. |
| InstanceMirror invoke(Symbol memberName, |
| List positionalArguments, |