| 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 #ifndef VM_DART_API_STATE_H_ | 5 #ifndef VM_DART_API_STATE_H_ |
| 6 #define VM_DART_API_STATE_H_ | 6 #define VM_DART_API_STATE_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "platform/thread.h" | 10 #include "platform/thread.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); | 519 DISALLOW_COPY_AND_ASSIGN(ApiLocalScope); |
| 520 }; | 520 }; |
| 521 | 521 |
| 522 | 522 |
| 523 // Implementation of the API State used in dart api for maintaining | 523 // Implementation of the API State used in dart api for maintaining |
| 524 // local scopes, persistent handles etc. These are setup on a per isolate | 524 // local scopes, persistent handles etc. These are setup on a per isolate |
| 525 // basis and destroyed when the isolate is shutdown. | 525 // basis and destroyed when the isolate is shutdown. |
| 526 class ApiState { | 526 class ApiState { |
| 527 public: | 527 public: |
| 528 ApiState() : top_scope_(NULL), delayed_weak_reference_sets_(NULL), | 528 ApiState() : top_scope_(NULL), delayed_weak_reference_sets_(NULL), |
| 529 null_(NULL), true_(NULL), false_(NULL) { } | 529 null_(NULL), true_(NULL), false_(NULL), |
| 530 callback_error_(NULL) {} |
| 530 ~ApiState() { | 531 ~ApiState() { |
| 531 while (top_scope_ != NULL) { | 532 while (top_scope_ != NULL) { |
| 532 ApiLocalScope* scope = top_scope_; | 533 ApiLocalScope* scope = top_scope_; |
| 533 top_scope_ = top_scope_->previous(); | 534 top_scope_ = top_scope_->previous(); |
| 534 delete scope; | 535 delete scope; |
| 535 } | 536 } |
| 536 if (null_ != NULL) { | 537 if (null_ != NULL) { |
| 537 persistent_handles().FreeHandle(null_); | 538 persistent_handles().FreeHandle(null_); |
| 538 null_ = NULL; | 539 null_ = NULL; |
| 539 } | 540 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 PersistentHandle* False() { | 669 PersistentHandle* False() { |
| 669 if (false_ == NULL) { | 670 if (false_ == NULL) { |
| 670 DARTSCOPE(Isolate::Current()); | 671 DARTSCOPE(Isolate::Current()); |
| 671 | 672 |
| 672 false_ = persistent_handles().AllocateHandle(); | 673 false_ = persistent_handles().AllocateHandle(); |
| 673 false_->set_raw(Bool::False()); | 674 false_->set_raw(Bool::False()); |
| 674 } | 675 } |
| 675 return false_; | 676 return false_; |
| 676 } | 677 } |
| 677 | 678 |
| 679 void SetupCallbackError() { |
| 680 ASSERT(callback_error_ == NULL); |
| 681 callback_error_ = persistent_handles().AllocateHandle(); |
| 682 callback_error_->set_raw( |
| 683 String::New("Internal Dart data pointers have been acquired, " |
| 684 "please release them using Dart_ByteArrayReleaseData.")); |
| 685 } |
| 686 |
| 687 PersistentHandle* CallbackError() const { |
| 688 ASSERT(callback_error_ != NULL); |
| 689 return callback_error_; |
| 690 } |
| 691 |
| 678 void DelayWeakReferenceSet(WeakReferenceSet* reference_set) { | 692 void DelayWeakReferenceSet(WeakReferenceSet* reference_set) { |
| 679 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); | 693 WeakReferenceSet::Push(reference_set, &delayed_weak_reference_sets_); |
| 680 } | 694 } |
| 681 | 695 |
| 682 private: | 696 private: |
| 683 PersistentHandles persistent_handles_; | 697 PersistentHandles persistent_handles_; |
| 684 FinalizablePersistentHandles weak_persistent_handles_; | 698 FinalizablePersistentHandles weak_persistent_handles_; |
| 685 FinalizablePersistentHandles prologue_weak_persistent_handles_; | 699 FinalizablePersistentHandles prologue_weak_persistent_handles_; |
| 686 ApiLocalScope* top_scope_; | 700 ApiLocalScope* top_scope_; |
| 687 WeakReferenceSet* delayed_weak_reference_sets_; | 701 WeakReferenceSet* delayed_weak_reference_sets_; |
| 688 | 702 |
| 689 // Persistent handles to important objects. | 703 // Persistent handles to important objects. |
| 690 PersistentHandle* null_; | 704 PersistentHandle* null_; |
| 691 PersistentHandle* true_; | 705 PersistentHandle* true_; |
| 692 PersistentHandle* false_; | 706 PersistentHandle* false_; |
| 707 PersistentHandle* callback_error_; |
| 693 | 708 |
| 694 DISALLOW_COPY_AND_ASSIGN(ApiState); | 709 DISALLOW_COPY_AND_ASSIGN(ApiState); |
| 695 }; | 710 }; |
| 696 | 711 |
| 697 | 712 |
| 698 class ApiNativeScope { | 713 class ApiNativeScope { |
| 699 public: | 714 public: |
| 700 ApiNativeScope() { | 715 ApiNativeScope() { |
| 701 // Currently no support for nesting native scopes. | 716 // Currently no support for nesting native scopes. |
| 702 ASSERT(Current() == NULL); | 717 ASSERT(Current() == NULL); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 ApiNativeScope::Current()->zone()) {} | 749 ApiNativeScope::Current()->zone()) {} |
| 735 ApiGrowableArray() | 750 ApiGrowableArray() |
| 736 : BaseGrowableArray<T, ValueObject>( | 751 : BaseGrowableArray<T, ValueObject>( |
| 737 ApiNativeScope::Current()->zone()) {} | 752 ApiNativeScope::Current()->zone()) {} |
| 738 }; | 753 }; |
| 739 | 754 |
| 740 | 755 |
| 741 } // namespace dart | 756 } // namespace dart |
| 742 | 757 |
| 743 #endif // VM_DART_API_STATE_H_ | 758 #endif // VM_DART_API_STATE_H_ |
| OLD | NEW |