| 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { | 364 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { |
| 365 Object& ref = reuse.Handle(); | 365 Object& ref = reuse.Handle(); |
| 366 ref = Api::UnwrapHandle(dart_handle); | 366 ref = Api::UnwrapHandle(dart_handle); |
| 367 if (ref.IsInstance()) { | 367 if (ref.IsInstance()) { |
| 368 return Instance::Cast(ref); | 368 return Instance::Cast(ref); |
| 369 } | 369 } |
| 370 return Object::null_instance(); | 370 return Object::null_instance(); |
| 371 } | 371 } |
| 372 | 372 |
| 373 | 373 |
| 374 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { | 374 Dart_Handle Api::CheckAndFinalizePendingClasses(Isolate* isolate) { |
| 375 if (!isolate->AllowClassFinalization()) { | 375 if (!isolate->AllowClassFinalization()) { |
| 376 // Class finalization is blocked for the isolate. Do nothing. | 376 // Class finalization is blocked for the isolate. Do nothing. |
| 377 return Api::Success(); | 377 return Api::Success(); |
| 378 } | 378 } |
| 379 if (ClassFinalizer::ProcessPendingClasses()) { | 379 if (ClassFinalizer::ProcessPendingClasses()) { |
| 380 return Api::Success(); | 380 return Api::Success(); |
| 381 } | 381 } |
| 382 ASSERT(isolate->object_store()->sticky_error() != Object::null()); | 382 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
| 383 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 383 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
| 384 } | 384 } |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 intptr_t* size) { | 1393 intptr_t* size) { |
| 1394 Isolate* isolate = Isolate::Current(); | 1394 Isolate* isolate = Isolate::Current(); |
| 1395 DARTSCOPE(isolate); | 1395 DARTSCOPE(isolate); |
| 1396 TIMERSCOPE(isolate, time_creating_snapshot); | 1396 TIMERSCOPE(isolate, time_creating_snapshot); |
| 1397 if (buffer == NULL) { | 1397 if (buffer == NULL) { |
| 1398 RETURN_NULL_ERROR(buffer); | 1398 RETURN_NULL_ERROR(buffer); |
| 1399 } | 1399 } |
| 1400 if (size == NULL) { | 1400 if (size == NULL) { |
| 1401 RETURN_NULL_ERROR(size); | 1401 RETURN_NULL_ERROR(size); |
| 1402 } | 1402 } |
| 1403 Dart_Handle state = Api::CheckIsolateState(isolate); | 1403 // Finalize all classes if needed. |
| 1404 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 1404 if (::Dart_IsError(state)) { | 1405 if (::Dart_IsError(state)) { |
| 1405 return state; | 1406 return state; |
| 1406 } | 1407 } |
| 1407 // Since this is only a snapshot the root library should not be set. | 1408 // Since this is only a snapshot the root library should not be set. |
| 1408 isolate->object_store()->set_root_library(Library::Handle(isolate)); | 1409 isolate->object_store()->set_root_library(Library::Handle(isolate)); |
| 1409 FullSnapshotWriter writer(buffer, ApiReallocate); | 1410 FullSnapshotWriter writer(buffer, ApiReallocate); |
| 1410 writer.WriteFullSnapshot(); | 1411 writer.WriteFullSnapshot(); |
| 1411 *size = writer.BytesWritten(); | 1412 *size = writer.BytesWritten(); |
| 1412 return Api::Success(); | 1413 return Api::Success(); |
| 1413 } | 1414 } |
| 1414 | 1415 |
| 1415 | 1416 |
| 1416 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1417 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, |
| 1417 intptr_t* size) { | 1418 intptr_t* size) { |
| 1418 Isolate* isolate = Isolate::Current(); | 1419 Isolate* isolate = Isolate::Current(); |
| 1419 DARTSCOPE(isolate); | 1420 DARTSCOPE(isolate); |
| 1420 TIMERSCOPE(isolate, time_creating_snapshot); | 1421 TIMERSCOPE(isolate, time_creating_snapshot); |
| 1421 if (buffer == NULL) { | 1422 if (buffer == NULL) { |
| 1422 RETURN_NULL_ERROR(buffer); | 1423 RETURN_NULL_ERROR(buffer); |
| 1423 } | 1424 } |
| 1424 if (size == NULL) { | 1425 if (size == NULL) { |
| 1425 RETURN_NULL_ERROR(size); | 1426 RETURN_NULL_ERROR(size); |
| 1426 } | 1427 } |
| 1427 Dart_Handle state = Api::CheckIsolateState(isolate); | 1428 // Finalize all classes if needed. |
| 1429 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 1428 if (::Dart_IsError(state)) { | 1430 if (::Dart_IsError(state)) { |
| 1429 return state; | 1431 return state; |
| 1430 } | 1432 } |
| 1431 Library& library = | 1433 Library& library = |
| 1432 Library::Handle(isolate, isolate->object_store()->root_library()); | 1434 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 1433 if (library.IsNull()) { | 1435 if (library.IsNull()) { |
| 1434 return | 1436 return |
| 1435 Api::NewError("%s expects the isolate to have a script loaded in it.", | 1437 Api::NewError("%s expects the isolate to have a script loaded in it.", |
| 1436 CURRENT_FUNC); | 1438 CURRENT_FUNC); |
| 1437 } | 1439 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 Dart_Handle type, | 1710 Dart_Handle type, |
| 1709 bool* value) { | 1711 bool* value) { |
| 1710 Isolate* isolate = Isolate::Current(); | 1712 Isolate* isolate = Isolate::Current(); |
| 1711 DARTSCOPE(isolate); | 1713 DARTSCOPE(isolate); |
| 1712 | 1714 |
| 1713 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); | 1715 const Type& type_obj = Api::UnwrapTypeHandle(isolate, type); |
| 1714 if (type_obj.IsNull()) { | 1716 if (type_obj.IsNull()) { |
| 1715 *value = false; | 1717 *value = false; |
| 1716 RETURN_TYPE_ERROR(isolate, type, Type); | 1718 RETURN_TYPE_ERROR(isolate, type, Type); |
| 1717 } | 1719 } |
| 1720 if (!type_obj.IsFinalized()) { |
| 1721 return Api::NewError( |
| 1722 "%s expects argument 'type' to be a fully resolved type.", |
| 1723 CURRENT_FUNC); |
| 1724 } |
| 1718 if (object == Api::Null()) { | 1725 if (object == Api::Null()) { |
| 1719 *value = false; | 1726 *value = false; |
| 1720 return Api::Success(); | 1727 return Api::Success(); |
| 1721 } | 1728 } |
| 1722 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); | 1729 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); |
| 1723 if (instance.IsNull()) { | 1730 if (instance.IsNull()) { |
| 1724 *value = false; | 1731 *value = false; |
| 1725 RETURN_TYPE_ERROR(isolate, object, Instance); | 1732 RETURN_TYPE_ERROR(isolate, object, Instance); |
| 1726 } | 1733 } |
| 1727 // Finalize all classes. | |
| 1728 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 1729 if (::Dart_IsError(state)) { | |
| 1730 *value = false; | |
| 1731 return state; | |
| 1732 } | |
| 1733 CHECK_CALLBACK_STATE(isolate); | 1734 CHECK_CALLBACK_STATE(isolate); |
| 1734 Error& malformed_type_error = Error::Handle(isolate); | 1735 Error& malformed_type_error = Error::Handle(isolate); |
| 1735 *value = instance.IsInstanceOf(type_obj, | 1736 *value = instance.IsInstanceOf(type_obj, |
| 1736 Object::null_type_arguments(), | 1737 Object::null_type_arguments(), |
| 1737 &malformed_type_error); | 1738 &malformed_type_error); |
| 1738 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1739 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
| 1739 return Api::Success(); | 1740 return Api::Success(); |
| 1740 } | 1741 } |
| 1741 | 1742 |
| 1742 | 1743 |
| (...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3499 CURRENT_FUNC); | 3500 CURRENT_FUNC); |
| 3500 } | 3501 } |
| 3501 | 3502 |
| 3502 // Get the class to instantiate. | 3503 // Get the class to instantiate. |
| 3503 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); | 3504 Object& unchecked_type = Object::Handle(Api::UnwrapHandle(type)); |
| 3504 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { | 3505 if (unchecked_type.IsNull() || !unchecked_type.IsType()) { |
| 3505 RETURN_TYPE_ERROR(isolate, type, Type); | 3506 RETURN_TYPE_ERROR(isolate, type, Type); |
| 3506 } | 3507 } |
| 3507 Type& type_obj = Type::Handle(); | 3508 Type& type_obj = Type::Handle(); |
| 3508 type_obj ^= unchecked_type.raw(); | 3509 type_obj ^= unchecked_type.raw(); |
| 3510 if (!type_obj.IsFinalized()) { |
| 3511 return Api::NewError( |
| 3512 "%s expects argument 'type' to be a fully resolved type.", |
| 3513 CURRENT_FUNC); |
| 3514 } |
| 3509 Class& cls = Class::Handle(isolate, type_obj.type_class()); | 3515 Class& cls = Class::Handle(isolate, type_obj.type_class()); |
| 3510 TypeArguments& type_arguments = | 3516 TypeArguments& type_arguments = |
| 3511 TypeArguments::Handle(isolate, type_obj.arguments()); | 3517 TypeArguments::Handle(isolate, type_obj.arguments()); |
| 3512 | 3518 |
| 3513 const String& base_constructor_name = String::Handle(isolate, cls.Name()); | 3519 const String& base_constructor_name = String::Handle(isolate, cls.Name()); |
| 3514 | 3520 |
| 3515 // And get the name of the constructor to invoke. | 3521 // And get the name of the constructor to invoke. |
| 3516 String& dot_name = String::Handle(isolate); | 3522 String& dot_name = String::Handle(isolate); |
| 3517 result = Api::UnwrapHandle(constructor_name); | 3523 result = Api::UnwrapHandle(constructor_name); |
| 3518 if (result.IsNull()) { | 3524 if (result.IsNull()) { |
| 3519 dot_name = Symbols::Dot().raw(); | 3525 dot_name = Symbols::Dot().raw(); |
| 3520 } else if (result.IsString()) { | 3526 } else if (result.IsString()) { |
| 3521 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); | 3527 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); |
| 3522 } else { | 3528 } else { |
| 3523 RETURN_TYPE_ERROR(isolate, constructor_name, String); | 3529 RETURN_TYPE_ERROR(isolate, constructor_name, String); |
| 3524 } | 3530 } |
| 3525 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 3526 if (::Dart_IsError(state)) { | |
| 3527 return state; | |
| 3528 } | |
| 3529 | 3531 |
| 3530 // Resolve the constructor. | 3532 // Resolve the constructor. |
| 3531 String& constr_name = | 3533 String& constr_name = |
| 3532 String::Handle(String::Concat(base_constructor_name, dot_name)); | 3534 String::Handle(String::Concat(base_constructor_name, dot_name)); |
| 3533 result = ResolveConstructor("Dart_New", | 3535 result = ResolveConstructor("Dart_New", |
| 3534 cls, | 3536 cls, |
| 3535 base_constructor_name, | 3537 base_constructor_name, |
| 3536 constr_name, | 3538 constr_name, |
| 3537 number_of_arguments); | 3539 number_of_arguments); |
| 3538 if (result.IsError()) { | 3540 if (result.IsError()) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3746 } | 3748 } |
| 3747 const String& constructor_name = Api::UnwrapStringHandle(isolate, name); | 3749 const String& constructor_name = Api::UnwrapStringHandle(isolate, name); |
| 3748 if (constructor_name.IsNull()) { | 3750 if (constructor_name.IsNull()) { |
| 3749 RETURN_TYPE_ERROR(isolate, name, String); | 3751 RETURN_TYPE_ERROR(isolate, name, String); |
| 3750 } | 3752 } |
| 3751 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); | 3753 const Instance& instance = Api::UnwrapInstanceHandle(isolate, object); |
| 3752 if (instance.IsNull()) { | 3754 if (instance.IsNull()) { |
| 3753 RETURN_TYPE_ERROR(isolate, object, Instance); | 3755 RETURN_TYPE_ERROR(isolate, object, Instance); |
| 3754 } | 3756 } |
| 3755 | 3757 |
| 3756 // Since we have allocated an object it would mean that all classes | 3758 // Since we have allocated an object it would mean that the type |
| 3757 // are finalized and hence it is not necessary to call | 3759 // is finalized. |
| 3758 // Api::CheckIsolateState. | |
| 3759 // TODO(asiva): How do we ensure that a constructor is not called more than | 3760 // TODO(asiva): How do we ensure that a constructor is not called more than |
| 3760 // once for the same object. | 3761 // once for the same object. |
| 3761 | 3762 |
| 3762 // Construct name of the constructor to invoke. | 3763 // Construct name of the constructor to invoke. |
| 3763 const Type& type_obj = Type::Handle(isolate, instance.GetType()); | 3764 const Type& type_obj = Type::Handle(isolate, instance.GetType()); |
| 3764 const Class& cls = Class::Handle(isolate, type_obj.type_class()); | 3765 const Class& cls = Class::Handle(isolate, type_obj.type_class()); |
| 3765 const String& class_name = String::Handle(isolate, cls.Name()); | 3766 const String& class_name = String::Handle(isolate, cls.Name()); |
| 3766 const Array& strings = Array::Handle(Array::New(3)); | 3767 const Array& strings = Array::Handle(Array::New(3)); |
| 3767 strings.SetAt(0, class_name); | 3768 strings.SetAt(0, class_name); |
| 3768 strings.SetAt(1, Symbols::Dot()); | 3769 strings.SetAt(1, Symbols::Dot()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3834 "%s expects argument 'number_of_arguments' to be non-negative.", | 3835 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3835 CURRENT_FUNC); | 3836 CURRENT_FUNC); |
| 3836 } | 3837 } |
| 3837 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 3838 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 3838 if (obj.IsError()) { | 3839 if (obj.IsError()) { |
| 3839 return target; | 3840 return target; |
| 3840 } | 3841 } |
| 3841 Dart_Handle result; | 3842 Dart_Handle result; |
| 3842 Array& args = Array::Handle(isolate); | 3843 Array& args = Array::Handle(isolate); |
| 3843 if (obj.IsType()) { | 3844 if (obj.IsType()) { |
| 3844 // Finalize all classes. | 3845 if (!Type::Cast(obj).IsFinalized()) { |
| 3845 Dart_Handle state = Api::CheckIsolateState(isolate); | 3846 return Api::NewError( |
| 3846 if (::Dart_IsError(state)) { | 3847 "%s expects argument 'target' to be a fully resolved type.", |
| 3847 return state; | 3848 CURRENT_FUNC); |
| 3848 } | 3849 } |
| 3849 | 3850 |
| 3850 const Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 3851 const Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); |
| 3851 const Function& function = Function::Handle( | 3852 const Function& function = Function::Handle( |
| 3852 isolate, | 3853 isolate, |
| 3853 Resolver::ResolveStatic(cls, | 3854 Resolver::ResolveStatic(cls, |
| 3854 function_name, | 3855 function_name, |
| 3855 number_of_arguments, | 3856 number_of_arguments, |
| 3856 Object::empty_array())); | 3857 Object::empty_array())); |
| 3857 if (function.IsNull()) { | 3858 if (function.IsNull()) { |
| 3858 const String& cls_name = String::Handle(isolate, cls.Name()); | 3859 const String& cls_name = String::Handle(isolate, cls.Name()); |
| 3859 return Api::NewError("%s: did not find static method '%s.%s'.", | 3860 return Api::NewError("%s: did not find static method '%s.%s'.", |
| 3860 CURRENT_FUNC, | 3861 CURRENT_FUNC, |
| 3861 cls_name.ToCString(), | 3862 cls_name.ToCString(), |
| 3862 function_name.ToCString()); | 3863 function_name.ToCString()); |
| 3863 } | 3864 } |
| 3864 // Setup args and check for malformed arguments in the arguments list. | 3865 // Setup args and check for malformed arguments in the arguments list. |
| 3865 result = SetupArguments(isolate, number_of_arguments, arguments, 0, &args); | 3866 result = SetupArguments(isolate, number_of_arguments, arguments, 0, &args); |
| 3866 if (!::Dart_IsError(result)) { | 3867 if (!::Dart_IsError(result)) { |
| 3867 result = Api::NewHandle(isolate, | 3868 result = Api::NewHandle(isolate, |
| 3868 DartEntry::InvokeFunction(function, args)); | 3869 DartEntry::InvokeFunction(function, args)); |
| 3869 } | 3870 } |
| 3870 return result; | 3871 return result; |
| 3871 } else if (obj.IsNull() || obj.IsInstance()) { | 3872 } else if (obj.IsNull() || obj.IsInstance()) { |
| 3872 // Since we have allocated an object it would mean that all classes | 3873 // Since we have allocated an object it would mean that the type of the |
| 3873 // are finalized and hence it is not necessary to call | 3874 // receiver is already resolved and finalized, hence it is not necessary |
| 3874 // Api::CheckIsolateState. | 3875 // to check here. |
| 3875 Instance& instance = Instance::Handle(isolate); | 3876 Instance& instance = Instance::Handle(isolate); |
| 3876 instance ^= obj.raw(); | 3877 instance ^= obj.raw(); |
| 3877 ArgumentsDescriptor args_desc( | 3878 ArgumentsDescriptor args_desc( |
| 3878 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); | 3879 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); |
| 3879 const Function& function = Function::Handle( | 3880 const Function& function = Function::Handle( |
| 3880 isolate, | 3881 isolate, |
| 3881 Resolver::ResolveDynamic(instance, function_name, args_desc)); | 3882 Resolver::ResolveDynamic(instance, function_name, args_desc)); |
| 3882 if (function.IsNull()) { | 3883 if (function.IsNull()) { |
| 3883 // Setup args and check for malformed arguments in the arguments list. | 3884 // Setup args and check for malformed arguments in the arguments list. |
| 3884 result = SetupArguments(isolate, | 3885 result = SetupArguments(isolate, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3903 if (!::Dart_IsError(result)) { | 3904 if (!::Dart_IsError(result)) { |
| 3904 args.SetAt(0, instance); | 3905 args.SetAt(0, instance); |
| 3905 result = Api::NewHandle(isolate, | 3906 result = Api::NewHandle(isolate, |
| 3906 DartEntry::InvokeFunction(function, args)); | 3907 DartEntry::InvokeFunction(function, args)); |
| 3907 } | 3908 } |
| 3908 return result; | 3909 return result; |
| 3909 } else if (obj.IsLibrary()) { | 3910 } else if (obj.IsLibrary()) { |
| 3910 // Check whether class finalization is needed. | 3911 // Check whether class finalization is needed. |
| 3911 const Library& lib = Library::Cast(obj); | 3912 const Library& lib = Library::Cast(obj); |
| 3912 | 3913 |
| 3913 // Finalize all classes if needed. | 3914 // Check that the library is loaded. |
| 3914 Dart_Handle state = Api::CheckIsolateState(isolate); | 3915 if (!lib.Loaded()) { |
| 3915 if (::Dart_IsError(state)) { | 3916 return Api::NewError( |
| 3916 return state; | 3917 "%s expects library argument 'target' to be loaded.", |
| 3918 CURRENT_FUNC); |
| 3917 } | 3919 } |
| 3918 | 3920 |
| 3919 const Function& function = | 3921 const Function& function = |
| 3920 Function::Handle(isolate, | 3922 Function::Handle(isolate, |
| 3921 lib.LookupFunctionAllowPrivate(function_name)); | 3923 lib.LookupFunctionAllowPrivate(function_name)); |
| 3922 if (function.IsNull()) { | 3924 if (function.IsNull()) { |
| 3923 return Api::NewError("%s: did not find top-level function '%s'.", | 3925 return Api::NewError("%s: did not find top-level function '%s'.", |
| 3924 CURRENT_FUNC, | 3926 CURRENT_FUNC, |
| 3925 function_name.ToCString()); | 3927 function_name.ToCString()); |
| 3926 } | 3928 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3987 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3989 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3988 Isolate* isolate = Isolate::Current(); | 3990 Isolate* isolate = Isolate::Current(); |
| 3989 DARTSCOPE(isolate); | 3991 DARTSCOPE(isolate); |
| 3990 CHECK_CALLBACK_STATE(isolate); | 3992 CHECK_CALLBACK_STATE(isolate); |
| 3991 | 3993 |
| 3992 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3994 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3993 if (field_name.IsNull()) { | 3995 if (field_name.IsNull()) { |
| 3994 RETURN_TYPE_ERROR(isolate, name, String); | 3996 RETURN_TYPE_ERROR(isolate, name, String); |
| 3995 } | 3997 } |
| 3996 | 3998 |
| 3997 // Finalize all classes. | |
| 3998 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 3999 if (::Dart_IsError(state)) { | |
| 4000 return state; | |
| 4001 } | |
| 4002 | |
| 4003 Field& field = Field::Handle(isolate); | 3999 Field& field = Field::Handle(isolate); |
| 4004 Function& getter = Function::Handle(isolate); | 4000 Function& getter = Function::Handle(isolate); |
| 4005 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4001 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 4006 if (obj.IsNull()) { | 4002 if (obj.IsNull()) { |
| 4007 return Api::NewError("%s expects argument 'container' to be non-null.", | 4003 return Api::NewError("%s expects argument 'container' to be non-null.", |
| 4008 CURRENT_FUNC); | 4004 CURRENT_FUNC); |
| 4009 } else if (obj.IsType()) { | 4005 } else if (obj.IsType()) { |
| 4006 if (!Type::Cast(obj).IsFinalized()) { |
| 4007 return Api::NewError( |
| 4008 "%s expects argument 'container' to be a fully resolved type.", |
| 4009 CURRENT_FUNC); |
| 4010 } |
| 4010 // To access a static field we may need to use the Field or the | 4011 // To access a static field we may need to use the Field or the |
| 4011 // getter Function. | 4012 // getter Function. |
| 4012 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4013 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); |
| 4013 | 4014 |
| 4014 field = cls.LookupStaticField(field_name); | 4015 field = cls.LookupStaticField(field_name); |
| 4015 if (field.IsNull() || field.IsUninitialized()) { | 4016 if (field.IsNull() || field.IsUninitialized()) { |
| 4016 const String& getter_name = | 4017 const String& getter_name = |
| 4017 String::Handle(isolate, Field::GetterName(field_name)); | 4018 String::Handle(isolate, Field::GetterName(field_name)); |
| 4018 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4019 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 4019 } | 4020 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4058 args, | 4059 args, |
| 4059 args_descriptor)); | 4060 args_descriptor)); |
| 4060 } | 4061 } |
| 4061 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); | 4062 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); |
| 4062 | 4063 |
| 4063 } else if (obj.IsLibrary()) { | 4064 } else if (obj.IsLibrary()) { |
| 4064 // To access a top-level we may need to use the Field or the | 4065 // To access a top-level we may need to use the Field or the |
| 4065 // getter Function. The getter function may either be in the | 4066 // getter Function. The getter function may either be in the |
| 4066 // library or in the field's owner class, depending. | 4067 // library or in the field's owner class, depending. |
| 4067 const Library& lib = Library::Cast(obj); | 4068 const Library& lib = Library::Cast(obj); |
| 4069 // Check that the library is loaded. |
| 4070 if (!lib.Loaded()) { |
| 4071 return Api::NewError( |
| 4072 "%s expects library argument 'container' to be loaded.", |
| 4073 CURRENT_FUNC); |
| 4074 } |
| 4068 field = lib.LookupFieldAllowPrivate(field_name); | 4075 field = lib.LookupFieldAllowPrivate(field_name); |
| 4069 if (field.IsNull()) { | 4076 if (field.IsNull()) { |
| 4070 // No field found and no ambiguity error. Check for a getter in the lib. | 4077 // No field found and no ambiguity error. Check for a getter in the lib. |
| 4071 const String& getter_name = | 4078 const String& getter_name = |
| 4072 String::Handle(isolate, Field::GetterName(field_name)); | 4079 String::Handle(isolate, Field::GetterName(field_name)); |
| 4073 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4080 getter = lib.LookupFunctionAllowPrivate(getter_name); |
| 4074 } else if (!field.IsNull() && field.IsUninitialized()) { | 4081 } else if (!field.IsNull() && field.IsUninitialized()) { |
| 4075 // A field was found. Check for a getter in the field's owner classs. | 4082 // A field was found. Check for a getter in the field's owner classs. |
| 4076 const Class& cls = Class::Handle(isolate, field.owner()); | 4083 const Class& cls = Class::Handle(isolate, field.owner()); |
| 4077 const String& getter_name = | 4084 const String& getter_name = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4113 } | 4120 } |
| 4114 | 4121 |
| 4115 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4122 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
| 4116 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 4123 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 4117 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 4124 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 4118 RETURN_TYPE_ERROR(isolate, value, Instance); | 4125 RETURN_TYPE_ERROR(isolate, value, Instance); |
| 4119 } | 4126 } |
| 4120 Instance& value_instance = Instance::Handle(isolate); | 4127 Instance& value_instance = Instance::Handle(isolate); |
| 4121 value_instance ^= value_obj.raw(); | 4128 value_instance ^= value_obj.raw(); |
| 4122 | 4129 |
| 4123 // Finalize all classes. | |
| 4124 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 4125 if (::Dart_IsError(state)) { | |
| 4126 return state; | |
| 4127 } | |
| 4128 Field& field = Field::Handle(isolate); | 4130 Field& field = Field::Handle(isolate); |
| 4129 Function& setter = Function::Handle(isolate); | 4131 Function& setter = Function::Handle(isolate); |
| 4130 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4132 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 4131 if (obj.IsNull()) { | 4133 if (obj.IsNull()) { |
| 4132 return Api::NewError("%s expects argument 'container' to be non-null.", | 4134 return Api::NewError("%s expects argument 'container' to be non-null.", |
| 4133 CURRENT_FUNC); | 4135 CURRENT_FUNC); |
| 4134 } else if (obj.IsType()) { | 4136 } else if (obj.IsType()) { |
| 4137 if (!Type::Cast(obj).IsFinalized()) { |
| 4138 return Api::NewError( |
| 4139 "%s expects argument 'container' to be a fully resolved type.", |
| 4140 CURRENT_FUNC); |
| 4141 } |
| 4142 |
| 4135 // To access a static field we may need to use the Field or the | 4143 // To access a static field we may need to use the Field or the |
| 4136 // setter Function. | 4144 // setter Function. |
| 4137 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4145 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); |
| 4138 | 4146 |
| 4139 field = cls.LookupStaticField(field_name); | 4147 field = cls.LookupStaticField(field_name); |
| 4140 if (field.IsNull()) { | 4148 if (field.IsNull()) { |
| 4141 String& setter_name = | 4149 String& setter_name = |
| 4142 String::Handle(isolate, Field::SetterName(field_name)); | 4150 String::Handle(isolate, Field::SetterName(field_name)); |
| 4143 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); | 4151 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); |
| 4144 } | 4152 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4203 args, | 4211 args, |
| 4204 args_descriptor)); | 4212 args_descriptor)); |
| 4205 } | 4213 } |
| 4206 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); | 4214 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); |
| 4207 | 4215 |
| 4208 } else if (obj.IsLibrary()) { | 4216 } else if (obj.IsLibrary()) { |
| 4209 // To access a top-level we may need to use the Field or the | 4217 // To access a top-level we may need to use the Field or the |
| 4210 // setter Function. The setter function may either be in the | 4218 // setter Function. The setter function may either be in the |
| 4211 // library or in the field's owner class, depending. | 4219 // library or in the field's owner class, depending. |
| 4212 const Library& lib = Library::Cast(obj); | 4220 const Library& lib = Library::Cast(obj); |
| 4221 // Check that the library is loaded. |
| 4222 if (!lib.Loaded()) { |
| 4223 return Api::NewError( |
| 4224 "%s expects library argument 'container' to be loaded.", |
| 4225 CURRENT_FUNC); |
| 4226 } |
| 4213 field = lib.LookupFieldAllowPrivate(field_name); | 4227 field = lib.LookupFieldAllowPrivate(field_name); |
| 4214 if (field.IsNull()) { | 4228 if (field.IsNull()) { |
| 4215 const String& setter_name = | 4229 const String& setter_name = |
| 4216 String::Handle(isolate, Field::SetterName(field_name)); | 4230 String::Handle(isolate, Field::SetterName(field_name)); |
| 4217 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 4231 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
| 4218 } | 4232 } |
| 4219 | 4233 |
| 4220 if (!setter.IsNull()) { | 4234 if (!setter.IsNull()) { |
| 4221 // Invoke the setter and return the result. | 4235 // Invoke the setter and return the result. |
| 4222 const int kNumArgs = 1; | 4236 const int kNumArgs = 1; |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4913 intptr_t number_of_type_arguments, | 4927 intptr_t number_of_type_arguments, |
| 4914 Dart_Handle* type_arguments) { | 4928 Dart_Handle* type_arguments) { |
| 4915 Isolate* isolate = Isolate::Current(); | 4929 Isolate* isolate = Isolate::Current(); |
| 4916 DARTSCOPE(isolate); | 4930 DARTSCOPE(isolate); |
| 4917 | 4931 |
| 4918 // Validate the input arguments. | 4932 // Validate the input arguments. |
| 4919 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4933 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4920 if (lib.IsNull()) { | 4934 if (lib.IsNull()) { |
| 4921 RETURN_TYPE_ERROR(isolate, library, Library); | 4935 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4922 } | 4936 } |
| 4937 if (!lib.Loaded()) { |
| 4938 return Api::NewError( |
| 4939 "%s expects library argument 'library' to be loaded.", |
| 4940 CURRENT_FUNC); |
| 4941 } |
| 4923 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); | 4942 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); |
| 4924 if (name_str.IsNull()) { | 4943 if (name_str.IsNull()) { |
| 4925 RETURN_TYPE_ERROR(isolate, class_name, String); | 4944 RETURN_TYPE_ERROR(isolate, class_name, String); |
| 4926 } | 4945 } |
| 4927 // Ensure all classes are finalized. | |
| 4928 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 4929 if (::Dart_IsError(state)) { | |
| 4930 return state; | |
| 4931 } | |
| 4932 const Class& cls = | 4946 const Class& cls = |
| 4933 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); | 4947 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); |
| 4934 if (cls.IsNull()) { | 4948 if (cls.IsNull()) { |
| 4935 const String& lib_name = String::Handle(isolate, lib.name()); | 4949 const String& lib_name = String::Handle(isolate, lib.name()); |
| 4936 return Api::NewError("Type '%s' not found in library '%s'.", | 4950 return Api::NewError("Type '%s' not found in library '%s'.", |
| 4937 name_str.ToCString(), lib_name.ToCString()); | 4951 name_str.ToCString(), lib_name.ToCString()); |
| 4938 } | 4952 } |
| 4939 if (cls.NumTypeArguments() == 0) { | 4953 if (cls.NumTypeArguments() == 0) { |
| 4940 if (number_of_type_arguments != 0) { | 4954 if (number_of_type_arguments != 0) { |
| 4941 return Api::NewError("Invalid number of type arguments specified, " | 4955 return Api::NewError("Invalid number of type arguments specified, " |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5048 Dart_Handle result; | 5062 Dart_Handle result; |
| 5049 CompileSource(isolate, library, script, &result); | 5063 CompileSource(isolate, library, script, &result); |
| 5050 // Propagate the error out right now. | 5064 // Propagate the error out right now. |
| 5051 if (::Dart_IsError(result)) { | 5065 if (::Dart_IsError(result)) { |
| 5052 return result; | 5066 return result; |
| 5053 } | 5067 } |
| 5054 | 5068 |
| 5055 // If this is the dart:_builtin library, register it with the VM. | 5069 // If this is the dart:_builtin library, register it with the VM. |
| 5056 if (url_str.Equals("dart:_builtin")) { | 5070 if (url_str.Equals("dart:_builtin")) { |
| 5057 isolate->object_store()->set_builtin_library(library); | 5071 isolate->object_store()->set_builtin_library(library); |
| 5058 Dart_Handle state = Api::CheckIsolateState(isolate); | 5072 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 5059 if (::Dart_IsError(state)) { | 5073 if (::Dart_IsError(state)) { |
| 5060 return state; | 5074 return state; |
| 5061 } | 5075 } |
| 5062 } | 5076 } |
| 5063 return result; | 5077 return result; |
| 5064 } | 5078 } |
| 5065 | 5079 |
| 5066 | 5080 |
| 5067 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 5081 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
| 5068 Dart_Handle import, | 5082 Dart_Handle import, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5174 Isolate* isolate = Isolate::Current(); | 5188 Isolate* isolate = Isolate::Current(); |
| 5175 DARTSCOPE(isolate); | 5189 DARTSCOPE(isolate); |
| 5176 CHECK_CALLBACK_STATE(isolate); | 5190 CHECK_CALLBACK_STATE(isolate); |
| 5177 | 5191 |
| 5178 isolate->DoneLoading(); | 5192 isolate->DoneLoading(); |
| 5179 | 5193 |
| 5180 // TODO(hausner): move the remaining code below (finalization and | 5194 // TODO(hausner): move the remaining code below (finalization and |
| 5181 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5195 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
| 5182 | 5196 |
| 5183 // Finalize all classes if needed. | 5197 // Finalize all classes if needed. |
| 5184 Dart_Handle state = Api::CheckIsolateState(isolate); | 5198 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
| 5185 if (::Dart_IsError(state)) { | 5199 if (::Dart_IsError(state)) { |
| 5186 return state; | 5200 return state; |
| 5187 } | 5201 } |
| 5188 | 5202 |
| 5189 if (complete_futures) { | 5203 if (complete_futures) { |
| 5190 const Library& corelib = Library::Handle(isolate, Library::CoreLibrary()); | 5204 const Library& corelib = Library::Handle(isolate, Library::CoreLibrary()); |
| 5191 const String& function_name = | 5205 const String& function_name = |
| 5192 String::Handle(isolate, String::New("_completeDeferredLoads")); | 5206 String::Handle(isolate, String::New("_completeDeferredLoads")); |
| 5193 const Function& function = | 5207 const Function& function = |
| 5194 Function::Handle(isolate, | 5208 Function::Handle(isolate, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5288 | 5302 |
| 5289 | 5303 |
| 5290 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5304 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 5291 const char* name, | 5305 const char* name, |
| 5292 Dart_ServiceRequestCallback callback, | 5306 Dart_ServiceRequestCallback callback, |
| 5293 void* user_data) { | 5307 void* user_data) { |
| 5294 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5308 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 5295 } | 5309 } |
| 5296 | 5310 |
| 5297 } // namespace dart | 5311 } // namespace dart |
| OLD | NEW |