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

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

Issue 17617006: Fix Dart_GetType to get the correct number of type arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 3686 matching lines...) Expand 10 before | Expand all | Expand 10 after
3697 3697
3698 // Validate the input arguments. 3698 // Validate the input arguments.
3699 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); 3699 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
3700 if (lib.IsNull()) { 3700 if (lib.IsNull()) {
3701 RETURN_TYPE_ERROR(isolate, library, Library); 3701 RETURN_TYPE_ERROR(isolate, library, Library);
3702 } 3702 }
3703 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); 3703 const String& name_str = Api::UnwrapStringHandle(isolate, class_name);
3704 if (name_str.IsNull()) { 3704 if (name_str.IsNull()) {
3705 RETURN_TYPE_ERROR(isolate, class_name, String); 3705 RETURN_TYPE_ERROR(isolate, class_name, String);
3706 } 3706 }
3707 // Ensure all classes are finalized.
3708 Dart_Handle state = Api::CheckIsolateState(isolate);
3709 if (::Dart_IsError(state)) {
3710 return state;
3711 }
3707 const Class& cls = 3712 const Class& cls =
3708 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); 3713 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str));
3709 if (cls.IsNull()) { 3714 if (cls.IsNull()) {
3710 const String& lib_name = String::Handle(isolate, lib.name()); 3715 const String& lib_name = String::Handle(isolate, lib.name());
3711 return Api::NewError("Type '%s' not found in library '%s'.", 3716 return Api::NewError("Type '%s' not found in library '%s'.",
3712 name_str.ToCString(), lib_name.ToCString()); 3717 name_str.ToCString(), lib_name.ToCString());
3713 } 3718 }
3714 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); 3719 if (cls.NumTypeArguments() == 0) {
3715 if (num_expected_type_arguments == 0) { 3720 if (number_of_type_arguments != 0) {
3721 return Api::NewError("Invalid number of type arguments specified, "
3722 "got %"Pd" expected 0", number_of_type_arguments);
3723 }
3716 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls)); 3724 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls));
3717 } 3725 }
3726 intptr_t num_expected_type_arguments = cls.NumTypeParameters();
3718 TypeArguments& type_args_obj = TypeArguments::Handle(); 3727 TypeArguments& type_args_obj = TypeArguments::Handle();
3719 if (number_of_type_arguments > 0) { 3728 if (number_of_type_arguments > 0) {
3720 if (type_arguments == NULL) { 3729 if (type_arguments == NULL) {
3721 RETURN_NULL_ERROR(type_arguments); 3730 RETURN_NULL_ERROR(type_arguments);
3722 } 3731 }
3723 if (num_expected_type_arguments != number_of_type_arguments) { 3732 if (num_expected_type_arguments != number_of_type_arguments) {
3724 return Api::NewError("Invalid number of type arguments specified, " 3733 return Api::NewError("Invalid number of type arguments specified, "
3725 "got %"Pd" expected %"Pd, 3734 "got %"Pd" expected %"Pd,
3726 number_of_type_arguments, 3735 number_of_type_arguments,
3727 num_expected_type_arguments); 3736 num_expected_type_arguments);
(...skipping 10 matching lines...) Expand all
3738 } 3747 }
3739 // Set up the type arguments array. 3748 // Set up the type arguments array.
3740 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); 3749 type_args_obj ^= TypeArguments::New(num_expected_type_arguments);
3741 AbstractType& type_arg = AbstractType::Handle(); 3750 AbstractType& type_arg = AbstractType::Handle();
3742 for (intptr_t i = 0; i < number_of_type_arguments; i++) { 3751 for (intptr_t i = 0; i < number_of_type_arguments; i++) {
3743 type_arg ^= array.At(i); 3752 type_arg ^= array.At(i);
3744 type_args_obj.SetTypeAt(i, type_arg); 3753 type_args_obj.SetTypeAt(i, type_arg);
3745 } 3754 }
3746 } 3755 }
3747 3756
3748 // Ensure all classes are finalized.
3749 Dart_Handle state = Api::CheckIsolateState(isolate);
3750 if (::Dart_IsError(state)) {
3751 return state;
3752 }
3753
3754 // Construct the type object, canonicalize it and return. 3757 // Construct the type object, canonicalize it and return.
3755 const Type& instantiated_type = Type::Handle( 3758 const Type& instantiated_type = Type::Handle(
3756 Type::New(cls, type_args_obj, Scanner::kDummyTokenIndex)); 3759 Type::New(cls, type_args_obj, Scanner::kDummyTokenIndex));
3757 ClassFinalizer::FinalizeType(cls, 3760 ClassFinalizer::FinalizeType(cls,
3758 instantiated_type, 3761 instantiated_type,
3759 ClassFinalizer::kCanonicalize); 3762 ClassFinalizer::kCanonicalize);
3760 return Api::NewHandle(isolate, instantiated_type.raw()); 3763 return Api::NewHandle(isolate, instantiated_type.raw());
3761 } 3764 }
3762 3765
3763 3766
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 } 3988 }
3986 { 3989 {
3987 NoGCScope no_gc; 3990 NoGCScope no_gc;
3988 RawObject* raw_obj = obj.raw(); 3991 RawObject* raw_obj = obj.raw();
3989 isolate->heap()->SetPeer(raw_obj, peer); 3992 isolate->heap()->SetPeer(raw_obj, peer);
3990 } 3993 }
3991 return Api::Success(); 3994 return Api::Success();
3992 } 3995 }
3993 3996
3994 } // namespace dart 3997 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698