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 // These values are allowed to be passed directly over the wire. | 9 // These values are allowed to be passed directly over the wire. |
10 bool _isSimpleValue(var value) { | 10 bool _isSimpleValue(var value) { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return _invokeOnClosure(reflectee, invocation); | 276 return _invokeOnClosure(reflectee, invocation); |
277 } | 277 } |
278 | 278 |
279 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; | 279 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; |
280 | 280 |
281 bool operator ==(other) { | 281 bool operator ==(other) { |
282 return other is _LocalInstanceMirrorImpl && | 282 return other is _LocalInstanceMirrorImpl && |
283 identical(_reflectee, other._reflectee); | 283 identical(_reflectee, other._reflectee); |
284 } | 284 } |
285 | 285 |
286 // TODO(12909): Use the reflectee's identity hash. | 286 int get hashCode { |
287 int get hashCode => _reflectee.hashCode; | 287 // If the reflectee is a double or bignum, use the base hashCode to preserve |
| 288 // the illusion that boxed numbers with the same value are identical. If the |
| 289 // reflectee is a Smi, use the base hashCode because Object.hashCode does |
| 290 // not work for non-heap objects. Otherwise, use Object.hashCode to maintain |
| 291 // correctness even if a user-defined hashCode returns different values for |
| 292 // successive invocations. |
| 293 var h = _reflectee is num ? _reflectee.hashCode : _identityHash(_reflectee); |
| 294 // Avoid hash collisions with the reflectee. This constant is in Smi range |
| 295 // and happens to be the inner padding from RFC 2104. |
| 296 return h ^ 0x36363636; |
| 297 } |
| 298 |
| 299 static _identityHash(reflectee) |
| 300 native "InstanceMirror_identityHash"; |
288 | 301 |
289 _invoke(reflectee, functionName, positionalArguments) | 302 _invoke(reflectee, functionName, positionalArguments) |
290 native 'InstanceMirror_invoke'; | 303 native 'InstanceMirror_invoke'; |
291 | 304 |
292 _invokeGetter(reflectee, getterName) | 305 _invokeGetter(reflectee, getterName) |
293 native 'InstanceMirror_invokeGetter'; | 306 native 'InstanceMirror_invokeGetter'; |
294 | 307 |
295 _invokeSetter(reflectee, setterName, value) | 308 _invokeSetter(reflectee, setterName, value) |
296 native 'InstanceMirror_invokeSetter'; | 309 native 'InstanceMirror_invokeSetter'; |
297 | 310 |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 if (typeMirror == null) { | 1308 if (typeMirror == null) { |
1296 typeMirror = makeLocalTypeMirror(key); | 1309 typeMirror = makeLocalTypeMirror(key); |
1297 _instanitationCache[key] = typeMirror; | 1310 _instanitationCache[key] = typeMirror; |
1298 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1311 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1299 _declarationCache[key] = typeMirror; | 1312 _declarationCache[key] = typeMirror; |
1300 } | 1313 } |
1301 } | 1314 } |
1302 return typeMirror; | 1315 return typeMirror; |
1303 } | 1316 } |
1304 } | 1317 } |
OLD | NEW |