| 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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 2666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 isolate, lib.LookupClassAllowPrivate(class_name)); | 2677 isolate, lib.LookupClassAllowPrivate(class_name)); |
| 2678 ASSERT(!cls.IsNull()); | 2678 ASSERT(!cls.IsNull()); |
| 2679 Object& result = Object::Handle(isolate); | 2679 Object& result = Object::Handle(isolate); |
| 2680 String& dot_name = String::Handle(String::New(".")); | 2680 String& dot_name = String::Handle(String::New(".")); |
| 2681 String& constr_name = String::Handle(String::Concat(class_name, dot_name)); | 2681 String& constr_name = String::Handle(String::Concat(class_name, dot_name)); |
| 2682 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1); | 2682 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1); |
| 2683 if (result.IsError()) return result.raw(); | 2683 if (result.IsError()) return result.raw(); |
| 2684 ASSERT(result.IsFunction()); | 2684 ASSERT(result.IsFunction()); |
| 2685 Function& constructor = Function::Handle(isolate); | 2685 Function& constructor = Function::Handle(isolate); |
| 2686 constructor ^= result.raw(); | 2686 constructor ^= result.raw(); |
| 2687 if (!constructor.IsConstructor()) { | 2687 if (!constructor.IsGenerativeConstructor()) { |
| 2688 const String& message = String::Handle( | 2688 const String& message = String::Handle( |
| 2689 String::NewFormatted("%s: class '%s' is not a constructor.", | 2689 String::NewFormatted("%s: class '%s' is not a constructor.", |
| 2690 CURRENT_FUNC, class_name.ToCString())); | 2690 CURRENT_FUNC, class_name.ToCString())); |
| 2691 return ApiError::New(message); | 2691 return ApiError::New(message); |
| 2692 } | 2692 } |
| 2693 Instance& exception = Instance::Handle(isolate); | 2693 Instance& exception = Instance::Handle(isolate); |
| 2694 exception = Instance::New(cls); | 2694 exception = Instance::New(cls); |
| 2695 const Array& args = Array::Handle(isolate, Array::New(3)); | 2695 const Array& args = Array::Handle(isolate, Array::New(3)); |
| 2696 args.SetAt(0, exception); | 2696 args.SetAt(0, exception); |
| 2697 args.SetAt(1, | 2697 args.SetAt(1, |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3144 } | 3144 } |
| 3145 | 3145 |
| 3146 | 3146 |
| 3147 static Dart_Handle NewByteData(Isolate* isolate, intptr_t length) { | 3147 static Dart_Handle NewByteData(Isolate* isolate, intptr_t length) { |
| 3148 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); | 3148 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); |
| 3149 Object& result = Object::Handle(isolate); | 3149 Object& result = Object::Handle(isolate); |
| 3150 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot(), 1); | 3150 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot(), 1); |
| 3151 ASSERT(!result.IsNull()); | 3151 ASSERT(!result.IsNull()); |
| 3152 ASSERT(result.IsFunction()); | 3152 ASSERT(result.IsFunction()); |
| 3153 const Function& factory = Function::Cast(result); | 3153 const Function& factory = Function::Cast(result); |
| 3154 ASSERT(!factory.IsConstructor()); | 3154 ASSERT(!factory.IsGenerativeConstructor()); |
| 3155 | 3155 |
| 3156 // Create the argument list. | 3156 // Create the argument list. |
| 3157 const Array& args = Array::Handle(isolate, Array::New(2)); | 3157 const Array& args = Array::Handle(isolate, Array::New(2)); |
| 3158 // Factories get type arguments. | 3158 // Factories get type arguments. |
| 3159 args.SetAt(0, Object::null_type_arguments()); | 3159 args.SetAt(0, Object::null_type_arguments()); |
| 3160 args.SetAt(1, Smi::Handle(isolate, Smi::New(length))); | 3160 args.SetAt(1, Smi::Handle(isolate, Smi::New(length))); |
| 3161 | 3161 |
| 3162 // Invoke the constructor and return the new object. | 3162 // Invoke the constructor and return the new object. |
| 3163 result = DartEntry::InvokeFunction(factory, args); | 3163 result = DartEntry::InvokeFunction(factory, args); |
| 3164 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3164 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3193 Dart_Handle ext_data = NewExternalTypedData( | 3193 Dart_Handle ext_data = NewExternalTypedData( |
| 3194 isolate, kExternalTypedDataUint8ArrayCid, data, length); | 3194 isolate, kExternalTypedDataUint8ArrayCid, data, length); |
| 3195 if (::Dart_IsError(ext_data)) { | 3195 if (::Dart_IsError(ext_data)) { |
| 3196 return ext_data; | 3196 return ext_data; |
| 3197 } | 3197 } |
| 3198 Object& result = Object::Handle(isolate); | 3198 Object& result = Object::Handle(isolate); |
| 3199 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot_view(), 3); | 3199 result = GetByteDataConstructor(isolate, Symbols::ByteDataDot_view(), 3); |
| 3200 ASSERT(!result.IsNull()); | 3200 ASSERT(!result.IsNull()); |
| 3201 ASSERT(result.IsFunction()); | 3201 ASSERT(result.IsFunction()); |
| 3202 const Function& factory = Function::Cast(result); | 3202 const Function& factory = Function::Cast(result); |
| 3203 ASSERT(!factory.IsConstructor()); | 3203 ASSERT(!factory.IsGenerativeConstructor()); |
| 3204 | 3204 |
| 3205 // Create the argument list. | 3205 // Create the argument list. |
| 3206 const intptr_t num_args = 3; | 3206 const intptr_t num_args = 3; |
| 3207 const Array& args = Array::Handle(isolate, Array::New(num_args + 1)); | 3207 const Array& args = Array::Handle(isolate, Array::New(num_args + 1)); |
| 3208 // Factories get type arguments. | 3208 // Factories get type arguments. |
| 3209 args.SetAt(0, Object::null_type_arguments()); | 3209 args.SetAt(0, Object::null_type_arguments()); |
| 3210 const ExternalTypedData& array = | 3210 const ExternalTypedData& array = |
| 3211 Api::UnwrapExternalTypedDataHandle(isolate, ext_data); | 3211 Api::UnwrapExternalTypedDataHandle(isolate, ext_data); |
| 3212 args.SetAt(1, array); | 3212 args.SetAt(1, array); |
| 3213 Smi& smi = Smi::Handle(isolate); | 3213 Smi& smi = Smi::Handle(isolate); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3374 RETURN_TYPE_ERROR(isolate, typed_data, 'TypedData'); | 3374 RETURN_TYPE_ERROR(isolate, typed_data, 'TypedData'); |
| 3375 } | 3375 } |
| 3376 Object& result = Object::Handle(isolate); | 3376 Object& result = Object::Handle(isolate); |
| 3377 result = GetByteBufferConstructor(isolate, | 3377 result = GetByteBufferConstructor(isolate, |
| 3378 Symbols::_ByteBuffer(), | 3378 Symbols::_ByteBuffer(), |
| 3379 Symbols::_ByteBufferDot_New(), | 3379 Symbols::_ByteBufferDot_New(), |
| 3380 1); | 3380 1); |
| 3381 ASSERT(!result.IsNull()); | 3381 ASSERT(!result.IsNull()); |
| 3382 ASSERT(result.IsFunction()); | 3382 ASSERT(result.IsFunction()); |
| 3383 const Function& factory = Function::Cast(result); | 3383 const Function& factory = Function::Cast(result); |
| 3384 ASSERT(!factory.IsConstructor()); | 3384 ASSERT(!factory.IsGenerativeConstructor()); |
| 3385 | 3385 |
| 3386 // Create the argument list. | 3386 // Create the argument list. |
| 3387 const Array& args = Array::Handle(isolate, Array::New(2)); | 3387 const Array& args = Array::Handle(isolate, Array::New(2)); |
| 3388 // Factories get type arguments. | 3388 // Factories get type arguments. |
| 3389 args.SetAt(0, Object::null_type_arguments()); | 3389 args.SetAt(0, Object::null_type_arguments()); |
| 3390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(typed_data)); | 3390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(typed_data)); |
| 3391 args.SetAt(1, obj); | 3391 args.SetAt(1, obj); |
| 3392 | 3392 |
| 3393 // Invoke the factory constructor and return the new object. | 3393 // Invoke the factory constructor and return the new object. |
| 3394 result = DartEntry::InvokeFunction(factory, args); | 3394 result = DartEntry::InvokeFunction(factory, args); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3519 | 3519 |
| 3520 static RawObject* ResolveConstructor(const char* current_func, | 3520 static RawObject* ResolveConstructor(const char* current_func, |
| 3521 const Class& cls, | 3521 const Class& cls, |
| 3522 const String& class_name, | 3522 const String& class_name, |
| 3523 const String& constr_name, | 3523 const String& constr_name, |
| 3524 int num_args) { | 3524 int num_args) { |
| 3525 // The constructor must be present in the interface. | 3525 // The constructor must be present in the interface. |
| 3526 const Function& constructor = | 3526 const Function& constructor = |
| 3527 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); | 3527 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); |
| 3528 if (constructor.IsNull() || | 3528 if (constructor.IsNull() || |
| 3529 (!constructor.IsConstructor() && !constructor.IsFactory())) { | 3529 (!constructor.IsGenerativeConstructor() && !constructor.IsFactory())) { |
| 3530 const String& lookup_class_name = String::Handle(cls.Name()); | 3530 const String& lookup_class_name = String::Handle(cls.Name()); |
| 3531 if (!class_name.Equals(lookup_class_name)) { | 3531 if (!class_name.Equals(lookup_class_name)) { |
| 3532 // When the class name used to build the constructor name is | 3532 // When the class name used to build the constructor name is |
| 3533 // different than the name of the class in which we are doing | 3533 // different than the name of the class in which we are doing |
| 3534 // the lookup, it can be confusing to the user to figure out | 3534 // the lookup, it can be confusing to the user to figure out |
| 3535 // what's going on. Be a little more explicit for these error | 3535 // what's going on. Be a little more explicit for these error |
| 3536 // messages. | 3536 // messages. |
| 3537 const String& message = String::Handle( | 3537 const String& message = String::Handle( |
| 3538 String::NewFormatted( | 3538 String::NewFormatted( |
| 3539 "%s: could not find factory '%s' in class '%s'.", | 3539 "%s: could not find factory '%s' in class '%s'.", |
| 3540 current_func, | 3540 current_func, |
| 3541 constr_name.ToCString(), | 3541 constr_name.ToCString(), |
| 3542 lookup_class_name.ToCString())); | 3542 lookup_class_name.ToCString())); |
| 3543 return ApiError::New(message); | 3543 return ApiError::New(message); |
| 3544 } else { | 3544 } else { |
| 3545 const String& message = String::Handle( | 3545 const String& message = String::Handle( |
| 3546 String::NewFormatted("%s: could not find constructor '%s'.", | 3546 String::NewFormatted("%s: could not find constructor '%s'.", |
| 3547 current_func, constr_name.ToCString())); | 3547 current_func, constr_name.ToCString())); |
| 3548 return ApiError::New(message); | 3548 return ApiError::New(message); |
| 3549 } | 3549 } |
| 3550 } | 3550 } |
| 3551 int extra_args = (constructor.IsConstructor() ? 2 : 1); | 3551 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); |
| 3552 String& error_message = String::Handle(); | 3552 String& error_message = String::Handle(); |
| 3553 if (!constructor.AreValidArgumentCounts(num_args + extra_args, | 3553 if (!constructor.AreValidArgumentCounts(num_args + extra_args, |
| 3554 0, | 3554 0, |
| 3555 &error_message)) { | 3555 &error_message)) { |
| 3556 const String& message = String::Handle( | 3556 const String& message = String::Handle( |
| 3557 String::NewFormatted("%s: wrong argument count for " | 3557 String::NewFormatted("%s: wrong argument count for " |
| 3558 "constructor '%s': %s.", | 3558 "constructor '%s': %s.", |
| 3559 current_func, | 3559 current_func, |
| 3560 constr_name.ToCString(), | 3560 constr_name.ToCString(), |
| 3561 error_message.ToCString())); | 3561 error_message.ToCString())); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3644 return Api::NewHandle(isolate, bound_error.raw()); | 3644 return Api::NewHandle(isolate, bound_error.raw()); |
| 3645 } | 3645 } |
| 3646 redirect_type ^= redirect_type.Canonicalize(); | 3646 redirect_type ^= redirect_type.Canonicalize(); |
| 3647 } | 3647 } |
| 3648 | 3648 |
| 3649 type_obj = redirect_type.raw(); | 3649 type_obj = redirect_type.raw(); |
| 3650 type_arguments = redirect_type.arguments(); | 3650 type_arguments = redirect_type.arguments(); |
| 3651 | 3651 |
| 3652 cls = type_obj.type_class(); | 3652 cls = type_obj.type_class(); |
| 3653 } | 3653 } |
| 3654 if (constructor.IsConstructor()) { | 3654 if (constructor.IsGenerativeConstructor()) { |
| 3655 // Create the new object. | 3655 // Create the new object. |
| 3656 new_object = Instance::New(cls); | 3656 new_object = Instance::New(cls); |
| 3657 } | 3657 } |
| 3658 | 3658 |
| 3659 // Create the argument list. | 3659 // Create the argument list. |
| 3660 intptr_t arg_index = 0; | 3660 intptr_t arg_index = 0; |
| 3661 int extra_args = (constructor.IsConstructor() ? 2 : 1); | 3661 int extra_args = (constructor.IsGenerativeConstructor() ? 2 : 1); |
| 3662 const Array& args = | 3662 const Array& args = |
| 3663 Array::Handle(isolate, Array::New(number_of_arguments + extra_args)); | 3663 Array::Handle(isolate, Array::New(number_of_arguments + extra_args)); |
| 3664 if (constructor.IsConstructor()) { | 3664 if (constructor.IsGenerativeConstructor()) { |
| 3665 // Constructors get the uninitialized object and a constructor phase. | 3665 // Constructors get the uninitialized object and a constructor phase. |
| 3666 if (!type_arguments.IsNull()) { | 3666 if (!type_arguments.IsNull()) { |
| 3667 // The type arguments will be null if the class has no type parameters, in | 3667 // The type arguments will be null if the class has no type parameters, in |
| 3668 // which case the following call would fail because there is no slot | 3668 // which case the following call would fail because there is no slot |
| 3669 // reserved in the object for the type vector. | 3669 // reserved in the object for the type vector. |
| 3670 new_object.SetTypeArguments(type_arguments); | 3670 new_object.SetTypeArguments(type_arguments); |
| 3671 } | 3671 } |
| 3672 args.SetAt(arg_index++, new_object); | 3672 args.SetAt(arg_index++, new_object); |
| 3673 args.SetAt(arg_index++, | 3673 args.SetAt(arg_index++, |
| 3674 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); | 3674 Smi::Handle(isolate, Smi::New(Function::kCtorPhaseAll))); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3690 } | 3690 } |
| 3691 args.SetAt(arg_index++, argument); | 3691 args.SetAt(arg_index++, argument); |
| 3692 } | 3692 } |
| 3693 | 3693 |
| 3694 // Invoke the constructor and return the new object. | 3694 // Invoke the constructor and return the new object. |
| 3695 result = DartEntry::InvokeFunction(constructor, args); | 3695 result = DartEntry::InvokeFunction(constructor, args); |
| 3696 if (result.IsError()) { | 3696 if (result.IsError()) { |
| 3697 return Api::NewHandle(isolate, result.raw()); | 3697 return Api::NewHandle(isolate, result.raw()); |
| 3698 } | 3698 } |
| 3699 | 3699 |
| 3700 if (constructor.IsConstructor()) { | 3700 if (constructor.IsGenerativeConstructor()) { |
| 3701 ASSERT(result.IsNull()); | 3701 ASSERT(result.IsNull()); |
| 3702 } else { | 3702 } else { |
| 3703 ASSERT(result.IsNull() || result.IsInstance()); | 3703 ASSERT(result.IsNull() || result.IsInstance()); |
| 3704 new_object ^= result.raw(); | 3704 new_object ^= result.raw(); |
| 3705 } | 3705 } |
| 3706 return Api::NewHandle(isolate, new_object.raw()); | 3706 return Api::NewHandle(isolate, new_object.raw()); |
| 3707 } | 3707 } |
| 3708 | 3708 |
| 3709 | 3709 |
| 3710 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) { | 3710 static RawInstance* AllocateObject(Isolate* isolate, const Class& cls) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3848 strings.SetAt(0, class_name); | 3848 strings.SetAt(0, class_name); |
| 3849 strings.SetAt(1, Symbols::Dot()); | 3849 strings.SetAt(1, Symbols::Dot()); |
| 3850 strings.SetAt(2, constructor_name); | 3850 strings.SetAt(2, constructor_name); |
| 3851 const String& dot_name = String::Handle(isolate, String::ConcatAll(strings)); | 3851 const String& dot_name = String::Handle(isolate, String::ConcatAll(strings)); |
| 3852 const TypeArguments& type_arguments = | 3852 const TypeArguments& type_arguments = |
| 3853 TypeArguments::Handle(isolate, type_obj.arguments()); | 3853 TypeArguments::Handle(isolate, type_obj.arguments()); |
| 3854 const Function& constructor = | 3854 const Function& constructor = |
| 3855 Function::Handle(isolate, cls.LookupFunctionAllowPrivate(dot_name)); | 3855 Function::Handle(isolate, cls.LookupFunctionAllowPrivate(dot_name)); |
| 3856 const int extra_args = 2; | 3856 const int extra_args = 2; |
| 3857 if (!constructor.IsNull() && | 3857 if (!constructor.IsNull() && |
| 3858 constructor.IsConstructor() && | 3858 constructor.IsGenerativeConstructor() && |
| 3859 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, | 3859 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, |
| 3860 0, | 3860 0, |
| 3861 NULL)) { | 3861 NULL)) { |
| 3862 // Create the argument list. | 3862 // Create the argument list. |
| 3863 // Constructors get the uninitialized object and a constructor phase. | 3863 // Constructors get the uninitialized object and a constructor phase. |
| 3864 if (!type_arguments.IsNull()) { | 3864 if (!type_arguments.IsNull()) { |
| 3865 // The type arguments will be null if the class has no type | 3865 // The type arguments will be null if the class has no type |
| 3866 // parameters, in which case the following call would fail | 3866 // parameters, in which case the following call would fail |
| 3867 // because there is no slot reserved in the object for the | 3867 // because there is no slot reserved in the object for the |
| 3868 // type vector. | 3868 // type vector. |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5475 | 5475 |
| 5476 | 5476 |
| 5477 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5477 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 5478 const char* name, | 5478 const char* name, |
| 5479 Dart_ServiceRequestCallback callback, | 5479 Dart_ServiceRequestCallback callback, |
| 5480 void* user_data) { | 5480 void* user_data) { |
| 5481 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5481 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 5482 } | 5482 } |
| 5483 | 5483 |
| 5484 } // namespace dart | 5484 } // namespace dart |
| OLD | NEW |