Chromium Code Reviews| 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 if (receiver.raw() == other.raw()) return Bool::True().raw(); | 38 // For implicit instance closures compare receiver instance and function's |
| 39 if (other.IsClosure()) { | 39 // name and owner (multiple function objects could exist for the same |
| 40 const Function& func_a = Function::Handle(zone, receiver.function()); | 40 // function due to hot reload). |
| 41 const Function& func_b = | 41 // Objects of other closure kinds are unique, so use identity comparison. |
| 42 Function::Handle(zone, Closure::Cast(other).function()); | 42 if (receiver.raw() == other.raw()) { |
| 43 if (func_a.raw() == func_b.raw()) { | 43 return Bool::True().raw(); |
| 44 ASSERT(!func_a.IsImplicitStaticClosureFunction()); | 44 } |
| 45 if (func_a.IsImplicitInstanceClosureFunction()) { | 45 const Function& func_a = Function::Handle(zone, receiver.function()); |
|
siva
2017/07/21 21:47:17
It probably makes sense to avoid creation of this
alexmarkov
2017/07/21 22:02:43
My gut feeling tells me that comparing a closure w
siva
2017/07/21 22:51:24
Not sure depends on the program being run, you sho
alexmarkov
2017/07/24 16:11:47
Reverted to the earlier testing other.IsClosure(),
| |
| 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()) { | |
| 46 const Context& context_a = Context::Handle(zone, receiver.context()); | 51 const Context& context_a = Context::Handle(zone, receiver.context()); |
| 47 const Context& context_b = | 52 const Context& context_b = |
| 48 Context::Handle(zone, Closure::Cast(other).context()); | 53 Context::Handle(zone, other_closure.context()); |
| 49 const Object& receiver_a = Object::Handle(zone, context_a.At(0)); | 54 RawObject* receiver_a = context_a.At(0); |
| 50 const Object& receiver_b = Object::Handle(zone, context_b.At(0)); | 55 RawObject* receiver_b = context_b.At(0); |
| 51 if (receiver_a.raw() == receiver_b.raw()) return Bool::True().raw(); | 56 if ((receiver_a == receiver_b) && |
| 52 } | 57 ((func_a.raw() == func_b.raw()) || |
| 53 } else if (func_a.IsImplicitInstanceClosureFunction() && | 58 ((func_a.name() == func_b.name()) && |
| 54 func_b.IsImplicitInstanceClosureFunction()) { | 59 (func_a.Owner() == func_b.Owner())))) { |
| 55 // TODO(rmacnak): Patch existing tears off during reload instead. | 60 return Bool::True().raw(); |
| 56 const Context& context_a = Context::Handle(zone, receiver.context()); | 61 } |
| 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(); | |
| 65 } | 62 } |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 return Bool::False().raw(); | 65 return Bool::False().raw(); |
| 69 } | 66 } |
| 70 | 67 |
| 71 DEFINE_NATIVE_ENTRY(Closure_computeHash, 1) { | 68 DEFINE_NATIVE_ENTRY(Closure_computeHash, 1) { |
| 72 const Closure& receiver = | 69 const Closure& receiver = |
| 73 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 70 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 74 return Smi::New(receiver.ComputeHash()); | 71 return Smi::New(receiver.ComputeHash()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 89 Object& instance = Object::Handle(zone); | 86 Object& instance = Object::Handle(zone); |
| 90 for (int i = 0; i < context.num_variables(); i++) { | 87 for (int i = 0; i < context.num_variables(); i++) { |
| 91 instance = context.At(i); | 88 instance = context.At(i); |
| 92 cloned_context.SetAt(i, instance); | 89 cloned_context.SetAt(i, instance); |
| 93 } | 90 } |
| 94 return Closure::New(instantiator_type_arguments, function_type_arguments, | 91 return Closure::New(instantiator_type_arguments, function_type_arguments, |
| 95 function, cloned_context); | 92 function, cloned_context); |
| 96 } | 93 } |
| 97 | 94 |
| 98 } // namespace dart | 95 } // namespace dart |
| OLD | NEW |