OLD | NEW |
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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 Exceptions::PropagateError(Error::Cast(result)); | 28 Exceptions::PropagateError(Error::Cast(result)); |
29 } | 29 } |
30 return result.raw(); | 30 return result.raw(); |
31 } | 31 } |
32 | 32 |
33 DEFINE_NATIVE_ENTRY(Closure_equals, 2) { | 33 DEFINE_NATIVE_ENTRY(Closure_equals, 2) { |
34 const Closure& receiver = | 34 const Closure& receiver = |
35 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 35 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
36 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); | 36 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); |
37 ASSERT(!other.IsNull()); | 37 ASSERT(!other.IsNull()); |
38 // For implicit instance closures compare receiver instance and function's | 38 if (receiver.raw() == other.raw()) return Bool::True().raw(); |
39 // name and owner (multiple function objects could exist for the same | 39 if (other.IsClosure()) { |
40 // function due to hot reload). | 40 const Function& func_a = Function::Handle(zone, receiver.function()); |
41 // Objects of other closure kinds are unique, so use identity comparison. | 41 const Function& func_b = |
42 if (receiver.raw() == other.raw()) { | 42 Function::Handle(zone, Closure::Cast(other).function()); |
43 return Bool::True().raw(); | 43 if (func_a.raw() == func_b.raw()) { |
44 } | 44 ASSERT(!func_a.IsImplicitStaticClosureFunction()); |
45 const Function& func_a = Function::Handle(zone, receiver.function()); | 45 if (func_a.IsImplicitInstanceClosureFunction()) { |
46 if (func_a.IsImplicitInstanceClosureFunction()) { | |
47 if (other.IsClosure()) { | |
48 const Closure& other_closure = Closure::Cast(other); | |
49 const Function& func_b = Function::Handle(zone, other_closure.function()); | |
50 if (func_b.IsImplicitInstanceClosureFunction()) { | |
51 const Context& context_a = Context::Handle(zone, receiver.context()); | 46 const Context& context_a = Context::Handle(zone, receiver.context()); |
52 const Context& context_b = | 47 const Context& context_b = |
53 Context::Handle(zone, other_closure.context()); | 48 Context::Handle(zone, Closure::Cast(other).context()); |
54 RawObject* receiver_a = context_a.At(0); | 49 const Object& receiver_a = Object::Handle(zone, context_a.At(0)); |
55 RawObject* receiver_b = context_b.At(0); | 50 const Object& receiver_b = Object::Handle(zone, context_b.At(0)); |
56 if ((receiver_a == receiver_b) && | 51 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw(); |
57 ((func_a.raw() == func_b.raw()) || | 52 } |
58 ((func_a.name() == func_b.name()) && | 53 } else if (func_a.IsImplicitInstanceClosureFunction() && |
59 (func_a.Owner() == func_b.Owner())))) { | 54 func_b.IsImplicitInstanceClosureFunction()) { |
60 return Bool::True().raw(); | 55 // TODO(rmacnak): Patch existing tears off during reload instead. |
61 } | 56 const Context& context_a = Context::Handle(zone, receiver.context()); |
| 57 const Context& context_b = |
| 58 Context::Handle(zone, Closure::Cast(other).context()); |
| 59 const Object& receiver_a = Object::Handle(zone, context_a.At(0)); |
| 60 const Object& receiver_b = Object::Handle(zone, context_b.At(0)); |
| 61 if ((receiver_a.raw() == receiver_b.raw()) && |
| 62 (func_a.name() == func_b.name()) && |
| 63 (func_a.Owner() == func_b.Owner())) { |
| 64 return Bool::True().raw(); |
62 } | 65 } |
63 } | 66 } |
64 } | 67 } |
65 return Bool::False().raw(); | 68 return Bool::False().raw(); |
66 } | 69 } |
67 | 70 |
68 DEFINE_NATIVE_ENTRY(Closure_computeHash, 1) { | 71 DEFINE_NATIVE_ENTRY(Closure_computeHash, 1) { |
69 const Closure& receiver = | 72 const Closure& receiver = |
70 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 73 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
71 return Smi::New(receiver.ComputeHash()); | 74 return Smi::New(receiver.ComputeHash()); |
(...skipping 14 matching lines...) Expand all Loading... |
86 Object& instance = Object::Handle(zone); | 89 Object& instance = Object::Handle(zone); |
87 for (int i = 0; i < context.num_variables(); i++) { | 90 for (int i = 0; i < context.num_variables(); i++) { |
88 instance = context.At(i); | 91 instance = context.At(i); |
89 cloned_context.SetAt(i, instance); | 92 cloned_context.SetAt(i, instance); |
90 } | 93 } |
91 return Closure::New(instantiator_type_arguments, function_type_arguments, | 94 return Closure::New(instantiator_type_arguments, function_type_arguments, |
92 function, cloned_context); | 95 function, cloned_context); |
93 } | 96 } |
94 | 97 |
95 } // namespace dart | 98 } // namespace dart |
OLD | NEW |