Chromium Code Reviews| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 126 |
| 127 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle( | 127 FinalizablePersistentHandle* Api::UnwrapAsPrologueWeakPersistentHandle( |
| 128 Dart_WeakPersistentHandle object) { | 128 Dart_WeakPersistentHandle object) { |
| 129 ASSERT(Isolate::Current()->api_state()->IsValidPrologueWeakPersistentHandle( | 129 ASSERT(Isolate::Current()->api_state()->IsValidPrologueWeakPersistentHandle( |
| 130 object)); | 130 object)); |
| 131 return reinterpret_cast<FinalizablePersistentHandle*>(object); | 131 return reinterpret_cast<FinalizablePersistentHandle*>(object); |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { | 135 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { |
| 136 if (ClassFinalizer::FinalizePendingClasses() && | 136 if (ClassFinalizer::FinalizePendingClasses() && |
|
Ivan Posva
2013/06/20 20:18:38
Why don't you check just here?
Cutch
2013/06/20 20:27:02
Done.
| |
| 137 isolate->object_store()->PreallocateObjects()) { | 137 isolate->object_store()->PreallocateObjects()) { |
| 138 return Api::Success(); | 138 return Api::Success(); |
| 139 } | 139 } |
| 140 ASSERT(isolate->object_store()->sticky_error() != Object::null()); | 140 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
| 141 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 141 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 | 144 |
| 145 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 145 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
| 146 return reinterpret_cast<Dart_Isolate>(isolate); | 146 return reinterpret_cast<Dart_Isolate>(isolate); |
| (...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2959 return Api::NewHandle(isolate, | 2959 return Api::NewHandle(isolate, |
| 2960 DartEntry::InvokeNoSuchMethod(instance, | 2960 DartEntry::InvokeNoSuchMethod(instance, |
| 2961 function_name, | 2961 function_name, |
| 2962 args, | 2962 args, |
| 2963 args_descriptor)); | 2963 args_descriptor)); |
| 2964 } | 2964 } |
| 2965 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); | 2965 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, args)); |
| 2966 | 2966 |
| 2967 } else if (obj.IsLibrary()) { | 2967 } else if (obj.IsLibrary()) { |
| 2968 // Check whether class finalization is needed. | 2968 // Check whether class finalization is needed. |
| 2969 bool finalize_classes = true; | 2969 bool finalize_classes = isolate->AllowClassFinalization(); |
| 2970 const Library& lib = Library::Cast(obj); | 2970 const Library& lib = Library::Cast(obj); |
| 2971 | 2971 |
| 2972 // When calling functions in the dart:builtin library do not finalize as it | |
| 2973 // should have been prefinalized. | |
| 2974 Library& builtin = | |
| 2975 Library::Handle(isolate, isolate->object_store()->builtin_library()); | |
| 2976 if (builtin.raw() == lib.raw()) { | |
| 2977 finalize_classes = false; | |
| 2978 } | |
| 2979 | |
| 2980 // Finalize all classes if needed. | 2972 // Finalize all classes if needed. |
| 2981 if (finalize_classes) { | 2973 if (finalize_classes) { |
| 2982 Dart_Handle state = Api::CheckIsolateState(isolate); | 2974 Dart_Handle state = Api::CheckIsolateState(isolate); |
| 2983 if (::Dart_IsError(state)) { | 2975 if (::Dart_IsError(state)) { |
| 2984 return state; | 2976 return state; |
| 2985 } | 2977 } |
| 2986 } | 2978 } |
| 2987 | 2979 |
| 2988 Function& function = Function::Handle(isolate); | 2980 Function& function = Function::Handle(isolate); |
| 2989 function = lib.LookupFunctionAllowPrivate(function_name); | 2981 function = lib.LookupFunctionAllowPrivate(function_name); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3062 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3054 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3063 Isolate* isolate = Isolate::Current(); | 3055 Isolate* isolate = Isolate::Current(); |
| 3064 DARTSCOPE(isolate); | 3056 DARTSCOPE(isolate); |
| 3065 CHECK_CALLBACK_STATE(isolate); | 3057 CHECK_CALLBACK_STATE(isolate); |
| 3066 | 3058 |
| 3067 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3059 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3068 if (field_name.IsNull()) { | 3060 if (field_name.IsNull()) { |
| 3069 RETURN_TYPE_ERROR(isolate, name, String); | 3061 RETURN_TYPE_ERROR(isolate, name, String); |
| 3070 } | 3062 } |
| 3071 | 3063 |
| 3072 // Finalize all classes. | 3064 bool finalize_classes = isolate->AllowClassFinalization(); |
| 3073 Dart_Handle state = Api::CheckIsolateState(isolate); | 3065 |
| 3074 if (::Dart_IsError(state)) { | 3066 if (finalize_classes) { |
| 3075 return state; | 3067 // Finalize all classes. |
| 3068 Dart_Handle state = Api::CheckIsolateState(isolate); | |
| 3069 if (::Dart_IsError(state)) { | |
| 3070 return state; | |
| 3071 } | |
| 3076 } | 3072 } |
| 3073 | |
| 3077 Field& field = Field::Handle(isolate); | 3074 Field& field = Field::Handle(isolate); |
| 3078 Function& getter = Function::Handle(isolate); | 3075 Function& getter = Function::Handle(isolate); |
| 3079 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 3076 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 3080 if (obj.IsNull()) { | 3077 if (obj.IsNull()) { |
| 3081 return Api::NewError("%s expects argument 'container' to be non-null.", | 3078 return Api::NewError("%s expects argument 'container' to be non-null.", |
| 3082 CURRENT_FUNC); | 3079 CURRENT_FUNC); |
| 3083 } else if (obj.IsType() || obj.IsClass()) { | 3080 } else if (obj.IsType() || obj.IsClass()) { |
| 3084 // To access a static field we may need to use the Field or the | 3081 // To access a static field we may need to use the Field or the |
| 3085 // getter Function. | 3082 // getter Function. |
| 3086 // For backwards compatibility we allow class objects to be passed in | 3083 // For backwards compatibility we allow class objects to be passed in |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3992 } | 3989 } |
| 3993 { | 3990 { |
| 3994 NoGCScope no_gc; | 3991 NoGCScope no_gc; |
| 3995 RawObject* raw_obj = obj.raw(); | 3992 RawObject* raw_obj = obj.raw(); |
| 3996 isolate->heap()->SetPeer(raw_obj, peer); | 3993 isolate->heap()->SetPeer(raw_obj, peer); |
| 3997 } | 3994 } |
| 3998 return Api::Success(); | 3995 return Api::Success(); |
| 3999 } | 3996 } |
| 4000 | 3997 |
| 4001 } // namespace dart | 3998 } // namespace dart |
| OLD | NEW |