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

Unified Diff: runtime/lib/function.cc

Issue 22425006: Fix equality of implicit closures in the Dart VM. (Closed) Base URL: http://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
« no previous file with comments | « no previous file | runtime/lib/function_patch.dart » ('j') | runtime/vm/object.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/function.cc
===================================================================
--- runtime/lib/function.cc (revision 25920)
+++ runtime/lib/function.cc (working copy)
@@ -27,4 +27,35 @@
return result.raw();
}
+
+DEFINE_NATIVE_ENTRY(Closure_comparison, 2) {
+ GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
+ GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
+ if (a.raw() == b.raw()) return Bool::True().raw();
+ if (a.IsClosure() && b.IsClosure()) {
+ const Function& func_a = Function::Handle(Closure::function(a));
+ const Function& func_b = Function::Handle(Closure::function(b));
+ if (func_a.raw() == func_b.raw()) {
+ const Context& context_a = Context::Handle(Closure::context(a));
+ const Context& context_b = Context::Handle(Closure::context(b));
+ const Instance& receiver_a = Instance::Handle(context_a.At(0));
+ const Instance& receiver_b = Instance::Handle(context_b.At(0));
+ if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw();
+ }
+ }
+ return Bool::False().raw();
+}
+
+
+DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) {
+ GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
+ if (a.IsClosure()) {
+ const Function& func = Function::Handle(Closure::function(a));
+ intptr_t result = String::Handle(func.name()).Hash();
+ // TODO(fschneider): Also use receiver for hash.
+ return Smi::New(result);
+ }
+ return Object::null();
+}
+
} // namespace dart
« no previous file with comments | « no previous file | runtime/lib/function_patch.dart » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698