| Index: runtime/vm/dart_entry.cc
|
| diff --git a/runtime/vm/dart_entry.cc b/runtime/vm/dart_entry.cc
|
| index c9e7769fba4a0b47400b6ee8dfcaf4302c9ab65f..e2327fff9f610e3d6b37b49bd8177d1d88fe9c84 100644
|
| --- a/runtime/vm/dart_entry.cc
|
| +++ b/runtime/vm/dart_entry.cc
|
| @@ -425,15 +425,22 @@ void ArgumentsDescriptor::InitOnce() {
|
| RawObject* DartLibraryCalls::InstanceCreate(const Library& lib,
|
| const String& class_name,
|
| const String& constructor_name,
|
| + bool factory,
|
| const Array& arguments) {
|
| const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name));
|
| + // Class may not be finalized yet, but will be as the constructor is compiled.
|
| ASSERT(!cls.IsNull());
|
| // For now, we only support a non-parameterized or raw type.
|
| - const int kNumExtraArgs = 1; // implicit rcvr arg.
|
| - const Instance& exception_object = Instance::Handle(Instance::New(cls));
|
| + const int kNumExtraArgs = 1; // Implicit rcvr arg or empty factory type args.
|
| + Instance& exception_object = Instance::Handle();
|
| const Array& constructor_arguments =
|
| Array::Handle(Array::New(arguments.Length() + kNumExtraArgs));
|
| - constructor_arguments.SetAt(0, exception_object);
|
| + if (factory) {
|
| + constructor_arguments.SetAt(0, TypeArguments::Handle());
|
| + } else {
|
| + exception_object = Instance::New(cls);
|
| + constructor_arguments.SetAt(0, exception_object);
|
| + }
|
| Object& obj = Object::Handle();
|
| for (intptr_t i = 0; i < arguments.Length(); i++) {
|
| obj = arguments.At(i);
|
| @@ -443,13 +450,14 @@ RawObject* DartLibraryCalls::InstanceCreate(const Library& lib,
|
| const String& function_name = String::Handle(
|
| String::Concat(class_name, constructor_name));
|
| const Function& constructor =
|
| - Function::Handle(cls.LookupConstructorAllowPrivate(function_name));
|
| + Function::Handle(factory ?
|
| + cls.LookupFactoryAllowPrivate(function_name) :
|
| + cls.LookupConstructorAllowPrivate(function_name));
|
| ASSERT(!constructor.IsNull());
|
| const Object& retval =
|
| Object::Handle(DartEntry::InvokeFunction(constructor,
|
| constructor_arguments));
|
| - ASSERT(retval.IsNull() || retval.IsError());
|
| - if (retval.IsError()) {
|
| + if (factory || retval.IsError()) {
|
| return retval.raw();
|
| }
|
| return exception_object.raw();
|
|
|