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

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

Issue 17346002: Fix for issue 11262. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
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 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 } else { 1129 } else {
1130 return Api::NewError("Expected boolean result from =="); 1130 return Api::NewError("Expected boolean result from ==");
1131 } 1131 }
1132 } 1132 }
1133 1133
1134 1134
1135 // TODO(iposva): This call actually implements IsInstanceOfClass. 1135 // TODO(iposva): This call actually implements IsInstanceOfClass.
1136 // Do we also need a real Dart_IsInstanceOf, which should take an instance 1136 // Do we also need a real Dart_IsInstanceOf, which should take an instance
1137 // rather than an object and a type rather than a class? 1137 // rather than an object and a type rather than a class?
1138 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, 1138 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object,
1139 Dart_Handle clazz, 1139 Dart_Handle type,
1140 bool* value) { 1140 bool* value) {
1141 Isolate* isolate = Isolate::Current(); 1141 Isolate* isolate = Isolate::Current();
1142 DARTSCOPE(isolate); 1142 DARTSCOPE(isolate);
1143 1143
1144 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 1144 Type& type_obj = Type::Handle();
1145 if (cls.IsNull()) { 1145 Object& obj = Object::Handle(isolate, Api::UnwrapHandle(type));
1146 RETURN_TYPE_ERROR(isolate, clazz, Class); 1146 if (obj.IsNull()) {
1147 RETURN_NULL_ERROR(type);
1147 } 1148 }
1148 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1149 if (obj.IsType()) {
1150 type_obj ^= obj.raw();
1151 } else {
1152 if (!obj.IsClass()) {
1153 RETURN_TYPE_ERROR(isolate, type, Type);
1154 }
1155 type_obj ^= Type::NewNonParameterizedType(Class::Cast(obj));
1156 }
1157 obj = Api::UnwrapHandle(object);
1149 if (obj.IsError()) { 1158 if (obj.IsError()) {
1150 return object; 1159 return object;
1151 } else if (!obj.IsNull() && !obj.IsInstance()) { 1160 } else if (!obj.IsNull() && !obj.IsInstance()) {
1152 return Api::NewError( 1161 return Api::NewError(
1153 "%s expects argument 'object' to be an instance of Object.", 1162 "%s expects argument 'object' to be an instance of Object.",
1154 CURRENT_FUNC); 1163 CURRENT_FUNC);
1155 } 1164 }
1156 // Finalize all classes. 1165 // Finalize all classes.
1157 Dart_Handle state = Api::CheckIsolateState(isolate); 1166 Dart_Handle state = Api::CheckIsolateState(isolate);
1158 if (::Dart_IsError(state)) { 1167 if (::Dart_IsError(state)) {
1159 return state; 1168 return state;
1160 } 1169 }
1161 if (obj.IsInstance()) { 1170 if (obj.IsInstance()) {
1162 CHECK_CALLBACK_STATE(isolate); 1171 CHECK_CALLBACK_STATE(isolate);
1163 const Type& type = Type::Handle(isolate,
1164 Type::NewNonParameterizedType(cls));
1165 Error& malformed_type_error = Error::Handle(isolate); 1172 Error& malformed_type_error = Error::Handle(isolate);
1166 *value = Instance::Cast(obj).IsInstanceOf(type, 1173 *value = Instance::Cast(obj).IsInstanceOf(type_obj,
1167 TypeArguments::Handle(isolate), 1174 TypeArguments::Handle(isolate),
1168 &malformed_type_error); 1175 &malformed_type_error);
1169 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1176 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1170 } else { 1177 } else {
1171 *value = false; 1178 *value = false;
1172 } 1179 }
1173 return Api::Success(); 1180 return Api::Success();
1174 } 1181 }
1175 1182
1176 1183
(...skipping 2435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 if (cls.IsNull()) { 3619 if (cls.IsNull()) {
3613 // TODO(turnidge): Return null or error in this case? 3620 // TODO(turnidge): Return null or error in this case?
3614 const String& lib_name = String::Handle(isolate, lib.name()); 3621 const String& lib_name = String::Handle(isolate, lib.name());
3615 return Api::NewError("Class '%s' not found in library '%s'.", 3622 return Api::NewError("Class '%s' not found in library '%s'.",
3616 cls_name.ToCString(), lib_name.ToCString()); 3623 cls_name.ToCString(), lib_name.ToCString());
3617 } 3624 }
3618 return Api::NewHandle(isolate, cls.raw()); 3625 return Api::NewHandle(isolate, cls.raw());
3619 } 3626 }
3620 3627
3621 3628
3629 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
3630 Dart_Handle type_name,
3631 intptr_t number_of_type_arguments,
3632 Dart_Handle* type_arguments) {
3633 Isolate* isolate = Isolate::Current();
3634 DARTSCOPE(isolate);
3635
3636 // Validate the input arguments.
3637 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
3638 if (lib.IsNull()) {
3639 RETURN_TYPE_ERROR(isolate, library, Library);
3640 }
3641 const String& type_name_str = Api::UnwrapStringHandle(isolate, type_name);
3642 if (type_name_str.IsNull()) {
3643 RETURN_TYPE_ERROR(isolate, type_name, String);
3644 }
3645 const Class& cls =
3646 Class::Handle(isolate, lib.LookupClassAllowPrivate(type_name_str));
3647 if (cls.IsNull()) {
3648 const String& lib_name = String::Handle(isolate, lib.name());
3649 return Api::NewError("Type '%s' not found in library '%s'.",
3650 type_name_str.ToCString(), lib_name.ToCString());
3651 }
3652 intptr_t num_expected_type_arguments = cls.NumTypeParameters();
3653 if (num_expected_type_arguments == 0) {
3654 return Api::NewHandle(isolate, Type::NewNonParameterizedType(cls));
3655 }
3656 TypeArguments& type_args_obj = TypeArguments::Handle();
3657 if (number_of_type_arguments > 0) {
3658 if (type_arguments == NULL) {
3659 RETURN_NULL_ERROR(type_arguments);
3660 }
3661 if (num_expected_type_arguments != number_of_type_arguments) {
3662 return Api::NewError("Invalid number of type arguments specified, "
3663 "got %"Pd" expected %"Pd,
3664 number_of_type_arguments,
3665 num_expected_type_arguments);
3666 }
3667 const Array& array = Api::UnwrapArrayHandle(isolate, *type_arguments);
3668 if (array.IsNull()) {
3669 RETURN_TYPE_ERROR(isolate, *type_arguments, Array);
3670 }
3671 if (array.Length() != num_expected_type_arguments) {
3672 return Api::NewError("Invalid type arguments specified, expected an "
3673 "array of len %"Pd" but got an array of len %"Pd,
3674 number_of_type_arguments,
3675 array.Length());
3676 }
3677 // Set up the type arguments array.
3678 type_args_obj ^= TypeArguments::New(num_expected_type_arguments);
3679 AbstractType& type_arg = AbstractType::Handle();
3680 for (intptr_t i = 0; i < number_of_type_arguments; i++) {
3681 type_arg ^= array.At(i);
3682 type_args_obj.SetTypeAt(i, type_arg);
3683 }
3684 }
3685
3686 // Construct the type object, canonicalize it and return.
3687 const Type& instantiated_type = Type::Handle(
3688 Type::New(cls, type_args_obj, Scanner::kDummyTokenIndex));
3689 ClassFinalizer::FinalizeType(cls,
3690 instantiated_type,
3691 ClassFinalizer::kCanonicalize);
3692 return Api::NewHandle(isolate, instantiated_type.raw());
3693 }
3694
3695
3622 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { 3696 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
3623 Isolate* isolate = Isolate::Current(); 3697 Isolate* isolate = Isolate::Current();
3624 DARTSCOPE(isolate); 3698 DARTSCOPE(isolate);
3625 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); 3699 const Library& lib = Api::UnwrapLibraryHandle(isolate, library);
3626 if (lib.IsNull()) { 3700 if (lib.IsNull()) {
3627 RETURN_TYPE_ERROR(isolate, library, Library); 3701 RETURN_TYPE_ERROR(isolate, library, Library);
3628 } 3702 }
3629 const String& url = String::Handle(isolate, lib.url()); 3703 const String& url = String::Handle(isolate, lib.url());
3630 ASSERT(!url.IsNull()); 3704 ASSERT(!url.IsNull());
3631 return Api::NewHandle(isolate, url.raw()); 3705 return Api::NewHandle(isolate, url.raw());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 } 3917 }
3844 { 3918 {
3845 NoGCScope no_gc; 3919 NoGCScope no_gc;
3846 RawObject* raw_obj = obj.raw(); 3920 RawObject* raw_obj = obj.raw();
3847 isolate->heap()->SetPeer(raw_obj, peer); 3921 isolate->heap()->SetPeer(raw_obj, peer);
3848 } 3922 }
3849 return Api::Success(); 3923 return Api::Success();
3850 } 3924 }
3851 3925
3852 } // namespace dart 3926 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698