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(); | |
159 ultimate_klass ^= klass.raw(); | |
siva
2013/07/11 22:53:37
why not
Class& ultimate_klass = Class::Handle(klas
| |
160 | |
161 Function& ultimate_constructor = Function::Handle(); | |
162 ultimate_constructor ^= constructor.raw(); | |
siva
2013/07/11 22:53:37
Ditto.
| |
163 | |
164 Instance& new_object = Instance::Handle(); | |
165 if (ultimate_constructor.IsRedirectingFactory()) { | |
166 Type& type = Type::Handle(ultimate_constructor.RedirectionType()); | |
167 ultimate_klass = type.type_class(); | |
168 ultimate_constructor = ultimate_constructor.RedirectionTarget(); | |
169 } | |
170 if (ultimate_constructor.IsConstructor()) { | |
171 // "Constructors" are really instance initializers. They are passed a newly | |
172 // allocated object as an extra argument. | |
173 new_object = Instance::New(ultimate_klass); | |
174 } | |
175 | |
176 // Create the argument list. | |
177 intptr_t number_of_arguments = arguments.Length(); | |
178 intptr_t arg_index = 0; | |
179 int extra_args = (ultimate_constructor.IsConstructor() ? 2 : 1); | |
180 const Array& args = | |
181 Array::Handle(Array::New(number_of_arguments + extra_args)); | |
182 if (ultimate_constructor.IsConstructor()) { | |
183 // Constructors get the uninitialized object and a constructor phase. | |
184 args.SetAt(arg_index++, new_object); | |
185 args.SetAt(arg_index++, | |
186 Smi::Handle(Smi::New(Function::kCtorPhaseAll))); | |
187 } else { | |
188 // Factories get type arguments. | |
189 args.SetAt(arg_index++, TypeArguments::Handle()); | |
190 } | |
191 Object& argument = Object::Handle(); | |
192 for (int i = 0; i < number_of_arguments; i++) { | |
193 argument = (arguments.At(i)); | |
194 args.SetAt(arg_index++, argument); | |
195 } | |
196 | |
197 // Invoke the constructor and return the new object. | |
198 Object& result = | |
199 Object::Handle(DartEntry::InvokeFunction(ultimate_constructor, args)); | |
200 if (result.IsError()) { | |
201 return result.raw(); | |
202 } | |
203 if (ultimate_constructor.IsConstructor()) { | |
204 return new_object.raw(); | |
205 } else { | |
206 return result.raw(); | |
207 } | |
208 } | |
209 | |
210 | |
155 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) | 211 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) |
156 : array_(array) { | 212 : array_(array) { |
157 } | 213 } |
158 | 214 |
159 | 215 |
160 intptr_t ArgumentsDescriptor::Count() const { | 216 intptr_t ArgumentsDescriptor::Count() const { |
161 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); | 217 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); |
162 } | 218 } |
163 | 219 |
164 | 220 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 String::Handle(Field::GetterName(Symbols::_id())))); | 540 String::Handle(Field::GetterName(Symbols::_id())))); |
485 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); | 541 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); |
486 ASSERT(!func.IsNull()); | 542 ASSERT(!func.IsNull()); |
487 const Array& args = Array::Handle(Array::New(1)); | 543 const Array& args = Array::Handle(Array::New(1)); |
488 args.SetAt(0, port); | 544 args.SetAt(0, port); |
489 return DartEntry::InvokeFunction(func, args); | 545 return DartEntry::InvokeFunction(func, args); |
490 } | 546 } |
491 | 547 |
492 | 548 |
493 } // namespace dart | 549 } // namespace dart |
OLD | NEW |