| 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 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 3916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3927 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3927 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3928 Isolate* isolate = Isolate::Current(); | 3928 Isolate* isolate = Isolate::Current(); |
| 3929 DARTSCOPE(isolate); | 3929 DARTSCOPE(isolate); |
| 3930 CHECK_CALLBACK_STATE(isolate); | 3930 CHECK_CALLBACK_STATE(isolate); |
| 3931 | 3931 |
| 3932 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3932 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3933 if (field_name.IsNull()) { | 3933 if (field_name.IsNull()) { |
| 3934 RETURN_TYPE_ERROR(isolate, name, String); | 3934 RETURN_TYPE_ERROR(isolate, name, String); |
| 3935 } | 3935 } |
| 3936 | 3936 |
| 3937 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 3937 // Finalize all classes. |
| 3938 | 3938 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 3939 if (::Dart_IsError(state)) { |
| 3940 return state; |
| 3941 } |
| 3939 Field& field = Field::Handle(isolate); | 3942 Field& field = Field::Handle(isolate); |
| 3940 Function& getter = Function::Handle(isolate); | 3943 Function& getter = Function::Handle(isolate); |
| 3944 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 3941 if (obj.IsNull()) { | 3945 if (obj.IsNull()) { |
| 3942 return Api::NewError("%s expects argument 'container' to be non-null.", | 3946 return Api::NewError("%s expects argument 'container' to be non-null.", |
| 3943 CURRENT_FUNC); | 3947 CURRENT_FUNC); |
| 3944 } else if (obj.IsInstance()) { | 3948 } else if (obj.IsInstance()) { |
| 3945 // Every instance field has a getter Function. Try to find the | 3949 // Every instance field has a getter Function. Try to find the |
| 3946 // getter in any superclass and use that function to access the | 3950 // getter in any superclass and use that function to access the |
| 3947 // field. | 3951 // field. |
| 3948 const Instance& instance = Instance::Cast(obj); | 3952 const Instance& instance = Instance::Cast(obj); |
| 3949 Class& cls = Class::Handle(isolate, instance.clazz()); | 3953 Class& cls = Class::Handle(isolate, instance.clazz()); |
| 3950 String& getter_name = | 3954 String& getter_name = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3966 Array::Handle(ArgumentsDescriptor::New(args.Length())); | 3970 Array::Handle(ArgumentsDescriptor::New(args.Length())); |
| 3967 return Api::NewHandle(isolate, | 3971 return Api::NewHandle(isolate, |
| 3968 DartEntry::InvokeNoSuchMethod(instance, | 3972 DartEntry::InvokeNoSuchMethod(instance, |
| 3969 getter_name, | 3973 getter_name, |
| 3970 args, | 3974 args, |
| 3971 args_descriptor)); | 3975 args_descriptor)); |
| 3972 } | 3976 } |
| 3973 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); | 3977 return Api::NewHandle(isolate, DartEntry::InvokeFunction(getter, args)); |
| 3974 | 3978 |
| 3975 } else if (obj.IsClass()) { | 3979 } else if (obj.IsClass()) { |
| 3976 // Finalize all classes. | |
| 3977 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 3978 if (::Dart_IsError(state)) { | |
| 3979 return state; | |
| 3980 } | |
| 3981 // To access a static field we may need to use the Field or the | 3980 // To access a static field we may need to use the Field or the |
| 3982 // getter Function. | 3981 // getter Function. |
| 3983 const Class& cls = Class::Cast(obj); | 3982 const Class& cls = Class::Cast(obj); |
| 3984 field = cls.LookupStaticField(field_name); | 3983 field = cls.LookupStaticField(field_name); |
| 3985 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { | 3984 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { |
| 3986 const String& getter_name = | 3985 const String& getter_name = |
| 3987 String::Handle(isolate, Field::GetterName(field_name)); | 3986 String::Handle(isolate, Field::GetterName(field_name)); |
| 3988 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 3987 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
| 3989 } | 3988 } |
| 3990 | 3989 |
| 3991 if (!getter.IsNull()) { | 3990 if (!getter.IsNull()) { |
| 3992 // Invoke the getter and return the result. | 3991 // Invoke the getter and return the result. |
| 3993 return Api::NewHandle( | 3992 return Api::NewHandle( |
| 3994 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); | 3993 isolate, DartEntry::InvokeFunction(getter, Object::empty_array())); |
| 3995 } else if (!field.IsNull()) { | 3994 } else if (!field.IsNull()) { |
| 3996 return Api::NewHandle(isolate, field.value()); | 3995 return Api::NewHandle(isolate, field.value()); |
| 3997 } else { | 3996 } else { |
| 3998 return Api::NewError("%s: did not find static field '%s'.", | 3997 return Api::NewError("%s: did not find static field '%s'.", |
| 3999 CURRENT_FUNC, field_name.ToCString()); | 3998 CURRENT_FUNC, field_name.ToCString()); |
| 4000 } | 3999 } |
| 4001 | 4000 |
| 4002 } else if (obj.IsLibrary()) { | 4001 } else if (obj.IsLibrary()) { |
| 4003 // TODO(turnidge): Do we need to call CheckIsolateState here? | |
| 4004 | |
| 4005 // To access a top-level we may need to use the Field or the | 4002 // To access a top-level we may need to use the Field or the |
| 4006 // getter Function. The getter function may either be in the | 4003 // getter Function. The getter function may either be in the |
| 4007 // library or in the field's owner class, depending. | 4004 // library or in the field's owner class, depending. |
| 4008 const Library& lib = Library::Cast(obj); | 4005 const Library& lib = Library::Cast(obj); |
| 4009 field = lib.LookupFieldAllowPrivate(field_name); | 4006 field = lib.LookupFieldAllowPrivate(field_name); |
| 4010 if (field.IsNull()) { | 4007 if (field.IsNull()) { |
| 4011 // No field found. Check for a getter in the lib. | 4008 // No field found. Check for a getter in the lib. |
| 4012 const String& getter_name = | 4009 const String& getter_name = |
| 4013 String::Handle(isolate, Field::GetterName(field_name)); | 4010 String::Handle(isolate, Field::GetterName(field_name)); |
| 4014 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4011 getter = lib.LookupFunctionAllowPrivate(getter_name); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4054 } | 4051 } |
| 4055 | 4052 |
| 4056 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 4053 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
| 4057 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 4054 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 4058 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 4055 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 4059 RETURN_TYPE_ERROR(isolate, value, Instance); | 4056 RETURN_TYPE_ERROR(isolate, value, Instance); |
| 4060 } | 4057 } |
| 4061 Instance& value_instance = Instance::Handle(isolate); | 4058 Instance& value_instance = Instance::Handle(isolate); |
| 4062 value_instance ^= value_obj.raw(); | 4059 value_instance ^= value_obj.raw(); |
| 4063 | 4060 |
| 4061 // Finalize all classes. |
| 4062 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 4063 if (::Dart_IsError(state)) { |
| 4064 return state; |
| 4065 } |
| 4064 Field& field = Field::Handle(isolate); | 4066 Field& field = Field::Handle(isolate); |
| 4065 Function& setter = Function::Handle(isolate); | 4067 Function& setter = Function::Handle(isolate); |
| 4066 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 4068 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 4067 if (obj.IsNull()) { | 4069 if (obj.IsNull()) { |
| 4068 return Api::NewError("%s expects argument 'container' to be non-null.", | 4070 return Api::NewError("%s expects argument 'container' to be non-null.", |
| 4069 CURRENT_FUNC); | 4071 CURRENT_FUNC); |
| 4070 } else if (obj.IsInstance()) { | 4072 } else if (obj.IsInstance()) { |
| 4071 // Every instance field has a setter Function. Try to find the | 4073 // Every instance field has a setter Function. Try to find the |
| 4072 // setter in any superclass and use that function to access the | 4074 // setter in any superclass and use that function to access the |
| 4073 // field. | 4075 // field. |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4870 } | 4872 } |
| 4871 { | 4873 { |
| 4872 NoGCScope no_gc; | 4874 NoGCScope no_gc; |
| 4873 RawObject* raw_obj = obj.raw(); | 4875 RawObject* raw_obj = obj.raw(); |
| 4874 isolate->heap()->SetPeer(raw_obj, peer); | 4876 isolate->heap()->SetPeer(raw_obj, peer); |
| 4875 } | 4877 } |
| 4876 return Api::Success(isolate); | 4878 return Api::Success(isolate); |
| 4877 } | 4879 } |
| 4878 | 4880 |
| 4879 } // namespace dart | 4881 } // namespace dart |
| OLD | NEW |