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

Unified Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 23460013: Implement InstanceMirror.== in dart2js and InstanceMirror.hashCode in the VM and … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: use isolate parameter to native Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/symbols.h ('k') | tests/lib/lib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart
index d5db7e5f505c54dafa04c3d37eddaf99847fd051..8911a689052d16f099f2a8ed153d56ba3b311d55 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -677,6 +677,26 @@ class JsInstanceMirror extends JsObjectMirror implements InstanceMirror {
return JSInvocationMirror.invokeFromMirror(invocation, reflectee);
}
+ operator ==(other) {
+ return other is JsInstanceMirror &&
+ identical(reflectee, other.reflectee);
+ }
+
+ int get hashCode {
+ // If the reflectee is a built-in type, use the base-level hashCode to
+ // preserve the illusion that, e.g. doubles, with the same value are
+ // identical. Otherwise, use the primitive identity hash to maintain
+ // correctness even if a user-defined hashCode returns different values for
+ // successive invocations.
+ var h = ((JS('bool', 'typeof # != "object"', reflectee)) ||
+ (reflectee == null))
+ ? reflectee.hashCode
+ : Primitives.objectHashCode(reflectee);
+ // Avoid hash collisions with the reflectee. This constant is in Smi range
+ // and happens to be the inner padding from RFC 2104.
+ return h ^ 0x36363636;
+ }
+
String toString() => 'InstanceMirror on ${Error.safeToString(reflectee)}';
// TODO(ahe): Remove this method from the API.
« no previous file with comments | « runtime/vm/symbols.h ('k') | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698