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

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 | « runtime/lib/corelib_sources.gypi ('k') | runtime/lib/function.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/function.cc
===================================================================
--- runtime/lib/function.cc (revision 26064)
+++ runtime/lib/function.cc (working copy)
@@ -27,4 +27,50 @@
return result.raw();
}
+
+DEFINE_NATIVE_ENTRY(FunctionImpl_equals, 2) {
+ const Instance& receiver = Instance::CheckedHandle(
+ isolate, arguments->NativeArgAt(0));
+ ASSERT(receiver.IsClosure());
+ GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1));
+ if (receiver.raw() == other.raw()) return Bool::True().raw();
+ if (other.IsClosure()) {
+ const Function& func_a = Function::Handle(Closure::function(receiver));
+ const Function& func_b = Function::Handle(Closure::function(other));
+ if (func_a.raw() == func_b.raw()) {
+ ASSERT(!func_a.IsImplicitStaticClosureFunction());
+ if (func_a.IsImplicitInstanceClosureFunction()) {
+ const Context& context_a = Context::Handle(Closure::context(receiver));
+ const Context& context_b = Context::Handle(Closure::context(other));
+ 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(FunctionImpl_hashCode, 1) {
+ const Instance& receiver = Instance::CheckedHandle(
+ isolate, arguments->NativeArgAt(0));
+ if (receiver.IsClosure()) {
+ const Function& func = Function::Handle(Closure::function(receiver));
+ // Hash together name, class name and signature.
+ const Class& cls = Class::Handle(func.Owner());
+ intptr_t result = String::Handle(func.name()).Hash();
+ result += String::Handle(func.Signature()).Hash();
+ result += String::Handle(cls.Name()).Hash();
+ // Finalize hash value like for strings so that it fits into a smi.
+ result += result << 3;
+ result ^= result >> 11;
+ result += result << 15;
+ result &=((static_cast<intptr_t>(1) << String::kHashBits) - 1);
+ return Smi::New(result);
+ }
+ UNREACHABLE();
+ return Object::null();
+}
+
} // namespace dart
« no previous file with comments | « runtime/lib/corelib_sources.gypi ('k') | runtime/lib/function.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698