| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef VM_DART_API_IMPL_H_ | 5 #ifndef VM_DART_API_IMPL_H_ |
| 6 #define VM_DART_API_IMPL_H_ | 6 #define VM_DART_API_IMPL_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/native_arguments.h" | 9 #include "vm/native_arguments.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #define CHECK_NO_ISOLATE(isolate) \ | 49 #define CHECK_NO_ISOLATE(isolate) \ |
| 50 do { \ | 50 do { \ |
| 51 TRACE_API_CALL(CURRENT_FUNC); \ | 51 TRACE_API_CALL(CURRENT_FUNC); \ |
| 52 if ((isolate) != NULL) { \ | 52 if ((isolate) != NULL) { \ |
| 53 FATAL1("%s expects there to be no current isolate. Did you " \ | 53 FATAL1("%s expects there to be no current isolate. Did you " \ |
| 54 "forget to call Dart_ExitIsolate?", CURRENT_FUNC); \ | 54 "forget to call Dart_ExitIsolate?", CURRENT_FUNC); \ |
| 55 } \ | 55 } \ |
| 56 } while (0) | 56 } while (0) |
| 57 | 57 |
| 58 // Checks that the current isolate is not NULL and that it has an API scope. | 58 // Checks that the current isolate is not NULL and that it has an API scope. |
| 59 #define CHECK_ISOLATE_SCOPE(isolate) \ | 59 #define CHECK_API_SCOPE(thread) \ |
| 60 do { \ | 60 do { \ |
| 61 Isolate* tmp = (isolate); \ | 61 Thread* tmpT = (thread); \ |
| 62 CHECK_ISOLATE(tmp); \ | 62 Isolate* tmpI = tmpT->isolate(); \ |
| 63 ApiState* state = tmp->api_state(); \ | 63 CHECK_ISOLATE(tmpI); \ |
| 64 ASSERT(state); \ | 64 if (tmpT->api_top_scope() == NULL) { \ |
| 65 if (state->top_scope() == NULL) { \ | |
| 66 FATAL1("%s expects to find a current scope. Did you forget to call " \ | 65 FATAL1("%s expects to find a current scope. Did you forget to call " \ |
| 67 "Dart_EnterScope?", CURRENT_FUNC); \ | 66 "Dart_EnterScope?", CURRENT_FUNC); \ |
| 68 } \ | 67 } \ |
| 69 } while (0) | 68 } while (0) |
| 70 | 69 |
| 71 #define DARTSCOPE(thread) \ | 70 #define DARTSCOPE(thread) \ |
| 72 Thread* T = (thread); \ | 71 Thread* T = (thread); \ |
| 73 Isolate* I = T->isolate(); \ | 72 CHECK_API_SCOPE(T); \ |
| 74 CHECK_ISOLATE_SCOPE(I); \ | |
| 75 HANDLESCOPE(T); | 73 HANDLESCOPE(T); |
| 76 | 74 |
| 77 | 75 |
| 78 #define RETURN_TYPE_ERROR(zone, dart_handle, type) \ | 76 #define RETURN_TYPE_ERROR(zone, dart_handle, type) \ |
| 79 do { \ | 77 do { \ |
| 80 const Object& tmp = \ | 78 const Object& tmp = \ |
| 81 Object::Handle(zone, Api::UnwrapHandle((dart_handle))); \ | 79 Object::Handle(zone, Api::UnwrapHandle((dart_handle))); \ |
| 82 if (tmp.IsNull()) { \ | 80 if (tmp.IsNull()) { \ |
| 83 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 81 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
| 84 CURRENT_FUNC, #dart_handle); \ | 82 CURRENT_FUNC, #dart_handle); \ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 115 } |
| 118 ~Scope() { | 116 ~Scope() { |
| 119 Dart_ExitScope(); | 117 Dart_ExitScope(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 private: | 120 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(Scope); | 121 DISALLOW_COPY_AND_ASSIGN(Scope); |
| 124 }; | 122 }; |
| 125 | 123 |
| 126 // Creates a new local handle. | 124 // Creates a new local handle. |
| 127 static Dart_Handle NewHandle(Isolate* isolate, RawObject* raw); | 125 static Dart_Handle NewHandle(Thread* thread, RawObject* raw); |
| 128 | 126 |
| 129 // Unwraps the raw object from the handle. | 127 // Unwraps the raw object from the handle. |
| 130 static RawObject* UnwrapHandle(Dart_Handle object); | 128 static RawObject* UnwrapHandle(Dart_Handle object); |
| 131 | 129 |
| 132 // Unwraps a raw Type from the handle. The handle will be null if | 130 // Unwraps a raw Type from the handle. The handle will be null if |
| 133 // the object was not of the requested Type. | 131 // the object was not of the requested Type. |
| 134 #define DECLARE_UNWRAP(Type) \ | 132 #define DECLARE_UNWRAP(Type) \ |
| 135 static const Type& Unwrap##Type##Handle(Zone* zone, \ | 133 static const Type& Unwrap##Type##Handle(Zone* zone, \ |
| 136 Dart_Handle object); | 134 Dart_Handle object); |
| 137 CLASS_LIST_FOR_HANDLES(DECLARE_UNWRAP) | 135 CLASS_LIST_FOR_HANDLES(DECLARE_UNWRAP) |
| 138 #undef DECLARE_UNWRAP | 136 #undef DECLARE_UNWRAP |
| 139 | 137 |
| 140 // Unwraps the raw object from the handle using a reused handle. | 138 // Unwraps the raw object from the handle using a reused handle. |
| 141 static const String& UnwrapStringHandle( | 139 static const String& UnwrapStringHandle( |
| 142 const ReusableObjectHandleScope& reused, Dart_Handle object); | 140 const ReusableObjectHandleScope& reused, Dart_Handle object); |
| 143 static const Instance& UnwrapInstanceHandle( | 141 static const Instance& UnwrapInstanceHandle( |
| 144 const ReusableObjectHandleScope& reused, Dart_Handle object); | 142 const ReusableObjectHandleScope& reused, Dart_Handle object); |
| 145 | 143 |
| 146 // Returns an Error handle if isolate is in an inconsistent state | 144 // Returns an Error handle if isolate is in an inconsistent state |
| 147 // or there was an error while finalizing classes. | 145 // or there was an error while finalizing classes. |
| 148 // Returns a Success handle when no error condition exists. | 146 // Returns a Success handle when no error condition exists. |
| 149 static Dart_Handle CheckAndFinalizePendingClasses(Isolate *isolate); | 147 static Dart_Handle CheckAndFinalizePendingClasses(Thread *thread); |
| 150 | 148 |
| 151 // Casts the internal Isolate* type to the external Dart_Isolate type. | 149 // Casts the internal Isolate* type to the external Dart_Isolate type. |
| 152 static Dart_Isolate CastIsolate(Isolate* isolate); | 150 static Dart_Isolate CastIsolate(Isolate* isolate); |
| 153 | 151 |
| 154 // Gets the handle used to designate successful return. | 152 // Gets the handle used to designate successful return. |
| 155 static Dart_Handle Success() { return Api::True(); } | 153 static Dart_Handle Success() { return Api::True(); } |
| 156 | 154 |
| 157 // Sets up the acquired error object after initializing an Isolate. This | 155 // Sets up the acquired error object after initializing an Isolate. This |
| 158 // object is pre-created because we will not be able to allocate this | 156 // object is pre-created because we will not be able to allocate this |
| 159 // object when the error actually occurs. When the error occurs there will | 157 // object when the error actually occurs. When the error occurs there will |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 static Dart_Handle False() { | 207 static Dart_Handle False() { |
| 210 return false_handle_; | 208 return false_handle_; |
| 211 } | 209 } |
| 212 | 210 |
| 213 // Gets a handle to EmptyString. | 211 // Gets a handle to EmptyString. |
| 214 static Dart_Handle EmptyString() { | 212 static Dart_Handle EmptyString() { |
| 215 return empty_string_handle_; | 213 return empty_string_handle_; |
| 216 } | 214 } |
| 217 | 215 |
| 218 // Retrieves the top ApiLocalScope. | 216 // Retrieves the top ApiLocalScope. |
| 219 static ApiLocalScope* TopScope(Isolate* isolate); | 217 static ApiLocalScope* TopScope(Thread* thread); |
| 220 | 218 |
| 221 // Performs one-time initialization needed by the API. | 219 // Performs one-time initialization needed by the API. |
| 222 static void InitOnce(); | 220 static void InitOnce(); |
| 223 | 221 |
| 224 // Allocates handles for objects in the VM isolate. | 222 // Allocates handles for objects in the VM isolate. |
| 225 static void InitHandles(); | 223 static void InitHandles(); |
| 226 | 224 |
| 227 // Helper function to get the peer value of an external string object. | 225 // Helper function to get the peer value of an external string object. |
| 228 static bool StringGetPeerHelper(NativeArguments* args, | 226 static bool StringGetPeerHelper(NativeArguments* args, |
| 229 int arg_index, | 227 int arg_index, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 static void SetDoubleReturnValue(NativeArguments* args, double retval) { | 264 static void SetDoubleReturnValue(NativeArguments* args, double retval) { |
| 267 args->SetReturnUnsafe(Double::New(retval)); | 265 args->SetReturnUnsafe(Double::New(retval)); |
| 268 } | 266 } |
| 269 static void SetWeakHandleReturnValue(NativeArguments* args, | 267 static void SetWeakHandleReturnValue(NativeArguments* args, |
| 270 Dart_WeakPersistentHandle retval); | 268 Dart_WeakPersistentHandle retval); |
| 271 | 269 |
| 272 static RawString* CallEnvironmentCallback(Thread* thread, | 270 static RawString* CallEnvironmentCallback(Thread* thread, |
| 273 const String& name); | 271 const String& name); |
| 274 | 272 |
| 275 private: | 273 private: |
| 276 static Dart_Handle InitNewHandle(Isolate* isolate, RawObject* raw); | 274 static Dart_Handle InitNewHandle(Thread* thread, RawObject* raw); |
| 277 | 275 |
| 278 // Thread local key used by the API. Currently holds the current | 276 // Thread local key used by the API. Currently holds the current |
| 279 // ApiNativeScope if any. | 277 // ApiNativeScope if any. |
| 280 static ThreadLocalKey api_native_key_; | 278 static ThreadLocalKey api_native_key_; |
| 281 static Dart_Handle true_handle_; | 279 static Dart_Handle true_handle_; |
| 282 static Dart_Handle false_handle_; | 280 static Dart_Handle false_handle_; |
| 283 static Dart_Handle null_handle_; | 281 static Dart_Handle null_handle_; |
| 284 static Dart_Handle empty_string_handle_; | 282 static Dart_Handle empty_string_handle_; |
| 285 | 283 |
| 286 friend class ApiNativeScope; | 284 friend class ApiNativeScope; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 305 return Api::NewError("%s: Cannot load after Dart_Precompile", \ | 303 return Api::NewError("%s: Cannot load after Dart_Precompile", \ |
| 306 CURRENT_FUNC); \ | 304 CURRENT_FUNC); \ |
| 307 } \ | 305 } \ |
| 308 | 306 |
| 309 #define ASSERT_CALLBACK_STATE(thread) \ | 307 #define ASSERT_CALLBACK_STATE(thread) \ |
| 310 ASSERT(thread->no_callback_scope_depth() == 0) | 308 ASSERT(thread->no_callback_scope_depth() == 0) |
| 311 | 309 |
| 312 } // namespace dart. | 310 } // namespace dart. |
| 313 | 311 |
| 314 #endif // VM_DART_API_IMPL_H_ | 312 #endif // VM_DART_API_IMPL_H_ |
| OLD | NEW |