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

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: 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
« no previous file with comments | « no previous file | runtime/lib/function_patch.dart » ('j') | runtime/vm/object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(Closure_comparison, 2) {
32 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
33 GET_NATIVE_ARGUMENT(Instance, b, arguments->NativeArgAt(1));
34 if (a.raw() == b.raw()) return Bool::True().raw();
35 if (a.IsClosure() && b.IsClosure()) {
36 const Function& func_a = Function::Handle(Closure::function(a));
37 const Function& func_b = Function::Handle(Closure::function(b));
38 if (func_a.raw() == func_b.raw()) {
39 const Context& context_a = Context::Handle(Closure::context(a));
40 const Context& context_b = Context::Handle(Closure::context(b));
41 const Instance& receiver_a = Instance::Handle(context_a.At(0));
42 const Instance& receiver_b = Instance::Handle(context_b.At(0));
43 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw();
44 }
45 }
46 return Bool::False().raw();
47 }
48
49
50 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) {
51 GET_NATIVE_ARGUMENT(Instance, a, arguments->NativeArgAt(0));
52 if (a.IsClosure()) {
53 const Function& func = Function::Handle(Closure::function(a));
54 intptr_t result = String::Handle(func.name()).Hash();
55 // TODO(fschneider): Also use receiver for hash.
56 return Smi::New(result);
57 }
58 return Object::null();
59 }
60
30 } // namespace dart 61 } // namespace dart
OLDNEW
« 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