Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
| 6 * | 6 * |
| 7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
| 8 * | 8 * |
| 9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
| 10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 template<class F1, class F2> friend class Persistent; | 658 template<class F1, class F2> friend class Persistent; |
| 659 template<class F> friend class UniquePersistent; | 659 template<class F> friend class UniquePersistent; |
| 660 template<class F> friend class PersistentBase; | 660 template<class F> friend class PersistentBase; |
| 661 template<class F> friend class ReturnValue; | 661 template<class F> friend class ReturnValue; |
| 662 template <class F1, class F2, class F3> | 662 template <class F1, class F2, class F3> |
| 663 friend class PersistentValueMapBase; | 663 friend class PersistentValueMapBase; |
| 664 template<class F1, class F2> friend class PersistentValueVector; | 664 template<class F1, class F2> friend class PersistentValueVector; |
| 665 friend class Object; | 665 friend class Object; |
| 666 | 666 |
| 667 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} | 667 explicit V8_INLINE PersistentBase(T* val) : val_(val) {} |
| 668 PersistentBase(PersistentBase& other); // NOLINT | 668 PersistentBase(PersistentBase& other) = delete; // NOLINT |
| 669 void operator=(PersistentBase&); | 669 void operator=(PersistentBase&) = delete; |
| 670 V8_INLINE static T* New(Isolate* isolate, T* that); | 670 V8_INLINE static T* New(Isolate* isolate, T* that); |
| 671 | 671 |
| 672 T* val_; | 672 T* val_; |
| 673 }; | 673 }; |
| 674 | 674 |
| 675 | 675 |
| 676 /** | 676 /** |
| 677 * Default traits for Persistent. This class does not allow | 677 * Default traits for Persistent. This class does not allow |
| 678 * use of the copy constructor or assignment operator. | 678 * use of the copy constructor or assignment operator. |
| 679 * At present kResetInDestructor is not set, but that will change in a future | 679 * At present kResetInDestructor is not set, but that will change in a future |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 }; | 807 }; |
| 808 | 808 |
| 809 | 809 |
| 810 /** | 810 /** |
| 811 * A PersistentBase which has move semantics. | 811 * A PersistentBase which has move semantics. |
| 812 * | 812 * |
| 813 * Note: Persistent class hierarchy is subject to future changes. | 813 * Note: Persistent class hierarchy is subject to future changes. |
| 814 */ | 814 */ |
| 815 template<class T> | 815 template<class T> |
| 816 class UniquePersistent : public PersistentBase<T> { | 816 class UniquePersistent : public PersistentBase<T> { |
| 817 struct RValue { | |
| 818 V8_INLINE explicit RValue(UniquePersistent* obj) : object(obj) {} | |
| 819 UniquePersistent* object; | |
| 820 }; | |
| 821 | |
| 822 public: | 817 public: |
| 823 /** | 818 /** |
| 824 * A UniquePersistent with no storage cell. | 819 * A UniquePersistent with no storage cell. |
| 825 */ | 820 */ |
| 826 V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } | 821 V8_INLINE UniquePersistent() : PersistentBase<T>(nullptr) {} |
| 827 /** | 822 /** |
| 828 * Construct a UniquePersistent from a Handle. | 823 * Construct a UniquePersistent from a Handle. |
| 829 * When the Handle is non-empty, a new storage cell is created | 824 * When the Handle is non-empty, a new storage cell is created |
| 830 * pointing to the same object, and no flags are set. | 825 * pointing to the same object, and no flags are set. |
| 831 */ | 826 */ |
| 832 template <class S> | 827 template <class S> |
| 833 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) | 828 V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) |
| 834 : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { | 829 : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { |
| 835 TYPE_CHECK(T, S); | 830 TYPE_CHECK(T, S); |
| 836 } | 831 } |
| 837 /** | 832 /** |
| 838 * Construct a UniquePersistent from a PersistentBase. | 833 * Construct a UniquePersistent from a PersistentBase. |
| 839 * When the Persistent is non-empty, a new storage cell is created | 834 * When the Persistent is non-empty, a new storage cell is created |
| 840 * pointing to the same object, and no flags are set. | 835 * pointing to the same object, and no flags are set. |
| 841 */ | 836 */ |
| 842 template <class S> | 837 template <class S> |
| 843 V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& that) | 838 V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& that) |
| 844 : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) { | 839 : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) { |
| 845 TYPE_CHECK(T, S); | 840 TYPE_CHECK(T, S); |
| 846 } | 841 } |
| 847 /** | 842 /** |
| 848 * Move constructor. | 843 * Move constructor. |
| 849 */ | 844 */ |
| 850 V8_INLINE UniquePersistent(RValue rvalue) | 845 V8_INLINE UniquePersistent(UniquePersistent&& other) |
| 851 : PersistentBase<T>(rvalue.object->val_) { | 846 : PersistentBase<T>(other.val_) { |
| 852 rvalue.object->val_ = 0; | 847 other.val_ = nullptr; |
| 853 } | 848 } |
| 854 V8_INLINE ~UniquePersistent() { this->Reset(); } | 849 V8_INLINE ~UniquePersistent() { this->Reset(); } |
| 855 /** | 850 /** |
| 856 * Move via assignment. | 851 * Move via assignment. |
| 857 */ | 852 */ |
| 858 template<class S> | 853 template <class S> |
| 859 V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { | 854 V8_INLINE UniquePersistent& operator=(UniquePersistent<S>&& rhs) { |
|
jamesr
2015/03/04 18:52:37
operator=(T&&)s should support self assignment, bu
dcarney
2015/03/04 19:40:24
good catch, thanks
| |
| 860 TYPE_CHECK(T, S); | 855 TYPE_CHECK(T, S); |
| 861 this->Reset(); | 856 this->Reset(); |
| 862 this->val_ = rhs.val_; | 857 this->val_ = rhs.val_; |
| 863 rhs.val_ = 0; | 858 rhs.val_ = nullptr; |
| 864 return *this; | 859 return *this; |
| 865 } | 860 } |
| 866 /** | 861 /** |
| 867 * Cast operator for moves. | |
| 868 */ | |
| 869 V8_INLINE operator RValue() { return RValue(this); } | |
| 870 /** | |
| 871 * Pass allows returning uniques from functions, etc. | 862 * Pass allows returning uniques from functions, etc. |
| 872 */ | 863 */ |
| 873 UniquePersistent Pass() { return UniquePersistent(RValue(this)); } | 864 // TODO(dcarney): deprecate, this is just std::move |
| 865 UniquePersistent Pass() { return static_cast<UniquePersistent&&>(*this); } | |
| 874 | 866 |
| 875 private: | 867 private: |
| 876 UniquePersistent(UniquePersistent&); | 868 UniquePersistent(UniquePersistent&) = delete; |
| 877 void operator=(UniquePersistent&); | 869 void operator=(UniquePersistent&) = delete; |
| 878 }; | 870 }; |
| 879 | 871 |
| 880 | 872 |
| 881 /** | 873 /** |
| 882 * A stack-allocated class that governs a number of local handles. | 874 * A stack-allocated class that governs a number of local handles. |
| 883 * After a handle scope has been created, all local handles will be | 875 * After a handle scope has been created, all local handles will be |
| 884 * allocated within that handle scope until either the handle scope is | 876 * allocated within that handle scope until either the handle scope is |
| 885 * deleted or another handle scope is created. If there is already a | 877 * deleted or another handle scope is created. If there is already a |
| 886 * handle scope and a new one is created, all allocations will take | 878 * handle scope and a new one is created, all allocations will take |
| 887 * place in the new handle scope until it is deleted. After that, | 879 * place in the new handle scope until it is deleted. After that, |
| (...skipping 6828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7716 */ | 7708 */ |
| 7717 | 7709 |
| 7718 | 7710 |
| 7719 } // namespace v8 | 7711 } // namespace v8 |
| 7720 | 7712 |
| 7721 | 7713 |
| 7722 #undef TYPE_CHECK | 7714 #undef TYPE_CHECK |
| 7723 | 7715 |
| 7724 | 7716 |
| 7725 #endif // V8_H_ | 7717 #endif // V8_H_ |
| OLD | NEW |