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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 result += result << 3; | 67 result += result << 3; |
68 result ^= result >> 11; | 68 result ^= result >> 11; |
69 result += result << 15; | 69 result += result << 15; |
70 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); | 70 result &= ((static_cast<intptr_t>(1) << String::kHashBits) - 1); |
71 return Smi::New(result); | 71 return Smi::New(result); |
72 } | 72 } |
73 UNREACHABLE(); | 73 UNREACHABLE(); |
74 return Object::null(); | 74 return Object::null(); |
75 } | 75 } |
76 | 76 |
| 77 |
| 78 DEFINE_NATIVE_ENTRY(FunctionImpl_clone, 1) { |
| 79 const Instance& receiver = Instance::CheckedHandle( |
| 80 isolate, arguments->NativeArgAt(0)); |
| 81 ASSERT(receiver.IsClosure()); |
| 82 if (receiver.IsClosure()) { |
| 83 const Function& func = |
| 84 Function::Handle(isolate, Closure::function(receiver)); |
| 85 const Context& ctx = |
| 86 Context::Handle(isolate, Closure::context(receiver)); |
| 87 Context& cloned_ctx = |
| 88 Context::Handle(isolate, Context::New(ctx.num_variables())); |
| 89 cloned_ctx.set_parent(Context::Handle(isolate, ctx.parent())); |
| 90 Object& inst = Object::Handle(isolate); |
| 91 for (int i = 0; i < ctx.num_variables(); i++) { |
| 92 inst = ctx.At(i); |
| 93 cloned_ctx.SetAt(i, inst); |
| 94 } |
| 95 return Closure::New(func, cloned_ctx); |
| 96 } |
| 97 return Object::null(); |
| 98 } |
| 99 |
| 100 |
77 } // namespace dart | 101 } // namespace dart |
OLD | NEW |