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

Side by Side 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: added missing file 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/native_entry.h" 10 #include "vm/native_entry.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 DEFINE_NATIVE_ENTRY(Function_apply, 2) { 16 DEFINE_NATIVE_ENTRY(Function_apply, 2) {
17 const Array& fun_arguments = Array::CheckedHandle(arguments->NativeArgAt(0)); 17 const Array& fun_arguments = Array::CheckedHandle(arguments->NativeArgAt(0));
18 const Array& fun_arg_names = Array::CheckedHandle(arguments->NativeArgAt(1)); 18 const Array& fun_arg_names = Array::CheckedHandle(arguments->NativeArgAt(1));
19 const Array& fun_args_desc = 19 const Array& fun_args_desc =
20 Array::Handle(ArgumentsDescriptor::New(fun_arguments.Length(), 20 Array::Handle(ArgumentsDescriptor::New(fun_arguments.Length(),
21 fun_arg_names)); 21 fun_arg_names));
22 const Object& result = 22 const Object& result =
23 Object::Handle(DartEntry::InvokeClosure(fun_arguments, fun_args_desc)); 23 Object::Handle(DartEntry::InvokeClosure(fun_arguments, fun_args_desc));
24 if (result.IsError()) { 24 if (result.IsError()) {
25 Exceptions::PropagateError(Error::Cast(result)); 25 Exceptions::PropagateError(Error::Cast(result));
26 } 26 }
27 return result.raw(); 27 return result.raw();
28 } 28 }
29 29
30
31 DEFINE_NATIVE_ENTRY(Function_equals, 2) {
Ivan Posva 2013/08/13 17:58:49 FunctionImpl_equals
Florian Schneider 2013/08/14 09:07:49 Done.
32 const Instance& receiver = Instance::CheckedHandle(
Ivan Posva 2013/08/13 17:58:49 Instance::CheckedHandle should really be a Closure
Florian Schneider 2013/08/14 09:07:49 Ok, I'll make a separate CL.
33 isolate, arguments->NativeArgAt(0));
34 ASSERT(receiver.IsClosure());
35 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1));
36 if (receiver.raw() == other.raw()) return Bool::True().raw();
37 if (other.IsClosure()) {
38 const Function& func_a = Function::Handle(Closure::function(receiver));
39 const Function& func_b = Function::Handle(Closure::function(other));
40 if (func_a.raw() == func_b.raw()) {
41 ASSERT(!func_a.IsImplicitStaticClosureFunction());
Ivan Posva 2013/08/13 17:58:49 Please add a comment why this assertion is here.
Florian Schneider 2013/08/14 09:07:49 Done.
42 if (func_a.IsImplicitInstanceClosureFunction()) {
43 const Context& context_a = Context::Handle(Closure::context(receiver));
44 const Context& context_b = Context::Handle(Closure::context(other));
45 const Instance& receiver_a = Instance::Handle(context_a.At(0));
46 const Instance& receiver_b = Instance::Handle(context_b.At(0));
47 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw();
48 }
49 }
50 }
51 return Bool::False().raw();
52 }
53
54
55 DEFINE_NATIVE_ENTRY(Function_hashCode, 1) {
Ivan Posva 2013/08/13 17:58:49 ditto
Florian Schneider 2013/08/14 09:07:49 Done.
56 const Instance& receiver = Instance::CheckedHandle(
Ivan Posva 2013/08/13 17:58:49 Same here about the Closure::CheckedHandle, which
Florian Schneider 2013/08/14 09:07:49 Will do in a separate CL.
57 isolate, arguments->NativeArgAt(0));
58 if (receiver.IsClosure()) {
59 const Function& func = Function::Handle(Closure::function(receiver));
60 intptr_t result = String::Handle(func.name()).Hash();
Ivan Posva 2013/08/13 17:58:49 How about hashing both the function name, the clas
Florian Schneider 2013/08/14 09:07:49 Done.
61 return Smi::New(result);
62 }
63 UNREACHABLE();
64 return Object::null();
65 }
66
30 } // namespace dart 67 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698