| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 3559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3570 } | 3570 } |
| 3571 | 3571 |
| 3572 | 3572 |
| 3573 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { | 3573 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { |
| 3574 ASSERT(!fld.IsNull()); | 3574 ASSERT(!fld.IsNull()); |
| 3575 | 3575 |
| 3576 // Return getter method for uninitialized fields, rather than the | 3576 // Return getter method for uninitialized fields, rather than the |
| 3577 // field object, since the value in the field object will not be | 3577 // field object, since the value in the field object will not be |
| 3578 // initialized until the first time the getter is invoked. | 3578 // initialized until the first time the getter is invoked. |
| 3579 const Instance& value = Instance::Handle(isolate, fld.value()); | 3579 const Instance& value = Instance::Handle(isolate, fld.value()); |
| 3580 ASSERT(value.raw() != Object::transition_sentinel()); | 3580 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 3581 return value.raw() == Object::sentinel(); | 3581 return value.raw() == Object::sentinel().raw(); |
| 3582 } | 3582 } |
| 3583 | 3583 |
| 3584 | 3584 |
| 3585 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3585 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3586 Isolate* isolate = Isolate::Current(); | 3586 Isolate* isolate = Isolate::Current(); |
| 3587 DARTSCOPE(isolate); | 3587 DARTSCOPE(isolate); |
| 3588 | 3588 |
| 3589 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3589 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3590 if (field_name.IsNull()) { | 3590 if (field_name.IsNull()) { |
| 3591 RETURN_TYPE_ERROR(isolate, name, String); | 3591 RETURN_TYPE_ERROR(isolate, name, String); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 const Class& cls = Class::Cast(obj); | 3636 const Class& cls = Class::Cast(obj); |
| 3637 field = cls.LookupStaticField(field_name); | 3637 field = cls.LookupStaticField(field_name); |
| 3638 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { | 3638 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { |
| 3639 const String& getter_name = | 3639 const String& getter_name = |
| 3640 String::Handle(isolate, Field::GetterName(field_name)); | 3640 String::Handle(isolate, Field::GetterName(field_name)); |
| 3641 getter = cls.LookupStaticFunction(getter_name); | 3641 getter = cls.LookupStaticFunction(getter_name); |
| 3642 } | 3642 } |
| 3643 | 3643 |
| 3644 if (!getter.IsNull()) { | 3644 if (!getter.IsNull()) { |
| 3645 // Invoke the getter and return the result. | 3645 // Invoke the getter and return the result. |
| 3646 const Array& args = Array::Handle(isolate, Object::empty_array()); | 3646 return Api::NewHandle( |
| 3647 return Api::NewHandle(isolate, DartEntry::InvokeStatic(getter, args)); | 3647 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); |
| 3648 } else if (!field.IsNull()) { | 3648 } else if (!field.IsNull()) { |
| 3649 return Api::NewHandle(isolate, field.value()); | 3649 return Api::NewHandle(isolate, field.value()); |
| 3650 } else { | 3650 } else { |
| 3651 return Api::NewError("%s: did not find static field '%s'.", | 3651 return Api::NewError("%s: did not find static field '%s'.", |
| 3652 CURRENT_FUNC, field_name.ToCString()); | 3652 CURRENT_FUNC, field_name.ToCString()); |
| 3653 } | 3653 } |
| 3654 | 3654 |
| 3655 } else if (obj.IsLibrary()) { | 3655 } else if (obj.IsLibrary()) { |
| 3656 // TODO(turnidge): Do we need to call CheckIsolateState here? | 3656 // TODO(turnidge): Do we need to call CheckIsolateState here? |
| 3657 | 3657 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3668 } else if (FieldIsUninitialized(isolate, field)) { | 3668 } else if (FieldIsUninitialized(isolate, field)) { |
| 3669 // A field was found. Check for a getter in the field's owner classs. | 3669 // A field was found. Check for a getter in the field's owner classs. |
| 3670 const Class& cls = Class::Handle(isolate, field.owner()); | 3670 const Class& cls = Class::Handle(isolate, field.owner()); |
| 3671 const String& getter_name = | 3671 const String& getter_name = |
| 3672 String::Handle(isolate, Field::GetterName(field_name)); | 3672 String::Handle(isolate, Field::GetterName(field_name)); |
| 3673 getter = cls.LookupStaticFunction(getter_name); | 3673 getter = cls.LookupStaticFunction(getter_name); |
| 3674 } | 3674 } |
| 3675 | 3675 |
| 3676 if (!getter.IsNull()) { | 3676 if (!getter.IsNull()) { |
| 3677 // Invoke the getter and return the result. | 3677 // Invoke the getter and return the result. |
| 3678 const Array& args = Array::Handle(isolate, Object::empty_array()); | 3678 return Api::NewHandle( |
| 3679 return Api::NewHandle(isolate, DartEntry::InvokeStatic(getter, args)); | 3679 isolate, DartEntry::InvokeStatic(getter, Object::empty_array())); |
| 3680 } else if (!field.IsNull()) { | 3680 } else if (!field.IsNull()) { |
| 3681 return Api::NewHandle(isolate, field.value()); | 3681 return Api::NewHandle(isolate, field.value()); |
| 3682 } else { | 3682 } else { |
| 3683 return Api::NewError("%s: did not find top-level variable '%s'.", | 3683 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 3684 CURRENT_FUNC, field_name.ToCString()); | 3684 CURRENT_FUNC, field_name.ToCString()); |
| 3685 } | 3685 } |
| 3686 | 3686 |
| 3687 } else if (obj.IsError()) { | 3687 } else if (obj.IsError()) { |
| 3688 return container; | 3688 return container; |
| 3689 } else { | 3689 } else { |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4496 } | 4496 } |
| 4497 { | 4497 { |
| 4498 NoGCScope no_gc; | 4498 NoGCScope no_gc; |
| 4499 RawObject* raw_obj = obj.raw(); | 4499 RawObject* raw_obj = obj.raw(); |
| 4500 isolate->heap()->SetPeer(raw_obj, peer); | 4500 isolate->heap()->SetPeer(raw_obj, peer); |
| 4501 } | 4501 } |
| 4502 return Api::Success(isolate); | 4502 return Api::Success(isolate); |
| 4503 } | 4503 } |
| 4504 | 4504 |
| 4505 } // namespace dart | 4505 } // namespace dart |
| OLD | NEW |