| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 return Bool::False().raw(); | 64 return Bool::False().raw(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 | 67 |
| 68 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { | 68 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { |
| 69 const Closure& receiver = | 69 const Closure& receiver = |
| 70 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 70 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 71 const Function& func = Function::Handle(receiver.function()); | 71 const Function& func = Function::Handle(receiver.function()); |
| 72 // Hash together name, class name and signature. | 72 return func.GetClosureHashCode(); |
| 73 const Class& cls = Class::Handle(func.Owner()); | |
| 74 intptr_t result = String::Handle(func.name()).Hash(); | |
| 75 result += String::Handle(func.Signature()).Hash(); | |
| 76 result += String::Handle(cls.Name()).Hash(); | |
| 77 // Finalize hash value like for strings so that it fits into a smi. | |
| 78 result += result << 3; | |
| 79 result ^= result >> 11; | |
| 80 result += result << 15; | |
| 81 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); | |
| 82 return Smi::New(result); | |
| 83 } | 73 } |
| 84 | 74 |
| 85 | 75 |
| 86 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { | 76 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { |
| 87 const Closure& receiver = | 77 const Closure& receiver = |
| 88 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 78 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
| 89 const Function& func = Function::Handle(zone, receiver.function()); | 79 const Function& func = Function::Handle(zone, receiver.function()); |
| 90 const Context& ctx = Context::Handle(zone, receiver.context()); | 80 const Context& ctx = Context::Handle(zone, receiver.context()); |
| 91 Context& cloned_ctx = | 81 Context& cloned_ctx = |
| 92 Context::Handle(zone, Context::New(ctx.num_variables())); | 82 Context::Handle(zone, Context::New(ctx.num_variables())); |
| 93 cloned_ctx.set_parent(Context::Handle(zone, ctx.parent())); | 83 cloned_ctx.set_parent(Context::Handle(zone, ctx.parent())); |
| 94 Object& inst = Object::Handle(zone); | 84 Object& inst = Object::Handle(zone); |
| 95 for (int i = 0; i < ctx.num_variables(); i++) { | 85 for (int i = 0; i < ctx.num_variables(); i++) { |
| 96 inst = ctx.At(i); | 86 inst = ctx.At(i); |
| 97 cloned_ctx.SetAt(i, inst); | 87 cloned_ctx.SetAt(i, inst); |
| 98 } | 88 } |
| 99 return Closure::New(func, cloned_ctx); | 89 return Closure::New(func, cloned_ctx); |
| 100 } | 90 } |
| 101 | 91 |
| 102 | 92 |
| 103 } // namespace dart | 93 } // namespace dart |
| OLD | NEW |