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 all classes |
hausner
2014/07/22 18:23:32
all classes, or the type of the receiver?
siva
2014/07/22 19:55:11
Fixed the comment.
On 2014/07/22 18:23:32, hausne
| |
3873 // are finalized and hence it is not necessary to call | 3874 // are finalized and hence it is not necessary to check here. |
3874 // Api::CheckIsolateState. | |
3875 Instance& instance = Instance::Handle(isolate); | 3875 Instance& instance = Instance::Handle(isolate); |
3876 instance ^= obj.raw(); | 3876 instance ^= obj.raw(); |
3877 ArgumentsDescriptor args_desc( | 3877 ArgumentsDescriptor args_desc( |
3878 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); | 3878 Array::Handle(ArgumentsDescriptor::New(number_of_arguments + 1))); |
3879 const Function& function = Function::Handle( | 3879 const Function& function = Function::Handle( |
3880 isolate, | 3880 isolate, |
3881 Resolver::ResolveDynamic(instance, function_name, args_desc)); | 3881 Resolver::ResolveDynamic(instance, function_name, args_desc)); |
3882 if (function.IsNull()) { | 3882 if (function.IsNull()) { |
3883 // Setup args and check for malformed arguments in the arguments list. | 3883 // Setup args and check for malformed arguments in the arguments list. |
3884 result = SetupArguments(isolate, | 3884 result = SetupArguments(isolate, |
(...skipping 18 matching lines...) Expand all Loading... | |
3903 if (!::Dart_IsError(result)) { | 3903 if (!::Dart_IsError(result)) { |
3904 args.SetAt(0, instance); | 3904 args.SetAt(0, instance); |
3905 result = Api::NewHandle(isolate, | 3905 result = Api::NewHandle(isolate, |
3906 DartEntry::InvokeFunction(function, args)); | 3906 DartEntry::InvokeFunction(function, args)); |
3907 } | 3907 } |
3908 return result; | 3908 return result; |
3909 } else if (obj.IsLibrary()) { | 3909 } else if (obj.IsLibrary()) { |
3910 // Check whether class finalization is needed. | 3910 // Check whether class finalization is needed. |
3911 const Library& lib = Library::Cast(obj); | 3911 const Library& lib = Library::Cast(obj); |
3912 | 3912 |
3913 // Finalize all classes if needed. | 3913 // Check that the library is loaded. |
3914 Dart_Handle state = Api::CheckIsolateState(isolate); | 3914 if (!lib.Loaded()) { |
3915 if (::Dart_IsError(state)) { | 3915 return Api::NewError( |
3916 return state; | 3916 "%s expects library argument 'target' to be loaded.", |
3917 CURRENT_FUNC); | |
3917 } | 3918 } |
3918 | 3919 |
3919 const Function& function = | 3920 const Function& function = |
3920 Function::Handle(isolate, | 3921 Function::Handle(isolate, |
3921 lib.LookupFunctionAllowPrivate(function_name)); | 3922 lib.LookupFunctionAllowPrivate(function_name)); |
3922 if (function.IsNull()) { | 3923 if (function.IsNull()) { |
3923 return Api::NewError("%s: did not find top-level function '%s'.", | 3924 return Api::NewError("%s: did not find top-level function '%s'.", |
3924 CURRENT_FUNC, | 3925 CURRENT_FUNC, |
3925 function_name.ToCString()); | 3926 function_name.ToCString()); |
3926 } | 3927 } |
(...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) { | 3988 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
3988 Isolate* isolate = Isolate::Current(); | 3989 Isolate* isolate = Isolate::Current(); |
3989 DARTSCOPE(isolate); | 3990 DARTSCOPE(isolate); |
3990 CHECK_CALLBACK_STATE(isolate); | 3991 CHECK_CALLBACK_STATE(isolate); |
3991 | 3992 |
3992 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3993 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
3993 if (field_name.IsNull()) { | 3994 if (field_name.IsNull()) { |
3994 RETURN_TYPE_ERROR(isolate, name, String); | 3995 RETURN_TYPE_ERROR(isolate, name, String); |
3995 } | 3996 } |
3996 | 3997 |
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); | 3998 Field& field = Field::Handle(isolate); |
4004 Function& getter = Function::Handle(isolate); | 3999 Function& getter = Function::Handle(isolate); |
4005 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4000 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
4006 if (obj.IsNull()) { | 4001 if (obj.IsNull()) { |
4007 return Api::NewError("%s expects argument 'container' to be non-null.", | 4002 return Api::NewError("%s expects argument 'container' to be non-null.", |
4008 CURRENT_FUNC); | 4003 CURRENT_FUNC); |
4009 } else if (obj.IsType()) { | 4004 } else if (obj.IsType()) { |
4005 if (!Type::Cast(obj).IsFinalized()) { | |
4006 return Api::NewError( | |
4007 "%s expects argument 'container' to be a fully resolved type.", | |
4008 CURRENT_FUNC); | |
4009 } | |
4010 // To access a static field we may need to use the Field or the | 4010 // To access a static field we may need to use the Field or the |
4011 // getter Function. | 4011 // getter Function. |
4012 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4012 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); |
4013 | 4013 |
4014 field = cls.LookupStaticField(field_name); | 4014 field = cls.LookupStaticField(field_name); |
4015 if (field.IsNull() || field.IsUninitialized()) { | 4015 if (field.IsNull() || field.IsUninitialized()) { |
4016 const String& getter_name = | 4016 const String& getter_name = |
4017 String::Handle(isolate, Field::GetterName(field_name)); | 4017 String::Handle(isolate, Field::GetterName(field_name)); |
4018 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4018 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
4019 } | 4019 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4058 args, | 4058 args, |
4059 args_descriptor)); | 4059 args_descriptor)); |
4060 } | 4060 } |
4061 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); | 4061 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); |
4062 | 4062 |
4063 } else if (obj.IsLibrary()) { | 4063 } else if (obj.IsLibrary()) { |
4064 // To access a top-level we may need to use the Field or the | 4064 // 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 | 4065 // getter Function. The getter function may either be in the |
4066 // library or in the field's owner class, depending. | 4066 // library or in the field's owner class, depending. |
4067 const Library& lib = Library::Cast(obj); | 4067 const Library& lib = Library::Cast(obj); |
4068 // Check that the library is loaded. | |
4069 if (!lib.Loaded()) { | |
4070 return Api::NewError( | |
4071 "%s expects library argument 'container' to be loaded.", | |
4072 CURRENT_FUNC); | |
4073 } | |
4068 field = lib.LookupFieldAllowPrivate(field_name); | 4074 field = lib.LookupFieldAllowPrivate(field_name); |
4069 if (field.IsNull()) { | 4075 if (field.IsNull()) { |
4070 // No field found and no ambiguity error. Check for a getter in the lib. | 4076 // No field found and no ambiguity error. Check for a getter in the lib. |
4071 const String& getter_name = | 4077 const String& getter_name = |
4072 String::Handle(isolate, Field::GetterName(field_name)); | 4078 String::Handle(isolate, Field::GetterName(field_name)); |
4073 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4079 getter = lib.LookupFunctionAllowPrivate(getter_name); |
4074 } else if (!field.IsNull() && field.IsUninitialized()) { | 4080 } else if (!field.IsNull() && field.IsUninitialized()) { |
4075 // A field was found. Check for a getter in the field's owner classs. | 4081 // A field was found. Check for a getter in the field's owner classs. |
4076 const Class& cls = Class::Handle(isolate, field.owner()); | 4082 const Class& cls = Class::Handle(isolate, field.owner()); |
4077 const String& getter_name = | 4083 const String& getter_name = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4113 } | 4119 } |
4114 | 4120 |
4115 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4121 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
4116 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 4122 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); |
4117 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 4123 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
4118 RETURN_TYPE_ERROR(isolate, value, Instance); | 4124 RETURN_TYPE_ERROR(isolate, value, Instance); |
4119 } | 4125 } |
4120 Instance& value_instance = Instance::Handle(isolate); | 4126 Instance& value_instance = Instance::Handle(isolate); |
4121 value_instance ^= value_obj.raw(); | 4127 value_instance ^= value_obj.raw(); |
4122 | 4128 |
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); | 4129 Field& field = Field::Handle(isolate); |
4129 Function& setter = Function::Handle(isolate); | 4130 Function& setter = Function::Handle(isolate); |
4130 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4131 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
4131 if (obj.IsNull()) { | 4132 if (obj.IsNull()) { |
4132 return Api::NewError("%s expects argument 'container' to be non-null.", | 4133 return Api::NewError("%s expects argument 'container' to be non-null.", |
4133 CURRENT_FUNC); | 4134 CURRENT_FUNC); |
4134 } else if (obj.IsType()) { | 4135 } else if (obj.IsType()) { |
4136 if (!Type::Cast(obj).IsFinalized()) { | |
4137 return Api::NewError( | |
4138 "%s expects argument 'container' to be a fully resolved type.", | |
4139 CURRENT_FUNC); | |
4140 } | |
4141 | |
4135 // To access a static field we may need to use the Field or the | 4142 // To access a static field we may need to use the Field or the |
4136 // setter Function. | 4143 // setter Function. |
4137 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); | 4144 Class& cls = Class::Handle(isolate, Type::Cast(obj).type_class()); |
4138 | 4145 |
4139 field = cls.LookupStaticField(field_name); | 4146 field = cls.LookupStaticField(field_name); |
4140 if (field.IsNull()) { | 4147 if (field.IsNull()) { |
4141 String& setter_name = | 4148 String& setter_name = |
4142 String::Handle(isolate, Field::SetterName(field_name)); | 4149 String::Handle(isolate, Field::SetterName(field_name)); |
4143 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); | 4150 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); |
4144 } | 4151 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4203 args, | 4210 args, |
4204 args_descriptor)); | 4211 args_descriptor)); |
4205 } | 4212 } |
4206 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); | 4213 return Api::NewHandle(isolate, DartEntry::InvokeFunction(setter, args)); |
4207 | 4214 |
4208 } else if (obj.IsLibrary()) { | 4215 } else if (obj.IsLibrary()) { |
4209 // To access a top-level we may need to use the Field or the | 4216 // 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 | 4217 // setter Function. The setter function may either be in the |
4211 // library or in the field's owner class, depending. | 4218 // library or in the field's owner class, depending. |
4212 const Library& lib = Library::Cast(obj); | 4219 const Library& lib = Library::Cast(obj); |
4220 // Check that the library is loaded. | |
4221 if (!lib.Loaded()) { | |
4222 return Api::NewError( | |
4223 "%s expects library argument 'container' to be loaded.", | |
4224 CURRENT_FUNC); | |
4225 } | |
4213 field = lib.LookupFieldAllowPrivate(field_name); | 4226 field = lib.LookupFieldAllowPrivate(field_name); |
4214 if (field.IsNull()) { | 4227 if (field.IsNull()) { |
4215 const String& setter_name = | 4228 const String& setter_name = |
4216 String::Handle(isolate, Field::SetterName(field_name)); | 4229 String::Handle(isolate, Field::SetterName(field_name)); |
4217 setter ^= lib.LookupFunctionAllowPrivate(setter_name); | 4230 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
4218 } | 4231 } |
4219 | 4232 |
4220 if (!setter.IsNull()) { | 4233 if (!setter.IsNull()) { |
4221 // Invoke the setter and return the result. | 4234 // Invoke the setter and return the result. |
4222 const int kNumArgs = 1; | 4235 const int kNumArgs = 1; |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4913 intptr_t number_of_type_arguments, | 4926 intptr_t number_of_type_arguments, |
4914 Dart_Handle* type_arguments) { | 4927 Dart_Handle* type_arguments) { |
4915 Isolate* isolate = Isolate::Current(); | 4928 Isolate* isolate = Isolate::Current(); |
4916 DARTSCOPE(isolate); | 4929 DARTSCOPE(isolate); |
4917 | 4930 |
4918 // Validate the input arguments. | 4931 // Validate the input arguments. |
4919 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4932 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
4920 if (lib.IsNull()) { | 4933 if (lib.IsNull()) { |
4921 RETURN_TYPE_ERROR(isolate, library, Library); | 4934 RETURN_TYPE_ERROR(isolate, library, Library); |
4922 } | 4935 } |
4936 if (!lib.Loaded()) { | |
4937 RETURN_TYPE_ERROR(isolate, library, Library); | |
hausner
2014/07/22 18:23:32
Shouldn't this be the same "library must be loaded
siva
2014/07/22 19:55:11
True, good catch that was a cut and paste error.
| |
4938 } | |
4923 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); | 4939 const String& name_str = Api::UnwrapStringHandle(isolate, class_name); |
4924 if (name_str.IsNull()) { | 4940 if (name_str.IsNull()) { |
4925 RETURN_TYPE_ERROR(isolate, class_name, String); | 4941 RETURN_TYPE_ERROR(isolate, class_name, String); |
4926 } | 4942 } |
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 = | 4943 const Class& cls = |
4933 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); | 4944 Class::Handle(isolate, lib.LookupClassAllowPrivate(name_str)); |
4934 if (cls.IsNull()) { | 4945 if (cls.IsNull()) { |
4935 const String& lib_name = String::Handle(isolate, lib.name()); | 4946 const String& lib_name = String::Handle(isolate, lib.name()); |
4936 return Api::NewError("Type '%s' not found in library '%s'.", | 4947 return Api::NewError("Type '%s' not found in library '%s'.", |
4937 name_str.ToCString(), lib_name.ToCString()); | 4948 name_str.ToCString(), lib_name.ToCString()); |
4938 } | 4949 } |
4939 if (cls.NumTypeArguments() == 0) { | 4950 if (cls.NumTypeArguments() == 0) { |
4940 if (number_of_type_arguments != 0) { | 4951 if (number_of_type_arguments != 0) { |
4941 return Api::NewError("Invalid number of type arguments specified, " | 4952 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; | 5059 Dart_Handle result; |
5049 CompileSource(isolate, library, script, &result); | 5060 CompileSource(isolate, library, script, &result); |
5050 // Propagate the error out right now. | 5061 // Propagate the error out right now. |
5051 if (::Dart_IsError(result)) { | 5062 if (::Dart_IsError(result)) { |
5052 return result; | 5063 return result; |
5053 } | 5064 } |
5054 | 5065 |
5055 // If this is the dart:_builtin library, register it with the VM. | 5066 // If this is the dart:_builtin library, register it with the VM. |
5056 if (url_str.Equals("dart:_builtin")) { | 5067 if (url_str.Equals("dart:_builtin")) { |
5057 isolate->object_store()->set_builtin_library(library); | 5068 isolate->object_store()->set_builtin_library(library); |
5058 Dart_Handle state = Api::CheckIsolateState(isolate); | 5069 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
5059 if (::Dart_IsError(state)) { | 5070 if (::Dart_IsError(state)) { |
5060 return state; | 5071 return state; |
5061 } | 5072 } |
5062 } | 5073 } |
5063 return result; | 5074 return result; |
5064 } | 5075 } |
5065 | 5076 |
5066 | 5077 |
5067 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 5078 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
5068 Dart_Handle import, | 5079 Dart_Handle import, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5174 Isolate* isolate = Isolate::Current(); | 5185 Isolate* isolate = Isolate::Current(); |
5175 DARTSCOPE(isolate); | 5186 DARTSCOPE(isolate); |
5176 CHECK_CALLBACK_STATE(isolate); | 5187 CHECK_CALLBACK_STATE(isolate); |
5177 | 5188 |
5178 isolate->DoneLoading(); | 5189 isolate->DoneLoading(); |
5179 | 5190 |
5180 // TODO(hausner): move the remaining code below (finalization and | 5191 // TODO(hausner): move the remaining code below (finalization and |
5181 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). | 5192 // invoing of _completeDeferredLoads) into Isolate::DoneLoading(). |
5182 | 5193 |
5183 // Finalize all classes if needed. | 5194 // Finalize all classes if needed. |
5184 Dart_Handle state = Api::CheckIsolateState(isolate); | 5195 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); |
5185 if (::Dart_IsError(state)) { | 5196 if (::Dart_IsError(state)) { |
5186 return state; | 5197 return state; |
5187 } | 5198 } |
5188 | 5199 |
5189 if (complete_futures) { | 5200 if (complete_futures) { |
5190 const Library& corelib = Library::Handle(isolate, Library::CoreLibrary()); | 5201 const Library& corelib = Library::Handle(isolate, Library::CoreLibrary()); |
5191 const String& function_name = | 5202 const String& function_name = |
5192 String::Handle(isolate, String::New("_completeDeferredLoads")); | 5203 String::Handle(isolate, String::New("_completeDeferredLoads")); |
5193 const Function& function = | 5204 const Function& function = |
5194 Function::Handle(isolate, | 5205 Function::Handle(isolate, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5288 | 5299 |
5289 | 5300 |
5290 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5301 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5291 const char* name, | 5302 const char* name, |
5292 Dart_ServiceRequestCallback callback, | 5303 Dart_ServiceRequestCallback callback, |
5293 void* user_data) { | 5304 void* user_data) { |
5294 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5305 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5295 } | 5306 } |
5296 | 5307 |
5297 } // namespace dart | 5308 } // namespace dart |
OLD | NEW |