OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/dart_entry.h" | 5 #include "vm/dart_entry.h" |
6 | 6 |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 Symbols::NoSuchMethod(), | 145 Symbols::NoSuchMethod(), |
146 args_desc)); | 146 args_desc)); |
147 ASSERT(!function.IsNull()); | 147 ASSERT(!function.IsNull()); |
148 const Array& args = Array::Handle(Array::New(kNumArguments)); | 148 const Array& args = Array::Handle(Array::New(kNumArguments)); |
149 args.SetAt(0, receiver); | 149 args.SetAt(0, receiver); |
150 args.SetAt(1, invocation_mirror); | 150 args.SetAt(1, invocation_mirror); |
151 return InvokeFunction(function, args); | 151 return InvokeFunction(function, args); |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 RawObject* DartEntry::InvokeConstructor(const Class& klass, | |
156 const Function& constructor, | |
157 const Array& arguments) { | |
158 Class& ultimate_klass = Class::Handle(klass.raw()); | |
159 Function& ultimate_constructor = Function::Handle(constructor.raw()); | |
160 | |
161 Instance& new_object = Instance::Handle(); | |
162 if (ultimate_constructor.IsRedirectingFactory()) { | |
163 ClassFinalizer::ResolveRedirectingFactory(klass, ultimate_constructor); | |
164 Type& type = Type::Handle(ultimate_constructor.RedirectionType()); | |
165 ultimate_constructor = ultimate_constructor.RedirectionTarget(); | |
166 ASSERT(!ultimate_constructor.IsNull()); | |
167 ultimate_klass = type.type_class(); | |
168 } | |
169 if (ultimate_constructor.IsConstructor()) { | |
170 // "Constructors" are really instance initializers. They are passed a newly | |
171 // allocated object as an extra argument. | |
172 new_object = Instance::New(ultimate_klass); | |
173 } | |
174 | |
175 // Create the argument list. | |
176 intptr_t number_of_arguments = arguments.Length(); | |
177 intptr_t arg_index = 0; | |
178 int extra_args = (ultimate_constructor.IsConstructor() ? 2 : 1); | |
179 const Array& args = | |
180 Array::Handle(Array::New(number_of_arguments + extra_args)); | |
181 if (ultimate_constructor.IsConstructor()) { | |
182 // Constructors get the uninitialized object and a constructor phase. | |
183 args.SetAt(arg_index++, new_object); | |
184 args.SetAt(arg_index++, | |
185 Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | |
186 } else { | |
187 // Factories get type arguments. | |
188 args.SetAt(arg_index++, TypeArguments::Handle()); | |
189 } | |
190 Object& argument = Object::Handle(); | |
191 for (int i = 0; i < number_of_arguments; i++) { | |
192 argument = (arguments.At(i)); | |
193 args.SetAt(arg_index++, argument); | |
194 } | |
195 | |
196 // Invoke the constructor and return the new object. | |
197 const Object& result = | |
198 Object::Handle(DartEntry::InvokeFunction(ultimate_constructor, args)); | |
199 if (result.IsError()) { | |
200 return result.raw(); | |
201 } | |
202 if (ultimate_constructor.IsConstructor()) { | |
203 return new_object.raw(); | |
204 } else { | |
205 return result.raw(); | |
206 } | |
207 } | |
208 | |
209 | |
210 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) | 155 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) |
211 : array_(array) { | 156 : array_(array) { |
212 } | 157 } |
213 | 158 |
214 | 159 |
215 intptr_t ArgumentsDescriptor::Count() const { | 160 intptr_t ArgumentsDescriptor::Count() const { |
216 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); | 161 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); |
217 } | 162 } |
218 | 163 |
219 | 164 |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 String::Handle(Field::GetterName(Symbols::_id())))); | 499 String::Handle(Field::GetterName(Symbols::_id())))); |
555 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 500 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
556 ASSERT(!func.IsNull()); | 501 ASSERT(!func.IsNull()); |
557 const Array& args = Array::Handle(Array::New(1)); | 502 const Array& args = Array::Handle(Array::New(1)); |
558 args.SetAt(0, port); | 503 args.SetAt(0, port); |
559 return DartEntry::InvokeFunction(func, args); | 504 return DartEntry::InvokeFunction(func, args); |
560 } | 505 } |
561 | 506 |
562 | 507 |
563 } // namespace dart | 508 } // namespace dart |
OLD | NEW |