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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/js_helper.dart

Issue 16042014: Implement operator== and hashCode for bound closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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/compiler/implementation/lib/js_helper.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/lib/js_helper.dart (revision 23339)
+++ sdk/lib/_internal/compiler/implementation/lib/js_helper.dart (working copy)
@@ -145,13 +145,13 @@
static int hashCodeSeed = 0;
static int objectHashCode(object) {
- int hash = JS('var', r'#.$identityHash', object);
+ int hash = JS('int|Null', r'#.$identityHash', object);
if (hash == null) {
// TOOD(ahe): We should probably randomize this somehow.
hash = ++hashCodeSeed;
JS('void', r'#.$identityHash = #', object, hash);
}
- return hash;
+ return JS('int', '#', hash);
}
/**
@@ -946,6 +946,28 @@
String toString() => "Closure";
}
+class BoundClosure extends Closure {
+ var self;
+ var target;
+ var receiver;
+
+ bool operator==(other) {
+ if (identical(this, other)) return true;
+ if (other is! BoundClosure) return false;
+ return JS('bool', '# === # && # === # && # === #',
+ self, other.self,
+ target, other.target,
+ receiver, other.receiver);
+ }
+
+ int get hashCode {
+ return JS('int', '(# + # + #) & 0x3ffffff',
+ self.hashCode,
+ target.hashCode,
+ receiver.hashCode);
+ }
+}
+
bool jsHasOwnProperty(var jsObject, String property) {
return JS('bool', r'#.hasOwnProperty(#)', jsObject, property);
}

Powered by Google App Engine
This is Rietveld 408576698