| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 void ArgumentsDescriptor::InitOnce() { | 418 void ArgumentsDescriptor::InitOnce() { |
| 419 for (int i = 0; i < kCachedDescriptorCount; i++) { | 419 for (int i = 0; i < kCachedDescriptorCount; i++) { |
| 420 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); | 420 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 | 424 |
| 425 RawObject* DartLibraryCalls::InstanceCreate(const Library& lib, | 425 RawObject* DartLibraryCalls::InstanceCreate(const Library& lib, |
| 426 const String& class_name, | 426 const String& class_name, |
| 427 const String& constructor_name, | 427 const String& constructor_name, |
| 428 bool factory, |
| 428 const Array& arguments) { | 429 const Array& arguments) { |
| 429 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); | 430 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); |
| 431 // Class may not be finalized yet, but will be as the constructor is compiled. |
| 430 ASSERT(!cls.IsNull()); | 432 ASSERT(!cls.IsNull()); |
| 431 // For now, we only support a non-parameterized or raw type. | 433 // For now, we only support a non-parameterized or raw type. |
| 432 const int kNumExtraArgs = 1; // implicit rcvr arg. | 434 const int kNumExtraArgs = 1; // Implicit rcvr arg or empty factory type args. |
| 433 const Instance& exception_object = Instance::Handle(Instance::New(cls)); | 435 Instance& exception_object = Instance::Handle(); |
| 434 const Array& constructor_arguments = | 436 const Array& constructor_arguments = |
| 435 Array::Handle(Array::New(arguments.Length() + kNumExtraArgs)); | 437 Array::Handle(Array::New(arguments.Length() + kNumExtraArgs)); |
| 436 constructor_arguments.SetAt(0, exception_object); | 438 if (factory) { |
| 439 constructor_arguments.SetAt(0, TypeArguments::Handle()); |
| 440 } else { |
| 441 exception_object = Instance::New(cls); |
| 442 constructor_arguments.SetAt(0, exception_object); |
| 443 } |
| 437 Object& obj = Object::Handle(); | 444 Object& obj = Object::Handle(); |
| 438 for (intptr_t i = 0; i < arguments.Length(); i++) { | 445 for (intptr_t i = 0; i < arguments.Length(); i++) { |
| 439 obj = arguments.At(i); | 446 obj = arguments.At(i); |
| 440 constructor_arguments.SetAt((i + kNumExtraArgs), obj); | 447 constructor_arguments.SetAt((i + kNumExtraArgs), obj); |
| 441 } | 448 } |
| 442 | 449 |
| 443 const String& function_name = String::Handle( | 450 const String& function_name = String::Handle( |
| 444 String::Concat(class_name, constructor_name)); | 451 String::Concat(class_name, constructor_name)); |
| 445 const Function& constructor = | 452 const Function& constructor = |
| 446 Function::Handle(cls.LookupConstructorAllowPrivate(function_name)); | 453 Function::Handle(factory ? |
| 454 cls.LookupFactoryAllowPrivate(function_name) : |
| 455 cls.LookupConstructorAllowPrivate(function_name)); |
| 447 ASSERT(!constructor.IsNull()); | 456 ASSERT(!constructor.IsNull()); |
| 448 const Object& retval = | 457 const Object& retval = |
| 449 Object::Handle(DartEntry::InvokeFunction(constructor, | 458 Object::Handle(DartEntry::InvokeFunction(constructor, |
| 450 constructor_arguments)); | 459 constructor_arguments)); |
| 451 ASSERT(retval.IsNull() || retval.IsError()); | 460 if (factory || retval.IsError()) { |
| 452 if (retval.IsError()) { | |
| 453 return retval.raw(); | 461 return retval.raw(); |
| 454 } | 462 } |
| 455 return exception_object.raw(); | 463 return exception_object.raw(); |
| 456 } | 464 } |
| 457 | 465 |
| 458 | 466 |
| 459 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { | 467 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { |
| 460 const int kNumArguments = 1; // Receiver. | 468 const int kNumArguments = 1; // Receiver. |
| 461 ArgumentsDescriptor args_desc( | 469 ArgumentsDescriptor args_desc( |
| 462 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 470 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 const Array& args = Array::Handle(Array::New(kNumArguments)); | 616 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 609 args.SetAt(0, map); | 617 args.SetAt(0, map); |
| 610 args.SetAt(1, key); | 618 args.SetAt(1, key); |
| 611 args.SetAt(2, value); | 619 args.SetAt(2, value); |
| 612 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, | 620 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, |
| 613 args)); | 621 args)); |
| 614 return result.raw(); | 622 return result.raw(); |
| 615 } | 623 } |
| 616 | 624 |
| 617 } // namespace dart | 625 } // namespace dart |
| OLD | NEW |