| 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 // These values are allowed to be passed directly over the wire. | 7 // These values are allowed to be passed directly over the wire. |
| 8 bool isSimpleValue(var value) { | 8 bool isSimpleValue(var value) { |
| 9 return (value === null || value is num || value is String || value is bool); | 9 return (value === null || value is num || value is String || value is bool); |
| 10 } | 10 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 buf.add(output); | 162 buf.add(output); |
| 163 } | 163 } |
| 164 return buf.toString(); | 164 return buf.toString(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl | 167 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl |
| 168 implements InstanceMirror { | 168 implements InstanceMirror { |
| 169 _LocalInstanceMirrorImpl(ref, | 169 _LocalInstanceMirrorImpl(ref, |
| 170 this._class, | 170 this._class, |
| 171 this.hasSimpleValue, | 171 this._hasSimpleValue, |
| 172 this._simpleValue) : super(ref) {} | 172 this._reflectee) : super(ref) {} |
| 173 | 173 |
| 174 var _class; | 174 var _class; |
| 175 InterfaceMirror getClass() { | 175 InterfaceMirror getClass() { |
| 176 if (_class is _LazyInterfaceMirror) { | 176 if (_class is _LazyInterfaceMirror) { |
| 177 _class = _class.resolve(isolate); | 177 _class = _class.resolve(isolate); |
| 178 } | 178 } |
| 179 return _class; | 179 return _class; |
| 180 } | 180 } |
| 181 | 181 |
| 182 bool hasSimpleValue; | 182 // LocalInstanceMirrors always reflect local instances |
| 183 bool hasReflectee = true; |
| 183 | 184 |
| 184 var _simpleValue; | 185 var _hasSimpleValue; |
| 185 get simpleValue() { | 186 var _reflectee; |
| 186 if (!hasSimpleValue) { | 187 get reflectee() => _reflectee; |
| 187 throw new MirrorException( | |
| 188 "Before accesing simpleValue you must check that hasSimpleValue " | |
| 189 "is true"); | |
| 190 } | |
| 191 return _simpleValue; | |
| 192 } | |
| 193 | 188 |
| 194 String toString() { | 189 String toString() { |
| 195 if (hasSimpleValue) { | 190 if (_hasSimpleValue) { |
| 196 if (simpleValue is String) { | 191 if (_reflectee is String) { |
| 197 return "InstanceMirror on <'${_dartEscape(simpleValue)}'>"; | 192 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; |
| 198 } else { | 193 } else { |
| 199 return "InstanceMirror on <$simpleValue>"; | 194 return "InstanceMirror on <$_reflectee>"; |
| 200 } | 195 } |
| 201 } else { | 196 } else { |
| 202 return "InstanceMirror on instance of '${getClass().simpleName}'"; | 197 return "InstanceMirror on instance of '${getClass().simpleName}'"; |
| 203 } | 198 } |
| 204 } | 199 } |
| 205 } | 200 } |
| 206 | 201 |
| 207 class _LazyInterfaceMirror { | 202 class _LazyInterfaceMirror { |
| 208 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} | 203 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} |
| 209 | 204 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 467 |
| 473 // Creates a new local InstanceMirror | 468 // Creates a new local InstanceMirror |
| 474 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 469 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 475 native 'Mirrors_makeLocalInstanceMirror'; | 470 native 'Mirrors_makeLocalInstanceMirror'; |
| 476 | 471 |
| 477 // The IsolateMirror for the current isolate. | 472 // The IsolateMirror for the current isolate. |
| 478 static InstanceMirror mirrorOf(Object reflectee) { | 473 static InstanceMirror mirrorOf(Object reflectee) { |
| 479 return makeLocalInstanceMirror(reflectee); | 474 return makeLocalInstanceMirror(reflectee); |
| 480 } | 475 } |
| 481 } | 476 } |
| OLD | NEW |