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/code_generator.h" | 7 #include "vm/code_generator.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 kNumArguments, | 145 kNumArguments, |
146 kNumNamedArguments)); | 146 kNumNamedArguments)); |
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 Type& type = Type::Handle(ultimate_constructor.RedirectionType()); | |
164 ultimate_klass = type.type_class(); | |
165 ultimate_constructor = ultimate_constructor.RedirectionTarget(); | |
166 } | |
167 if (ultimate_constructor.IsConstructor()) { | |
168 // "Constructors" are really instance initializers. They are passed a newly | |
169 // allocated object as an extra argument. | |
170 new_object = Instance::New(ultimate_klass); | |
171 } | |
172 | |
173 // Create the argument list. | |
174 intptr_t number_of_arguments = arguments.Length(); | |
175 intptr_t arg_index = 0; | |
176 int extra_args = (ultimate_constructor.IsConstructor() ? 2 : 1); | |
177 const Array& args = | |
178 Array::Handle(Array::New(number_of_arguments + extra_args)); | |
179 if (ultimate_constructor.IsConstructor()) { | |
180 // Constructors get the uninitialized object and a constructor phase. | |
181 args.SetAt(arg_index++, new_object); | |
182 args.SetAt(arg_index++, | |
183 Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | |
184 } else { | |
185 // Factories get type arguments. | |
186 args.SetAt(arg_index++, TypeArguments::Handle()); | |
187 } | |
188 Object& argument = Object::Handle(); | |
189 for (int i = 0; i < number_of_arguments; i++) { | |
190 argument = (arguments.At(i)); | |
191 args.SetAt(arg_index++, argument); | |
192 } | |
193 | |
194 // Invoke the constructor and return the new object. | |
195 Object& result = | |
siva
2013/07/15 20:52:52
const Object& result
| |
196 Object::Handle(DartEntry::InvokeFunction(ultimate_constructor, args)); | |
197 if (result.IsError()) { | |
198 return result.raw(); | |
199 } | |
200 if (ultimate_constructor.IsConstructor()) { | |
201 return new_object.raw(); | |
202 } else { | |
203 return result.raw(); | |
204 } | |
205 } | |
206 | |
207 | |
155 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) | 208 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) |
156 : array_(array) { | 209 : array_(array) { |
157 } | 210 } |
158 | 211 |
159 | 212 |
160 intptr_t ArgumentsDescriptor::Count() const { | 213 intptr_t ArgumentsDescriptor::Count() const { |
161 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); | 214 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); |
162 } | 215 } |
163 | 216 |
164 | 217 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 String::Handle(Field::GetterName(Symbols::_id())))); | 544 String::Handle(Field::GetterName(Symbols::_id())))); |
492 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 545 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
493 ASSERT(!func.IsNull()); | 546 ASSERT(!func.IsNull()); |
494 const Array& args = Array::Handle(Array::New(1)); | 547 const Array& args = Array::Handle(Array::New(1)); |
495 args.SetAt(0, port); | 548 args.SetAt(0, port); |
496 return DartEntry::InvokeFunction(func, args); | 549 return DartEntry::InvokeFunction(func, args); |
497 } | 550 } |
498 | 551 |
499 | 552 |
500 } // namespace dart | 553 } // namespace dart |
OLD | NEW |