Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: include/v8.h

Issue 978783002: give UniquePersistent full move semantics (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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) {
860 TYPE_CHECK(T, S); 855 TYPE_CHECK(T, S);
861 this->Reset(); 856 if (this != &rhs) {
862 this->val_ = rhs.val_; 857 this->Reset();
863 rhs.val_ = 0; 858 this->val_ = rhs.val_;
859 rhs.val_ = nullptr;
860 }
864 return *this; 861 return *this;
865 } 862 }
866 /** 863 /**
867 * Cast operator for moves.
868 */
869 V8_INLINE operator RValue() { return RValue(this); }
870 /**
871 * Pass allows returning uniques from functions, etc. 864 * Pass allows returning uniques from functions, etc.
872 */ 865 */
873 UniquePersistent Pass() { return UniquePersistent(RValue(this)); } 866 UniquePersistent Pass() { return static_cast<UniquePersistent&&>(*this); }
874 867
875 private: 868 private:
876 UniquePersistent(UniquePersistent&); 869 UniquePersistent(UniquePersistent&) = delete;
877 void operator=(UniquePersistent&); 870 void operator=(UniquePersistent&) = delete;
878 }; 871 };
879 872
880 873
881 /** 874 /**
882 * A stack-allocated class that governs a number of local handles. 875 * A stack-allocated class that governs a number of local handles.
883 * After a handle scope has been created, all local handles will be 876 * After a handle scope has been created, all local handles will be
884 * allocated within that handle scope until either the handle scope is 877 * allocated within that handle scope until either the handle scope is
885 * deleted or another handle scope is created. If there is already a 878 * 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 879 * 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, 880 * place in the new handle scope until it is deleted. After that,
(...skipping 6828 matching lines...) Expand 10 before | Expand all | Expand 10 after
7716 */ 7709 */
7717 7710
7718 7711
7719 } // namespace v8 7712 } // namespace v8
7720 7713
7721 7714
7722 #undef TYPE_CHECK 7715 #undef TYPE_CHECK
7723 7716
7724 7717
7725 #endif // V8_H_ 7718 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698