Index: runtime/vm/dart_entry.cc |
=================================================================== |
--- runtime/vm/dart_entry.cc (revision 24960) |
+++ runtime/vm/dart_entry.cc (working copy) |
@@ -152,6 +152,62 @@ |
} |
+RawObject* DartEntry::InvokeConstructor(const Class& klass, |
+ const Function& constructor, |
+ const Array& arguments) { |
+ Class& ultimate_klass = Class::Handle(); |
+ ultimate_klass ^= klass.raw(); |
siva
2013/07/15 05:42:58
incoming parameter is already a Class so why not j
|
+ |
+ Function& ultimate_constructor = Function::Handle(); |
+ ultimate_constructor ^= constructor.raw(); |
siva
2013/07/15 05:42:58
Ditto comment about constructor being already a Fu
|
+ |
+ Instance& new_object = Instance::Handle(); |
+ if (ultimate_constructor.IsRedirectingFactory()) { |
+ Type& type = Type::Handle(ultimate_constructor.RedirectionType()); |
+ ultimate_klass = type.type_class(); |
+ ultimate_constructor = ultimate_constructor.RedirectionTarget(); |
+ } |
+ if (ultimate_constructor.IsConstructor()) { |
+ // "Constructors" are really instance initializers. They are passed a newly |
+ // allocated object as an extra argument. |
+ new_object = Instance::New(ultimate_klass); |
+ } |
+ |
+ // Create the argument list. |
+ intptr_t number_of_arguments = arguments.Length(); |
+ intptr_t arg_index = 0; |
+ int extra_args = (ultimate_constructor.IsConstructor() ? 2 : 1); |
+ const Array& args = |
+ Array::Handle(Array::New(number_of_arguments + extra_args)); |
+ if (ultimate_constructor.IsConstructor()) { |
+ // Constructors get the uninitialized object and a constructor phase. |
+ args.SetAt(arg_index++, new_object); |
+ args.SetAt(arg_index++, |
+ Smi::Handle(Smi::New(Function::kCtorPhaseAll))); |
+ } else { |
+ // Factories get type arguments. |
+ args.SetAt(arg_index++, TypeArguments::Handle()); |
+ } |
+ Object& argument = Object::Handle(); |
+ for (int i = 0; i < number_of_arguments; i++) { |
+ argument = (arguments.At(i)); |
+ args.SetAt(arg_index++, argument); |
+ } |
+ |
+ // Invoke the constructor and return the new object. |
+ Object& result = |
+ Object::Handle(DartEntry::InvokeFunction(ultimate_constructor, args)); |
+ if (result.IsError()) { |
+ return result.raw(); |
+ } |
+ if (ultimate_constructor.IsConstructor()) { |
+ return new_object.raw(); |
+ } else { |
+ return result.raw(); |
+ } |
+} |
+ |
+ |
ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) |
: array_(array) { |
} |