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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // ApiNativeScope if any. | 279 // ApiNativeScope if any. |
280 static ThreadLocalKey api_native_key_; | 280 static ThreadLocalKey api_native_key_; |
281 static Dart_Handle true_handle_; | 281 static Dart_Handle true_handle_; |
282 static Dart_Handle false_handle_; | 282 static Dart_Handle false_handle_; |
283 static Dart_Handle null_handle_; | 283 static Dart_Handle null_handle_; |
284 static Dart_Handle empty_string_handle_; | 284 static Dart_Handle empty_string_handle_; |
285 | 285 |
286 friend class ApiNativeScope; | 286 friend class ApiNativeScope; |
287 }; | 287 }; |
288 | 288 |
289 class IsolateSaver { | |
290 public: | |
291 explicit IsolateSaver(Isolate* current_isolate) | |
292 : saved_isolate_(current_isolate) { | |
293 } | |
294 ~IsolateSaver() { | |
295 // TODO(koda): Audit users; they should know whether they're in an isolate. | |
296 if (saved_isolate_ != NULL) { | |
297 Thread::EnterIsolate(saved_isolate_); | |
298 } | |
299 } | |
300 private: | |
301 Isolate* saved_isolate_; | |
302 | |
303 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | |
304 }; | |
305 | |
306 // Start a scope in which no Dart API call backs are allowed. | 289 // Start a scope in which no Dart API call backs are allowed. |
307 #define START_NO_CALLBACK_SCOPE(thread) \ | 290 #define START_NO_CALLBACK_SCOPE(thread) \ |
308 thread->IncrementNoCallbackScopeDepth() | 291 thread->IncrementNoCallbackScopeDepth() |
309 | 292 |
310 // End a no Dart API call backs Scope. | 293 // End a no Dart API call backs Scope. |
311 #define END_NO_CALLBACK_SCOPE(thread) \ | 294 #define END_NO_CALLBACK_SCOPE(thread) \ |
312 thread->DecrementNoCallbackScopeDepth() | 295 thread->DecrementNoCallbackScopeDepth() |
313 | 296 |
314 #define CHECK_CALLBACK_STATE(thread) \ | 297 #define CHECK_CALLBACK_STATE(thread) \ |
315 if (thread->no_callback_scope_depth() != 0) { \ | 298 if (thread->no_callback_scope_depth() != 0) { \ |
316 return reinterpret_cast<Dart_Handle>( \ | 299 return reinterpret_cast<Dart_Handle>( \ |
317 Api::AcquiredError(thread->isolate())); \ | 300 Api::AcquiredError(thread->isolate())); \ |
318 } \ | 301 } \ |
319 | 302 |
320 #define CHECK_COMPILATION_ALLOWED(isolate) \ | 303 #define CHECK_COMPILATION_ALLOWED(isolate) \ |
321 if (!isolate->compilation_allowed()) { \ | 304 if (!isolate->compilation_allowed()) { \ |
322 return Api::NewError("%s: Cannot load after Dart_Precompile", \ | 305 return Api::NewError("%s: Cannot load after Dart_Precompile", \ |
323 CURRENT_FUNC); \ | 306 CURRENT_FUNC); \ |
324 } \ | 307 } \ |
325 | 308 |
326 #define ASSERT_CALLBACK_STATE(thread) \ | 309 #define ASSERT_CALLBACK_STATE(thread) \ |
327 ASSERT(thread->no_callback_scope_depth() == 0) | 310 ASSERT(thread->no_callback_scope_depth() == 0) |
328 | 311 |
329 } // namespace dart. | 312 } // namespace dart. |
330 | 313 |
331 #endif // VM_DART_API_IMPL_H_ | 314 #endif // VM_DART_API_IMPL_H_ |
OLD | NEW |