| OLD | NEW |
| 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 2816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2827 CHECK_CALLBACK_STATE(isolate); | 2827 CHECK_CALLBACK_STATE(isolate); |
| 2828 Object& result = Object::Handle(isolate); | 2828 Object& result = Object::Handle(isolate); |
| 2829 | 2829 |
| 2830 if (number_of_arguments < 0) { | 2830 if (number_of_arguments < 0) { |
| 2831 return Api::NewError( | 2831 return Api::NewError( |
| 2832 "%s expects argument 'number_of_arguments' to be non-negative.", | 2832 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 2833 CURRENT_FUNC); | 2833 CURRENT_FUNC); |
| 2834 } | 2834 } |
| 2835 | 2835 |
| 2836 // Get the class to instantiate. | 2836 // Get the class to instantiate. |
| 2837 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); | 2837 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); |
| 2838 if (type_obj.IsNull()) { | 2838 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { |
| 2839 RETURN_TYPE_ERROR(isolate, type, Type); | 2839 RETURN_TYPE_ERROR(isolate, type, Type); |
| 2840 } | 2840 } |
| 2841 Type& type_obj = Type::Handle(); |
| 2842 type_obj ^= unchecked_type.raw(); |
| 2841 Class& cls = Class::Handle(isolate, type_obj.type_class()); | 2843 Class& cls = Class::Handle(isolate, type_obj.type_class()); |
| 2842 const AbstractTypeArguments& type_arguments = | 2844 AbstractTypeArguments& type_arguments = |
| 2843 AbstractTypeArguments::Handle(isolate, type_obj.arguments()); | 2845 AbstractTypeArguments::Handle(isolate, type_obj.arguments()); |
| 2844 | 2846 |
| 2845 const String& base_constructor_name = String::Handle(isolate, cls.Name()); | 2847 const String& base_constructor_name = String::Handle(isolate, cls.Name()); |
| 2846 | 2848 |
| 2847 // And get the name of the constructor to invoke. | 2849 // And get the name of the constructor to invoke. |
| 2848 String& dot_name = String::Handle(isolate); | 2850 String& dot_name = String::Handle(isolate); |
| 2849 result = Api::UnwrapHandle(constructor_name); | 2851 result = Api::UnwrapHandle(constructor_name); |
| 2850 if (result.IsNull()) { | 2852 if (result.IsNull()) { |
| 2851 dot_name = Symbols::Dot().raw(); | 2853 dot_name = Symbols::Dot().raw(); |
| 2852 } else if (result.IsString()) { | 2854 } else if (result.IsString()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2870 if (result.IsError()) { | 2872 if (result.IsError()) { |
| 2871 return Api::NewHandle(isolate, result.raw()); | 2873 return Api::NewHandle(isolate, result.raw()); |
| 2872 } | 2874 } |
| 2873 ASSERT(result.IsFunction()); | 2875 ASSERT(result.IsFunction()); |
| 2874 Function& constructor = Function::Handle(isolate); | 2876 Function& constructor = Function::Handle(isolate); |
| 2875 constructor ^= result.raw(); | 2877 constructor ^= result.raw(); |
| 2876 | 2878 |
| 2877 Instance& new_object = Instance::Handle(isolate); | 2879 Instance& new_object = Instance::Handle(isolate); |
| 2878 if (constructor.IsRedirectingFactory()) { | 2880 if (constructor.IsRedirectingFactory()) { |
| 2879 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); | 2881 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); |
| 2880 const Type& type = Type::Handle(constructor.RedirectionType()); | 2882 Type& redirect_type = Type::Handle(constructor.RedirectionType()); |
| 2881 constructor = constructor.RedirectionTarget(); | 2883 constructor = constructor.RedirectionTarget(); |
| 2882 if (constructor.IsNull()) { | 2884 if (constructor.IsNull()) { |
| 2883 ASSERT(type.IsMalformed()); | 2885 ASSERT(redirect_type.IsMalformed()); |
| 2884 return Api::NewHandle(isolate, type.malformed_error()); | 2886 return Api::NewHandle(isolate, redirect_type.malformed_error()); |
| 2885 } | 2887 } |
| 2886 cls = type.type_class(); | 2888 |
| 2889 if (!redirect_type.IsInstantiated()) { |
| 2890 // The type arguments of the redirection type are instantiated from the |
| 2891 // type arguments of the type argument. |
| 2892 Error& malformed_error = Error::Handle(); |
| 2893 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, |
| 2894 &malformed_error); |
| 2895 if (!malformed_error.IsNull()) { |
| 2896 return Api::NewHandle(isolate, malformed_error.raw()); |
| 2897 } |
| 2898 } |
| 2899 |
| 2900 type_obj = redirect_type.raw(); |
| 2901 type_arguments = redirect_type.arguments(); |
| 2902 |
| 2903 cls = type_obj.type_class(); |
| 2887 } | 2904 } |
| 2888 if (constructor.IsConstructor()) { | 2905 if (constructor.IsConstructor()) { |
| 2889 // Create the new object. | 2906 // Create the new object. |
| 2890 new_object = Instance::New(cls); | 2907 new_object = Instance::New(cls); |
| 2891 } | 2908 } |
| 2892 | 2909 |
| 2893 // Create the argument list. | 2910 // Create the argument list. |
| 2894 intptr_t arg_index = 0; | 2911 intptr_t arg_index = 0; |
| 2895 int extra_args = (constructor.IsConstructor() ? 2 : 1); | 2912 int extra_args = (constructor.IsConstructor() ? 2 : 1); |
| 2896 const Array& args = | 2913 const Array& args = |
| (...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4284 } | 4301 } |
| 4285 { | 4302 { |
| 4286 NoGCScope no_gc; | 4303 NoGCScope no_gc; |
| 4287 RawObject* raw_obj = obj.raw(); | 4304 RawObject* raw_obj = obj.raw(); |
| 4288 isolate->heap()->SetPeer(raw_obj, peer); | 4305 isolate->heap()->SetPeer(raw_obj, peer); |
| 4289 } | 4306 } |
| 4290 return Api::Success(); | 4307 return Api::Success(); |
| 4291 } | 4308 } |
| 4292 | 4309 |
| 4293 } // namespace dart | 4310 } // namespace dart |
| OLD | NEW |