| 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 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2839 "%s expects argument 'number_of_arguments' to be non-negative.", | 2839 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 2840 CURRENT_FUNC); | 2840 CURRENT_FUNC); |
| 2841 } | 2841 } |
| 2842 | 2842 |
| 2843 // Get the class to instantiate. | 2843 // Get the class to instantiate. |
| 2844 result = Api::UnwrapHandle(type); | 2844 result = Api::UnwrapHandle(type); |
| 2845 if (result.IsNull()) { | 2845 if (result.IsNull()) { |
| 2846 RETURN_TYPE_ERROR(isolate, type, Type); | 2846 RETURN_TYPE_ERROR(isolate, type, Type); |
| 2847 } | 2847 } |
| 2848 Class& cls = Class::Handle(isolate); | 2848 Class& cls = Class::Handle(isolate); |
| 2849 AbstractTypeArguments& type_arguments = |
| 2850 AbstractTypeArguments::Handle(isolate); |
| 2851 |
| 2849 if (result.IsType()) { | 2852 if (result.IsType()) { |
| 2850 cls = Type::Cast(result).type_class(); | 2853 cls = Type::Cast(result).type_class(); |
| 2854 type_arguments = Type::Cast(result).arguments(); |
| 2851 } else if (result.IsClass()) { | 2855 } else if (result.IsClass()) { |
| 2852 // For backwards compatibility we allow class objects to be passed in | 2856 // For backwards compatibility we allow class objects to be passed in |
| 2853 // for now. This needs to be removed once all code that uses class | 2857 // for now. This needs to be removed once all code that uses class |
| 2854 // objects to invoke Dart_New is removed. | 2858 // objects to invoke Dart_New is removed. |
| 2855 cls ^= result.raw(); | 2859 cls ^= result.raw(); |
| 2860 type_arguments = Type::Handle(cls.BasicType()).arguments(); |
| 2856 } else { | 2861 } else { |
| 2857 RETURN_TYPE_ERROR(isolate, type, Type); | 2862 RETURN_TYPE_ERROR(isolate, type, Type); |
| 2858 } | 2863 } |
| 2859 | 2864 |
| 2860 String& base_constructor_name = String::Handle(); | 2865 String& base_constructor_name = String::Handle(); |
| 2861 base_constructor_name = cls.Name(); | 2866 base_constructor_name = cls.Name(); |
| 2862 | 2867 |
| 2863 // And get the name of the constructor to invoke. | 2868 // And get the name of the constructor to invoke. |
| 2864 String& dot_name = String::Handle(isolate); | 2869 String& dot_name = String::Handle(isolate); |
| 2865 result = Api::UnwrapHandle(constructor_name); | 2870 result = Api::UnwrapHandle(constructor_name); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2906 new_object = Instance::New(cls); | 2911 new_object = Instance::New(cls); |
| 2907 } | 2912 } |
| 2908 | 2913 |
| 2909 // Create the argument list. | 2914 // Create the argument list. |
| 2910 intptr_t arg_index = 0; | 2915 intptr_t arg_index = 0; |
| 2911 int extra_args = (constructor.IsConstructor() ? 2 : 1); | 2916 int extra_args = (constructor.IsConstructor() ? 2 : 1); |
| 2912 const Array& args = | 2917 const Array& args = |
| 2913 Array::Handle(isolate, Array::New(number_of_arguments + extra_args)); | 2918 Array::Handle(isolate, Array::New(number_of_arguments + extra_args)); |
| 2914 if (constructor.IsConstructor()) { | 2919 if (constructor.IsConstructor()) { |
| 2915 // Constructors get the uninitialized object and a constructor phase. | 2920 // Constructors get the uninitialized object and a constructor phase. |
| 2921 if (!type_arguments.IsNull()) { |
| 2922 // The type arguments will be null if the class has no type parameters, in |
| 2923 // which case the following call would fail because there is no slot |
| 2924 // reserved in the object for the type vector. |
| 2925 new_object.SetTypeArguments(type_arguments); |
| 2926 } |
| 2916 args.SetAt(arg_index++, new_object); | 2927 args.SetAt(arg_index++, new_object); |
| 2917 args.SetAt(arg_index++, | 2928 args.SetAt(arg_index++, |
| 2918 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); | 2929 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); |
| 2919 } else { | 2930 } else { |
| 2920 // Factories get type arguments. | 2931 // Factories get type arguments. |
| 2921 args.SetAt(arg_index++, TypeArguments::Handle(isolate)); | 2932 args.SetAt(arg_index++, type_arguments); |
| 2922 } | 2933 } |
| 2923 Object& argument = Object::Handle(isolate); | 2934 Object& argument = Object::Handle(isolate); |
| 2924 for (int i = 0; i < number_of_arguments; i++) { | 2935 for (int i = 0; i < number_of_arguments; i++) { |
| 2925 argument = Api::UnwrapHandle(arguments[i]); | 2936 argument = Api::UnwrapHandle(arguments[i]); |
| 2926 if (!argument.IsNull() && !argument.IsInstance()) { | 2937 if (!argument.IsNull() && !argument.IsInstance()) { |
| 2927 if (argument.IsError()) { | 2938 if (argument.IsError()) { |
| 2928 return Api::NewHandle(isolate, argument.raw()); | 2939 return Api::NewHandle(isolate, argument.raw()); |
| 2929 } else { | 2940 } else { |
| 2930 return Api::NewError( | 2941 return Api::NewError( |
| 2931 "%s expects arguments[%d] to be an Instance handle.", | 2942 "%s expects arguments[%d] to be an Instance handle.", |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4326 } | 4337 } |
| 4327 { | 4338 { |
| 4328 NoGCScope no_gc; | 4339 NoGCScope no_gc; |
| 4329 RawObject* raw_obj = obj.raw(); | 4340 RawObject* raw_obj = obj.raw(); |
| 4330 isolate->heap()->SetPeer(raw_obj, peer); | 4341 isolate->heap()->SetPeer(raw_obj, peer); |
| 4331 } | 4342 } |
| 4332 return Api::Success(); | 4343 return Api::Success(); |
| 4333 } | 4344 } |
| 4334 | 4345 |
| 4335 } // namespace dart | 4346 } // namespace dart |
| OLD | NEW |