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 12 matching lines...) Expand all Loading... |
23 zone, ArgumentsDescriptor::New(kTypeArgsLen, fun_arguments.Length(), | 23 zone, ArgumentsDescriptor::New(kTypeArgsLen, fun_arguments.Length(), |
24 fun_arg_names)); | 24 fun_arg_names)); |
25 const Object& result = Object::Handle( | 25 const Object& result = Object::Handle( |
26 zone, DartEntry::InvokeClosure(fun_arguments, fun_args_desc)); | 26 zone, DartEntry::InvokeClosure(fun_arguments, fun_args_desc)); |
27 if (result.IsError()) { | 27 if (result.IsError()) { |
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 | |
34 DEFINE_NATIVE_ENTRY(Closure_equals, 2) { | 33 DEFINE_NATIVE_ENTRY(Closure_equals, 2) { |
35 const Closure& receiver = | 34 const Closure& receiver = |
36 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 35 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
37 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); | 36 GET_NATIVE_ARGUMENT(Instance, other, arguments->NativeArgAt(1)); |
38 ASSERT(!other.IsNull()); | 37 ASSERT(!other.IsNull()); |
39 if (receiver.raw() == other.raw()) return Bool::True().raw(); | 38 if (receiver.raw() == other.raw()) return Bool::True().raw(); |
40 if (other.IsClosure()) { | 39 if (other.IsClosure()) { |
41 const Function& func_a = Function::Handle(zone, receiver.function()); | 40 const Function& func_a = Function::Handle(zone, receiver.function()); |
42 const Function& func_b = | 41 const Function& func_b = |
43 Function::Handle(zone, Closure::Cast(other).function()); | 42 Function::Handle(zone, Closure::Cast(other).function()); |
(...skipping 18 matching lines...) Expand all Loading... |
62 if ((receiver_a.raw() == receiver_b.raw()) && | 61 if ((receiver_a.raw() == receiver_b.raw()) && |
63 (func_a.name() == func_b.name()) && | 62 (func_a.name() == func_b.name()) && |
64 (func_a.Owner() == func_b.Owner())) { | 63 (func_a.Owner() == func_b.Owner())) { |
65 return Bool::True().raw(); | 64 return Bool::True().raw(); |
66 } | 65 } |
67 } | 66 } |
68 } | 67 } |
69 return Bool::False().raw(); | 68 return Bool::False().raw(); |
70 } | 69 } |
71 | 70 |
72 | |
73 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { | 71 DEFINE_NATIVE_ENTRY(Closure_hashCode, 1) { |
74 const Closure& receiver = | 72 const Closure& receiver = |
75 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 73 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
76 const Function& func = Function::Handle(zone, receiver.function()); | 74 const Function& func = Function::Handle(zone, receiver.function()); |
77 return func.GetClosureHashCode(); | 75 return func.GetClosureHashCode(); |
78 } | 76 } |
79 | 77 |
80 | |
81 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { | 78 DEFINE_NATIVE_ENTRY(Closure_clone, 1) { |
82 const Closure& receiver = | 79 const Closure& receiver = |
83 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); | 80 Closure::CheckedHandle(zone, arguments->NativeArgAt(0)); |
84 const TypeArguments& instantiator_type_arguments = | 81 const TypeArguments& instantiator_type_arguments = |
85 TypeArguments::Handle(zone, receiver.instantiator_type_arguments()); | 82 TypeArguments::Handle(zone, receiver.instantiator_type_arguments()); |
86 const TypeArguments& function_type_arguments = | 83 const TypeArguments& function_type_arguments = |
87 TypeArguments::Handle(zone, receiver.function_type_arguments()); | 84 TypeArguments::Handle(zone, receiver.function_type_arguments()); |
88 const Function& function = Function::Handle(zone, receiver.function()); | 85 const Function& function = Function::Handle(zone, receiver.function()); |
89 const Context& context = Context::Handle(zone, receiver.context()); | 86 const Context& context = Context::Handle(zone, receiver.context()); |
90 Context& cloned_context = | 87 Context& cloned_context = |
91 Context::Handle(zone, Context::New(context.num_variables())); | 88 Context::Handle(zone, Context::New(context.num_variables())); |
92 cloned_context.set_parent(Context::Handle(zone, context.parent())); | 89 cloned_context.set_parent(Context::Handle(zone, context.parent())); |
93 Object& instance = Object::Handle(zone); | 90 Object& instance = Object::Handle(zone); |
94 for (int i = 0; i < context.num_variables(); i++) { | 91 for (int i = 0; i < context.num_variables(); i++) { |
95 instance = context.At(i); | 92 instance = context.At(i); |
96 cloned_context.SetAt(i, instance); | 93 cloned_context.SetAt(i, instance); |
97 } | 94 } |
98 return Closure::New(instantiator_type_arguments, function_type_arguments, | 95 return Closure::New(instantiator_type_arguments, function_type_arguments, |
99 function, cloned_context); | 96 function, cloned_context); |
100 } | 97 } |
101 | 98 |
102 | |
103 } // namespace dart | 99 } // namespace dart |
OLD | NEW |