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

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: Created 7 years, 4 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
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 88decfe41e335b24be18c46d811b255c54ac3a03..e826fd2078bb0e17687005b00375501bef72c587 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -29,7 +29,8 @@ import 'dart:_js_helper' show
runtimeTypeToString;
import 'dart:_interceptors' show
Interceptor,
- JSExtendableArray;
+ JSExtendableArray,
+ getInterceptor;
ahe 2013/08/30 20:40:14 I think you can remove this import if my suggestio
rmacnak 2013/08/30 21:08:29 Done.
import 'dart:_js_names';
/// No-op method that is called to inform the compiler that tree-shaking needs
@@ -677,6 +678,22 @@ 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 intercepted, use the base 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.
+ return getInterceptor(reflectee) is Interceptor
ahe 2013/08/30 20:40:14 I think other native types, such as DivElement, wi
rmacnak 2013/08/30 21:08:29 Done, but I have to also separate out null. typeof
+ ? reflectee.hashCode
+ : Primitives.objectHashCode(reflectee);
+ }
+
String toString() => 'InstanceMirror on ${Error.safeToString(reflectee)}';
// TODO(ahe): Remove this method from the API.

Powered by Google App Engine
This is Rietveld 408576698