Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1569213003: Eliminate phase parameter in constructors (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 Function& constructor = Function::Handle(zone); 2740 Function& constructor = Function::Handle(zone);
2741 constructor ^= result.raw(); 2741 constructor ^= result.raw();
2742 if (!constructor.IsGenerativeConstructor()) { 2742 if (!constructor.IsGenerativeConstructor()) {
2743 const String& message = String::Handle( 2743 const String& message = String::Handle(
2744 String::NewFormatted("%s: class '%s' is not a constructor.", 2744 String::NewFormatted("%s: class '%s' is not a constructor.",
2745 CURRENT_FUNC, class_name.ToCString())); 2745 CURRENT_FUNC, class_name.ToCString()));
2746 return ApiError::New(message); 2746 return ApiError::New(message);
2747 } 2747 }
2748 Instance& exception = Instance::Handle(zone); 2748 Instance& exception = Instance::Handle(zone);
2749 exception = Instance::New(cls); 2749 exception = Instance::New(cls);
2750 const Array& args = Array::Handle(zone, Array::New(3)); 2750 const Array& args = Array::Handle(zone, Array::New(2));
2751 args.SetAt(0, exception); 2751 args.SetAt(0, exception);
2752 args.SetAt(1, Smi::Handle(zone, Smi::New(Function::kCtorPhaseAll))); 2752 args.SetAt(1, String::Handle(String::New(exception_message)));
2753 args.SetAt(2, String::Handle(String::New(exception_message)));
2754 result = DartEntry::InvokeFunction(constructor, args); 2753 result = DartEntry::InvokeFunction(constructor, args);
2755 if (result.IsError()) return result.raw(); 2754 if (result.IsError()) return result.raw();
2756 ASSERT(result.IsNull()); 2755 ASSERT(result.IsNull());
2757 2756
2758 if (thread->top_exit_frame_info() == 0) { 2757 if (thread->top_exit_frame_info() == 0) {
2759 // There are no dart frames on the stack so it would be illegal to 2758 // There are no dart frames on the stack so it would be illegal to
2760 // throw an exception here. 2759 // throw an exception here.
2761 const String& message = String::Handle( 2760 const String& message = String::Handle(
2762 String::New("No Dart frames on stack, cannot throw exception")); 2761 String::New("No Dart frames on stack, cannot throw exception"));
2763 return ApiError::New(message); 2762 return ApiError::New(message);
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 constr_name.ToCString(), 3596 constr_name.ToCString(),
3598 lookup_class_name.ToCString())); 3597 lookup_class_name.ToCString()));
3599 return ApiError::New(message); 3598 return ApiError::New(message);
3600 } else { 3599 } else {
3601 const String& message = String::Handle( 3600 const String& message = String::Handle(
3602 String::NewFormatted("%s: could not find constructor '%s'.", 3601 String::NewFormatted("%s: could not find constructor '%s'.",
3603 current_func, constr_name.ToCString())); 3602 current_func, constr_name.ToCString()));
3604 return ApiError::New(message); 3603 return ApiError::New(message);
3605 } 3604 }
3606 } 3605 }
3607 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); 3606 int extra_args = 1;
3608 String& error_message = String::Handle(); 3607 String& error_message = String::Handle();
3609 if (!constructor.AreValidArgumentCounts(num_args + extra_args, 3608 if (!constructor.AreValidArgumentCounts(num_args + extra_args,
3610 0, 3609 0,
3611 &error_message)) { 3610 &error_message)) {
3612 const String& message = String::Handle( 3611 const String& message = String::Handle(
3613 String::NewFormatted("%s: wrong argument count for " 3612 String::NewFormatted("%s: wrong argument count for "
3614 "constructor '%s': %s.", 3613 "constructor '%s': %s.",
3615 current_func, 3614 current_func,
3616 constr_name.ToCString(), 3615 constr_name.ToCString(),
3617 error_message.ToCString())); 3616 error_message.ToCString()));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) { 3710 if (!cls.is_allocated() && Dart::IsRunningPrecompiledCode()) {
3712 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); 3711 return Api::NewError("Precompilation dropped '%s'", cls.ToCString());
3713 } 3712 }
3714 #endif 3713 #endif
3715 // Create the new object. 3714 // Create the new object.
3716 new_object = Instance::New(cls); 3715 new_object = Instance::New(cls);
3717 } 3716 }
3718 3717
3719 // Create the argument list. 3718 // Create the argument list.
3720 intptr_t arg_index = 0; 3719 intptr_t arg_index = 0;
3721 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); 3720 int extra_args = 1;
3722 const Array& args = 3721 const Array& args =
3723 Array::Handle(Z, Array::New(number_of_arguments + extra_args)); 3722 Array::Handle(Z, Array::New(number_of_arguments + extra_args));
3724 if (constructor.IsGenerativeConstructor()) { 3723 if (constructor.IsGenerativeConstructor()) {
3725 // Constructors get the uninitialized object and a constructor phase. 3724 // Constructors get the uninitialized object.
3726 if (!type_arguments.IsNull()) { 3725 if (!type_arguments.IsNull()) {
3727 // The type arguments will be null if the class has no type parameters, in 3726 // The type arguments will be null if the class has no type parameters, in
3728 // which case the following call would fail because there is no slot 3727 // which case the following call would fail because there is no slot
3729 // reserved in the object for the type vector. 3728 // reserved in the object for the type vector.
3730 new_object.SetTypeArguments(type_arguments); 3729 new_object.SetTypeArguments(type_arguments);
3731 } 3730 }
3732 args.SetAt(arg_index++, new_object); 3731 args.SetAt(arg_index++, new_object);
3733 args.SetAt(arg_index++, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll)));
3734 } else { 3732 } else {
3735 // Factories get type arguments. 3733 // Factories get type arguments.
3736 args.SetAt(arg_index++, type_arguments); 3734 args.SetAt(arg_index++, type_arguments);
3737 } 3735 }
3738 Object& argument = Object::Handle(Z); 3736 Object& argument = Object::Handle(Z);
3739 for (int i = 0; i < number_of_arguments; i++) { 3737 for (int i = 0; i < number_of_arguments; i++) {
3740 argument = Api::UnwrapHandle(arguments[i]); 3738 argument = Api::UnwrapHandle(arguments[i]);
3741 if (!argument.IsNull() && !argument.IsInstance()) { 3739 if (!argument.IsNull() && !argument.IsInstance()) {
3742 if (argument.IsError()) { 3740 if (argument.IsError()) {
3743 return Api::NewHandle(T, argument.raw()); 3741 return Api::NewHandle(T, argument.raw());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3915 if (constructor_name.IsNull()) { 3913 if (constructor_name.IsNull()) {
3916 strings.SetAt(2, Symbols::Empty()); 3914 strings.SetAt(2, Symbols::Empty());
3917 } else { 3915 } else {
3918 strings.SetAt(2, constructor_name); 3916 strings.SetAt(2, constructor_name);
3919 } 3917 }
3920 const String& dot_name = String::Handle(Z, String::ConcatAll(strings)); 3918 const String& dot_name = String::Handle(Z, String::ConcatAll(strings));
3921 const TypeArguments& type_arguments = 3919 const TypeArguments& type_arguments =
3922 TypeArguments::Handle(Z, type_obj.arguments()); 3920 TypeArguments::Handle(Z, type_obj.arguments());
3923 const Function& constructor = 3921 const Function& constructor =
3924 Function::Handle(Z, cls.LookupFunctionAllowPrivate(dot_name)); 3922 Function::Handle(Z, cls.LookupFunctionAllowPrivate(dot_name));
3925 const int extra_args = 2; 3923 const int extra_args = 1;
3926 if (!constructor.IsNull() && 3924 if (!constructor.IsNull() &&
3927 constructor.IsGenerativeConstructor() && 3925 constructor.IsGenerativeConstructor() &&
3928 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, 3926 constructor.AreValidArgumentCounts(number_of_arguments + extra_args,
3929 0, 3927 0,
3930 NULL)) { 3928 NULL)) {
3931 // Create the argument list. 3929 // Create the argument list.
3932 // Constructors get the uninitialized object and a constructor phase. 3930 // Constructors get the uninitialized object.
3933 if (!type_arguments.IsNull()) { 3931 if (!type_arguments.IsNull()) {
3934 // The type arguments will be null if the class has no type 3932 // The type arguments will be null if the class has no type
3935 // parameters, in which case the following call would fail 3933 // parameters, in which case the following call would fail
3936 // because there is no slot reserved in the object for the 3934 // because there is no slot reserved in the object for the
3937 // type vector. 3935 // type vector.
3938 instance.SetTypeArguments(type_arguments); 3936 instance.SetTypeArguments(type_arguments);
3939 } 3937 }
3940 Dart_Handle result; 3938 Dart_Handle result;
3941 Array& args = Array::Handle(Z); 3939 Array& args = Array::Handle(Z);
3942 result = SetupArguments( 3940 result = SetupArguments(
3943 T, number_of_arguments, arguments, extra_args, &args); 3941 T, number_of_arguments, arguments, extra_args, &args);
3944 if (!::Dart_IsError(result)) { 3942 if (!::Dart_IsError(result)) {
3945 args.SetAt(0, instance); 3943 args.SetAt(0, instance);
3946 args.SetAt(1, Smi::Handle(Z, Smi::New(Function::kCtorPhaseAll)));
3947 const Object& retval = Object::Handle(Z, 3944 const Object& retval = Object::Handle(Z,
3948 DartEntry::InvokeFunction(constructor, args)); 3945 DartEntry::InvokeFunction(constructor, args));
3949 if (retval.IsError()) { 3946 if (retval.IsError()) {
3950 result = Api::NewHandle(T, retval.raw()); 3947 result = Api::NewHandle(T, retval.raw());
3951 } else { 3948 } else {
3952 result = Api::NewHandle(T, instance.raw()); 3949 result = Api::NewHandle(T, instance.raw());
3953 } 3950 }
3954 } 3951 }
3955 return result; 3952 return result;
3956 } 3953 }
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
5997 return Api::Success(); 5994 return Api::Success();
5998 } 5995 }
5999 #endif // DART_PRECOMPILED 5996 #endif // DART_PRECOMPILED
6000 5997
6001 5998
6002 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 5999 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6003 return Dart::IsRunningPrecompiledCode(); 6000 return Dart::IsRunningPrecompiledCode();
6004 } 6001 }
6005 6002
6006 } // namespace dart 6003 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698